traxxx/assets/components/container/container.vue

235 lines
4.4 KiB
Vue
Raw Permalink Normal View History

<template>
<div class="container">
2020-12-18 01:10:30 +00:00
<Warning
v-if="showWarning"
class="warning-container"
@enter="(includeQueer) => setConsent(true, includeQueer)"
2020-12-19 22:01:17 +00:00
@leave="setConsent(false)"
2020-12-18 01:10:30 +00:00
/>
2020-08-08 20:18:55 +00:00
<transition name="slide">
<Sidebar v-if="showSidebar" />
2020-08-08 20:18:55 +00:00
</transition>
<Header />
2021-02-05 02:50:03 +00:00
<p
v-if="config.showDisclaimer"
class="disclaimer"
v-html="config.disclaimer"
/>
2021-02-05 02:50:03 +00:00
2023-06-18 23:36:04 +00:00
<p
v-if="config.showAnnouncement"
class="announcement"
v-html="config.announcement"
/>
2023-06-18 23:36:04 +00:00
2021-01-17 20:24:20 +00:00
<div
ref="content"
class="content"
2021-02-28 02:38:54 +00:00
@scroll="scroll"
2021-01-17 20:24:20 +00:00
>
<RouterView @scroll="scrollToTop" />
2020-05-25 00:02:28 +00:00
</div>
<Filters
v-if="showFilters"
@close="toggleFilters(false)"
/>
<Settings
v-if="showSettings"
@close="toggleSettings(false)"
/>
2020-05-25 00:02:28 +00:00
</div>
</template>
<script>
2020-12-18 01:10:30 +00:00
import Warning from './warning.vue';
import Header from '../header/header.vue';
import Sidebar from '../sidebar/sidebar.vue';
2021-03-20 22:03:13 +00:00
import Filters from '../filters/filters.vue';
import Settings from '../settings/settings.vue';
function toggleSidebar(state) {
2020-05-25 00:02:28 +00:00
this.showSidebar = typeof state === 'boolean' ? state : !this.showSidebar;
}
function toggleFilters(state) {
this.showFilters = state;
this.showSidebar = false;
}
function toggleSettings(state) {
this.showSettings = state;
this.showSidebar = false;
}
async function setConsent(consent, includeQueer) {
2020-12-19 22:01:17 +00:00
if (consent) {
this.showWarning = false;
localStorage.setItem('consent', window.env.sessionId);
2020-12-19 22:01:17 +00:00
}
if (includeQueer) {
2022-03-26 16:40:20 +00:00
this.$store.dispatch('setTagFilter', this.$store.state.ui.tagFilter.filter((tag) => !['gay', 'bisexual', 'transsexual'].includes(tag)));
return;
}
this.$store.dispatch('setTagFilter', this.$store.state.ui.tagFilter.concat(['gay', 'bisexual', 'transsexual']));
2020-12-18 01:10:30 +00:00
}
2020-12-27 03:21:10 +00:00
function blur(event) {
this.events.emit('blur', event);
}
function resize(event) {
this.events.emit('resize', event);
}
2021-02-28 02:38:54 +00:00
function scroll(event) {
this.events.emit('scroll', event);
}
2021-01-17 20:24:20 +00:00
function scrollToTop() {
this.$refs.content.scrollTop = 0;
}
2023-07-25 22:26:15 +00:00
function trackIframeCampaign() {
// no way to capture clicks from an iframe directly
if (window.umami && document.activeElement.tagName === 'IFRAME' && document.activeElement.dataset.umamiEvent === 'campaign-click') {
window.umami.track('campaign-click', {
'campaign-id': document.activeElement.dataset.umamiEventCampaignId,
});
}
}
2020-12-27 03:21:10 +00:00
function mounted() {
document.addEventListener('click', this.blur);
window.addEventListener('resize', this.resize);
this.events.on('toggleSettings', this.toggleSettings);
this.events.on('toggleSidebar', this.toggleSidebar);
2023-07-25 22:26:15 +00:00
window.addEventListener('blur', this.trackIframeCampaign);
2020-12-27 03:21:10 +00:00
}
function beforeUnmount() {
document.removeEventListener('click', this.blur);
window.removeEventListener('resize', this.resize);
2023-07-25 22:26:15 +00:00
window.removeEventListener('blur', this.trackIframeCampaign);
2020-12-27 03:21:10 +00:00
}
export default {
2020-05-25 00:02:28 +00:00
components: {
Header,
Sidebar,
2020-12-18 01:10:30 +00:00
Warning,
Filters,
Settings,
2020-05-25 00:02:28 +00:00
},
data() {
return {
showSidebar: false,
showWarning: localStorage.getItem('consent') !== window.env.sessionId,
showFilters: false,
showSettings: false,
selected: null,
2020-05-25 00:02:28 +00:00
};
},
2020-12-27 03:21:10 +00:00
mounted,
beforeUnmount,
2020-05-25 00:02:28 +00:00
methods: {
2023-07-25 22:26:15 +00:00
setConsent,
2020-05-25 00:02:28 +00:00
toggleSidebar,
toggleFilters,
toggleSettings,
2023-07-25 22:26:15 +00:00
trackIframeCampaign,
2020-12-27 03:21:10 +00:00
blur,
resize,
2021-02-28 02:38:54 +00:00
scroll,
2021-01-17 20:24:20 +00:00
scrollToTop,
2020-05-25 00:02:28 +00:00
},
};
</script>
<style lang="scss">
.container {
position: relative;
height: 100%;
display: flex;
flex-direction: column;
overflow: hidden;
2020-05-25 00:02:28 +00:00
background: var(--background-soft);
color: var(--text);
}
.content {
display: flex;
flex-direction: column;
flex-grow: 1;
2019-11-14 00:18:19 +00:00
overflow-y: auto;
2020-06-29 23:07:48 +00:00
overflow-x: hidden;
}
.content-inner {
display: flex;
flex-direction: column;
2020-06-27 02:50:13 +00:00
flex-grow: 1;
overflow-y: auto;
overflow-x: hidden;
z-index: 1;
}
2020-08-08 20:18:55 +00:00
.slide-enter-active,
.slide-leave-active {
&.sidebar-container {
transition: background .15s ease-in-out;
2020-08-08 20:18:55 +00:00
}
.sidebar {
transition: transform .15s ease-in-out;
2020-08-08 20:18:55 +00:00
}
}
2020-12-29 19:04:18 +00:00
.slide-enter-from,
2020-08-08 20:18:55 +00:00
.slide-leave-to {
&.sidebar-container {
background: transparent;
}
.sidebar {
transform: translate(100%, 0);
2020-08-08 20:18:55 +00:00
}
}
.column {
width: 1200px;
max-width: 100%;
padding: 0 1rem;
margin: 0 auto;
box-sizing: border-box;
}
2021-03-03 18:21:56 +00:00
</style>
2021-02-05 02:50:03 +00:00
2021-03-03 18:21:56 +00:00
<style lang="scss" scoped>
2023-06-18 23:36:04 +00:00
.disclaimer,
.announcement {
padding: .5rem 1rem;
2021-02-05 02:50:03 +00:00
margin: 0;
color: var(--text-light);
font-weight: bold;
box-shadow: inset 0 0 3px var(--darken-weak);
text-align: center;
}
2023-06-18 23:36:04 +00:00
.disclaimer {
background: var(--warn);
}
.announcement {
background: var(--notice);
}
</style>