Restored 'new' label client-side.

This commit is contained in:
DebaucheryLibrarian 2023-06-16 00:47:19 +02:00
parent 078837f276
commit c4424f30ec
7 changed files with 39 additions and 23 deletions

View File

@ -10,6 +10,7 @@ import {
actorStashesFields, actorStashesFields,
getIncludedEntities, getIncludedEntities,
getIncludedActors, getIncludedActors,
batchFragment,
} from '../fragments'; } from '../fragments';
function initActorActions(store, router) { function initActorActions(store, router) {
@ -27,7 +28,7 @@ function initActorActions(store, router) {
const includedTags = router.currentRoute.value.query.tags ? router.currentRoute.value.query.tags.split(',') : []; const includedTags = router.currentRoute.value.query.tags ? router.currentRoute.value.query.tags.split(',') : [];
const mode = router.currentRoute.value.query.mode || 'all'; const mode = router.currentRoute.value.query.mode || 'all';
const { actor } = await graphql(` const { actor, batches: [lastBatch] } = await graphql(`
query Actor( query Actor(
$actorId: Int! $actorId: Int!
$userId: Int, $userId: Int,
@ -254,6 +255,7 @@ function initActorActions(store, router) {
} }
${actorStashesFields} ${actorStashesFields}
} }
${batchFragment}
} }
`, { `, {
actorId, actorId,
@ -281,7 +283,7 @@ function initActorActions(store, router) {
return { return {
actor: curateActor(actor, null, curateRelease), actor: curateActor(actor, null, curateRelease),
releases: actor.scenesConnection.releases.map((release) => curateRelease(release)), releases: actor.scenesConnection.releases.map((release) => curateRelease(release, 'scene', { lastBatch: lastBatch.id })),
totalCount: actor.scenesConnection.totalCount, totalCount: actor.scenesConnection.totalCount,
}; };
} }

View File

@ -65,19 +65,20 @@ function curateActor(actor, release) {
return curatedActor; return curatedActor;
} }
function curateRelease(release, type = 'scene') { function curateRelease(release, type = 'scene', context = {}) {
const curatedRelease = { const curatedRelease = {
...release, ...release,
type: release.type || type, type: release.type || type,
actors: [], actors: [],
poster: release.poster && release.poster.media, poster: release.poster && release.poster.media,
tags: release.tags ? release.tags.map((tag) => tag.tag || tag) : [], tags: release.tags ? release.tags.map((tag) => tag.tag || tag) : [],
isNew: release.createdBatchId === context.lastBatch,
}; };
curatedRelease.scenes = release.scenes?.filter(Boolean).map(({ scene }) => curateRelease(scene, 'scene')) || []; curatedRelease.scenes = release.scenes?.filter(Boolean).map(({ scene }) => curateRelease(scene, 'scene', context)) || [];
curatedRelease.movies = release.movies?.filter(Boolean).map(({ movie }) => curateRelease(movie, 'movie')) || []; curatedRelease.movies = release.movies?.filter(Boolean).map(({ movie }) => curateRelease(movie, 'movie', context)) || [];
curatedRelease.series = release.series?.filter(Boolean).map(({ serie }) => curateRelease(serie, 'serie')) || []; curatedRelease.series = release.series?.filter(Boolean).map(({ serie }) => curateRelease(serie, 'serie', context)) || [];
curatedRelease.chapters = release.chapters?.filter(Boolean).map((chapter) => curateRelease(chapter)) || []; curatedRelease.chapters = release.chapters?.filter(Boolean).map((chapter) => curateRelease(chapter, 'chapter', context)) || [];
curatedRelease.photos = release.photos?.filter(Boolean).map((photo) => photo.media || photo) || []; curatedRelease.photos = release.photos?.filter(Boolean).map((photo) => photo.media || photo) || [];
curatedRelease.scenesPhotos = release.scenesPhotos?.filter(Boolean).map((photo) => photo.media || photo) || []; curatedRelease.scenesPhotos = release.scenesPhotos?.filter(Boolean).map((photo) => photo.media || photo) || [];
curatedRelease.covers = release.covers?.filter(Boolean).map(({ media }) => media) || []; curatedRelease.covers = release.covers?.filter(Boolean).map(({ media }) => media) || [];
@ -102,7 +103,7 @@ function curateRelease(release, type = 'scene') {
return curatedRelease; return curatedRelease;
} }
function curateEntity(entity, parent, releases) { function curateEntity(entity, parent, releases, context) {
const curatedEntity = { const curatedEntity = {
...entity, ...entity,
children: [], children: [],
@ -120,19 +121,19 @@ function curateEntity(entity, parent, releases) {
} }
if (entity.parent || parent) curatedEntity.parent = curateEntity(entity.parent || parent); if (entity.parent || parent) curatedEntity.parent = curateEntity(entity.parent || parent);
if (releases) curatedEntity.releases = releases.map((release) => curateRelease(release)); if (releases) curatedEntity.releases = releases.map((release) => curateRelease(release, 'scene', context));
curatedEntity.sceneTotal = entity.sceneTotal; curatedEntity.sceneTotal = entity.sceneTotal;
return curatedEntity; return curatedEntity;
} }
function curateTag(tag) { function curateTag(tag, context) {
const curatedTag = { const curatedTag = {
...tag, ...tag,
}; };
if (tag.releases) curatedTag.releases = tag.releases.map(({ release }) => curateRelease(release)); if (tag.releases) curatedTag.releases = tag.releases.map(({ release }) => curateRelease(release, 'scene', context));
if (tag.banners) curatedTag.banners = tag.banners.map(({ banner }) => banner); if (tag.banners) curatedTag.banners = tag.banners.map(({ banner }) => banner);
if (tag.photos) curatedTag.photos = tag.photos.map(({ media }) => media); if (tag.photos) curatedTag.photos = tag.photos.map(({ media }) => media);
if (tag.poster) curatedTag.poster = tag.poster.media; if (tag.poster) curatedTag.poster = tag.poster.media;
@ -140,14 +141,14 @@ function curateTag(tag) {
return curatedTag; return curatedTag;
} }
function curateStash(stash) { function curateStash(stash, context) {
const curatedStash = stash; const curatedStash = stash;
if (stash.scenes || stash.scenesConnection?.scenes) { if (stash.scenes || stash.scenesConnection?.scenes) {
curatedStash.sceneTotal = stash.scenesConnection?.totalCount || null; curatedStash.sceneTotal = stash.scenesConnection?.totalCount || null;
curatedStash.scenes = (stash.scenesConnection?.scenes || stash.scenes).map((item) => ({ curatedStash.scenes = (stash.scenesConnection?.scenes || stash.scenes).map((item) => ({
...item, ...item,
scene: curateRelease(item.scene), scene: curateRelease(item.scene, 'scene', context),
})); }));
} }
@ -163,7 +164,7 @@ function curateStash(stash) {
curatedStash.movieTotal = stash.moviesConnection?.totalCount || null; curatedStash.movieTotal = stash.moviesConnection?.totalCount || null;
curatedStash.movies = (stash.moviesConnection?.movies || stash.movies).map((item) => ({ curatedStash.movies = (stash.moviesConnection?.movies || stash.movies).map((item) => ({
...item, ...item,
movie: curateRelease(item.movie), movie: curateRelease(item.movie, 'movie', context),
})); }));
} }

View File

@ -1,6 +1,6 @@
import { graphql } from '../api'; import { graphql } from '../api';
// import { sitesFragment, releaseFields } from '../fragments'; // import { sitesFragment, releaseFields } from '../fragments';
import { releaseFields, campaignsFragment } from '../fragments'; import { releaseFields, batchFragment, campaignsFragment } from '../fragments';
import { curateEntity } from '../curate'; import { curateEntity } from '../curate';
import getDateRange from '../get-date-range'; import getDateRange from '../get-date-range';
@ -14,7 +14,7 @@ function initEntitiesActions(store, router) {
}) { }) {
const { before, after, orderBy } = getDateRange(range); const { before, after, orderBy } = getDateRange(range);
const { entity } = await graphql(` const { entity, batches: [lastBatch] } = await graphql(`
query Entity( query Entity(
$entitySlug: String! $entitySlug: String!
$entityType: String! = "channel" $entityType: String! = "channel"
@ -110,6 +110,7 @@ function initEntitiesActions(store, router) {
totalCount totalCount
} }
} }
${batchFragment}
} }
`, { `, {
entitySlug, entitySlug,
@ -130,7 +131,7 @@ function initEntitiesActions(store, router) {
} }
return { return {
entity: curateEntity(entity, null, entity.connection.releases), entity: curateEntity(entity, null, entity.connection.releases, { lastBatch: lastBatch.id }),
totalCount: entity.connection.totalCount, totalCount: entity.connection.totalCount,
}; };
} }

