traxxx-web/components/scenes/scenes.vue

237 lines
5.5 KiB
Vue
Raw Normal View History

<template>
<div class="page">
<Filters v-if="showFilters">
2024-01-08 01:21:57 +00:00
<TagsFilter
:filters="filters"
:tags="aggTags"
@update="updateFilter"
/>
<ChannelsFilter
:filters="filters"
:channels="aggChannels"
@update="updateFilter"
/>
2024-01-07 22:44:33 +00:00
<ActorsFilter
:filters="filters"
2024-01-08 01:21:57 +00:00
:actors="aggActors"
2024-01-07 22:44:33 +00:00
@update="updateFilter"
/>
</Filters>
<div class="scenes-container">
2024-01-07 22:44:33 +00:00
<div
v-if="showMeta"
class="scenes-header"
>
<div class="meta">{{ total }} results</div>
</div>
<nav class="scopes">
<Link
:href="getPath('latest')"
class="scope nolink"
:active="scope === 'latest'"
>Latest</Link>
<Link
:href="getPath('upcoming')"
class="scope nolink"
:active="scope === 'upcoming'"
>Upcoming</Link>
<Link
:href="getPath('new')"
class="scope nolink"
:active="scope === 'new'"
>New</Link>
</nav>
<ul class="scenes nolist">
<li
v-for="scene in scenes"
:key="scene.id"
>
<Scene :scene="scene" />
</li>
</ul>
<Pagination />
</div>
</div>
</template>
<script setup>
2024-01-07 22:44:33 +00:00
import { ref, inject } from 'vue';
import { parse } from 'path-to-regexp';
import navigate from '#/src/navigate.js';
import { get } from '#/src/api.js';
import events from '#/src/events.js';
import { getActorIdentifier, parseActorIdentifier } from '#/src/query.js';
import Filters from '#/components/filters/filters.vue';
2024-01-07 22:44:33 +00:00
import ActorsFilter from '#/components/filters/actors.vue';
2024-01-08 01:21:57 +00:00
import TagsFilter from '#/components/filters/tags.vue';
import ChannelsFilter from '#/components/filters/channels.vue';
import Scene from './tile.vue';
import Pagination from '../pagination/pagination.vue';
defineProps({
showFilters: {
type: Boolean,
default: true,
},
2024-01-07 22:44:33 +00:00
showMeta: {
type: Boolean,
default: true,
},
});
const { pageProps, routeParams, urlParsed } = inject('pageContext');
const { scope } = routeParams;
const {
actor: pageActor,
tag: pageTag,
channel: pageChannel,
} = pageProps;
const scenes = ref(pageProps.scenes);
2024-01-08 01:21:57 +00:00
const aggActors = ref(pageProps.aggActors);
const aggTags = ref(pageProps.aggTags);
const aggChannels = ref(pageProps.aggChannels);
const currentPage = ref(Number(routeParams.page));
const total = ref(Number(pageProps.total));
const actorIds = urlParsed.search.actors?.split(',').map((identifier) => parseActorIdentifier(identifier)?.id).filter(Boolean) || [];
const queryActors = actorIds.map((urlActorId) => aggActors.value.find((aggActor) => aggActor.id === urlActorId)).filter(Boolean);
const networks = Object.fromEntries(aggChannels.value.map((channel) => (channel.type === 'network' ? channel : channel.parent)).filter(Boolean).map((parent) => [`_${parent.slug}`, parent]));
const channels = Object.fromEntries(aggChannels.value.filter((channel) => channel.type === 'channel').map((channel) => [channel.slug, channel]));
const queryChannel = networks[urlParsed.search.e] || channels[urlParsed.search.e];
const filters = ref({
2024-01-08 01:21:57 +00:00
tags: urlParsed.search.tags?.split(',').filter(Boolean) || [],
channel: queryChannel,
actors: queryActors,
});
function getPath(targetScope, preserveQuery) {
const path = parse(routeParams.path)
.map((segment) => {
if (segment.name === 'scope') {
return targetScope;
}
if (segment.name === 'page') {
return 1;
}
return routeParams[segment.name] || segment;
})
.join('/');
if (preserveQuery && urlParsed.searchOriginal) {
return `${path}${urlParsed.searchOriginal}`;
}
return path;
}
async function search(resetPage = true) {
if (resetPage) {
currentPage.value = 1;
}
const query = {};
2024-01-08 01:21:57 +00:00
const entity = filters.value.channel || pageChannel;
const entitySlug = entity?.type === 'network' ? `_${entity.slug}` : entity?.slug;
const res = await get('/scenes', {
...query,
actors: [pageActor, ...filters.value.actors].filter(Boolean).map((filterActor) => getActorIdentifier(filterActor)).join(','), // if we're on an actor page, that actor ID needs to be included
tags: [pageTag?.slug, ...filters.value.tags].filter(Boolean).join(','),
entity: entitySlug,
scope,
page: currentPage.value, // client uses param rather than query pagination
});
scenes.value = res.scenes;
2024-01-08 01:21:57 +00:00
aggActors.value = res.aggActors;
aggTags.value = res.aggTags;
total.value = res.total;
events.emit('scrollUp');
navigate(getPath(scope, false), {
...query,
actors: filters.value.actors.map((filterActor) => getActorIdentifier(filterActor)).join(',') || undefined, // don't include page actor ID in query, already a parameter
tags: filters.value.tags.join(',') || undefined,
e: filters.value.channel?.type === 'network' ? `_${filters.value.channel.slug}` : (filters.value.channel?.slug || undefined),
}, { redirect: false });
}
function updateFilter(prop, value, reload = true) {
filters.value[prop] = value;
if (reload) {
search();
}
}
</script>
<style scoped>
.page {
display: flex;
background: var(--background-base-10);
}
.scenes-header {
display: flex;
align-items: center;
padding: .5rem 0 .25rem 2rem;
}
.scenes-container {
display: flex;
flex-direction: column;
2024-01-07 22:44:33 +00:00
flex-grow: 1;
}
.meta {
display: flex;
flex-grow: 1;
justify-content: space-between;
align-items: center;
}
.scenes {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(22rem, 1fr));
gap: .75rem .5rem;
padding: 1rem;
}
.scopes {
margin-left: 1rem;
}
.scope {
box-sizing: border-box;
padding: 1rem;
color: var(--shadow);
font-size: .9rem;
font-weight: bold;
&.active {
color: var(--primary);
font-weight: bold;
}
}
</style>