View File

@ -596,6 +596,12 @@ const releaseFragment = `
} }
`; `;
const batchFragment = `
batches(first: 1, orderBy: CREATED_AT_DESC) {
id
}
`;
function getIncludedEntities(router) { function getIncludedEntities(router) {
const includedChannels = router.currentRoute.value.query.channels ? router.currentRoute.value.query.channels.split(',') : []; const includedChannels = router.currentRoute.value.query.channels ? router.currentRoute.value.query.channels.split(',') : [];
const includedNetworks = router.currentRoute.value.query.networks ? router.currentRoute.value.query.networks.split(',') : []; const includedNetworks = router.currentRoute.value.query.networks ? router.currentRoute.value.query.networks.split(',') : [];
@ -662,6 +668,7 @@ function getIncludedActors(router) {
export { export {
actorFields, actorFields,
actorStashesFields, actorStashesFields,
batchFragment,
campaignsFragment, campaignsFragment,
mediaFields, mediaFields,
mediaFragment, mediaFragment,

View File

@ -1,5 +1,6 @@
import { graphql } from '../api'; import { graphql } from '../api';
import { import {
batchFragment,
releasesFragment, releasesFragment,
releaseFragment, releaseFragment,
releaseFields, releaseFields,
@ -14,7 +15,7 @@ function initReleasesActions(store, router) {
async function fetchReleases({ _commit }, { limit = 10, pageNumber = 1, range = 'latest' }) { async function fetchReleases({ _commit }, { limit = 10, pageNumber = 1, range = 'latest' }) {
const { before, after, orderBy } = getDateRange(range); const { before, after, orderBy } = getDateRange(range);
const { connection: { releases, totalCount } } = await graphql(` const { connection: { releases, totalCount }, batches: [lastBatch] } = await graphql(`
query Releases( query Releases(
$hasAuth: Boolean! $hasAuth: Boolean!
$userId: Int $userId: Int
@ -26,6 +27,7 @@ function initReleasesActions(store, router) {
$exclude: [String!] $exclude: [String!]
) { ) {
${releasesFragment} ${releasesFragment}
${batchFragment}
} }
`, { `, {
hasAuth: !!store.state.auth.user, hasAuth: !!store.state.auth.user,
@ -39,7 +41,7 @@ function initReleasesActions(store, router) {
}); });
return { return {
releases: releases.map((release) => curateRelease(release.release || release)), releases: releases.map((release) => curateRelease(release.release || release, 'scene', { lastBatch: lastBatch.id })),
totalCount, totalCount,
}; };
} }

View File

@ -1,6 +1,7 @@
import { graphql, get } from '../api'; import { graphql, get } from '../api';
import { import {
releaseFields, releaseFields,
batchFragment,
} from '../fragments'; } from '../fragments';
import { curateTag, curateRelease } from '../curate'; import { curateTag, curateRelease } from '../curate';
import getDateRange from '../get-date-range'; import getDateRange from '../get-date-range';
@ -14,7 +15,7 @@ function initTagsActions(store, _router) {
}) { }) {
const { before, after, orderBy } = getDateRange(range); const { before, after, orderBy } = getDateRange(range);
const { tagBySlug } = await graphql(` const { tagBySlug, batches: [lastBatch] } = await graphql(`
query Tag( query Tag(
$tagSlug:String! $tagSlug:String!
$offset: Int = 0, $offset: Int = 0,
@ -180,6 +181,7 @@ function initTagsActions(store, _router) {
totalCount totalCount
} }
} }
${batchFragment}
} }
`, { `, {
tagSlug, tagSlug,
@ -195,7 +197,7 @@ function initTagsActions(store, _router) {
return { return {
tag: curateTag(tagBySlug, null, curateRelease), tag: curateTag(tagBySlug, null, curateRelease),
releases: tagBySlug.scenesConnection.releases.map((release) => curateRelease(release)), releases: tagBySlug.scenesConnection.releases.map((release) => curateRelease(release, 'scene', { lastBatch: lastBatch.id })),
totalCount: tagBySlug.scenesConnection.totalCount, totalCount: tagBySlug.scenesConnection.totalCount,
}; };
} }

View File

@ -1,5 +1,5 @@
import { graphql, patch } from '../api'; import { graphql, patch } from '../api';
import { releaseFields, actorStashesFields } from '../fragments'; import { releaseFields, batchFragment, actorStashesFields } from '../fragments';
import { curateRelease, curateActor, curateNotification } from '../curate'; import { curateRelease, curateActor, curateNotification } from '../curate';
function initUiActions(store, _router) { function initUiActions(store, _router) {
@ -218,6 +218,7 @@ function initUiActions(store, _router) {
} }
${actorStashesFields} ${actorStashesFields}
} }
${batchFragment}
} }
`, { `, {
query, query,
@ -227,7 +228,7 @@ function initUiActions(store, _router) {
}); });
return { return {
releases: res?.results.map((result) => curateRelease(result.release)) || [], releases: res?.results.map((result) => curateRelease(result.release, 'scene', { lastBatch: res?.batches[0].id })) || [],
actors: res?.actors.map((actor) => curateActor(actor)) || [], actors: res?.actors.map((actor) => curateActor(actor)) || [],
}; };
} }