From c4424f30eced15994025b46092c65e8657e687a0 Mon Sep 17 00:00:00 2001 From: DebaucheryLibrarian Date: Fri, 16 Jun 2023 00:47:19 +0200 Subject: [PATCH] Restored 'new' label client-side. --- assets/js/actors/actions.js | 6 ++++-- assets/js/curate.js | 25 +++++++++++++------------ assets/js/entities/actions.js | 7 ++++--- assets/js/fragments.js | 7 +++++++ assets/js/releases/actions.js | 6 ++++-- assets/js/tags/actions.js | 6 ++++-- assets/js/ui/actions.js | 5 +++-- 7 files changed, 39 insertions(+), 23 deletions(-) diff --git a/assets/js/actors/actions.js b/assets/js/actors/actions.js index 95a61d78..d5ac5040 100755 --- a/assets/js/actors/actions.js +++ b/assets/js/actors/actions.js @@ -10,6 +10,7 @@ import { actorStashesFields, getIncludedEntities, getIncludedActors, + batchFragment, } from '../fragments'; 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 mode = router.currentRoute.value.query.mode || 'all'; - const { actor } = await graphql(` + const { actor, batches: [lastBatch] } = await graphql(` query Actor( $actorId: Int! $userId: Int, @@ -254,6 +255,7 @@ function initActorActions(store, router) { } ${actorStashesFields} } + ${batchFragment} } `, { actorId, @@ -281,7 +283,7 @@ function initActorActions(store, router) { return { 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, }; } diff --git a/assets/js/curate.js b/assets/js/curate.js index 96bce5c8..ece3535f 100755 --- a/assets/js/curate.js +++ b/assets/js/curate.js @@ -65,19 +65,20 @@ function curateActor(actor, release) { return curatedActor; } -function curateRelease(release, type = 'scene') { +function curateRelease(release, type = 'scene', context = {}) { const curatedRelease = { ...release, type: release.type || type, actors: [], poster: release.poster && release.poster.media, 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.movies = release.movies?.filter(Boolean).map(({ movie }) => curateRelease(movie, 'movie')) || []; - curatedRelease.series = release.series?.filter(Boolean).map(({ serie }) => curateRelease(serie, 'serie')) || []; - curatedRelease.chapters = release.chapters?.filter(Boolean).map((chapter) => curateRelease(chapter)) || []; + curatedRelease.scenes = release.scenes?.filter(Boolean).map(({ scene }) => curateRelease(scene, 'scene', context)) || []; + curatedRelease.movies = release.movies?.filter(Boolean).map(({ movie }) => curateRelease(movie, 'movie', context)) || []; + curatedRelease.series = release.series?.filter(Boolean).map(({ serie }) => curateRelease(serie, 'serie', context)) || []; + curatedRelease.chapters = release.chapters?.filter(Boolean).map((chapter) => curateRelease(chapter, 'chapter', context)) || []; curatedRelease.photos = release.photos?.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) || []; @@ -102,7 +103,7 @@ function curateRelease(release, type = 'scene') { return curatedRelease; } -function curateEntity(entity, parent, releases) { +function curateEntity(entity, parent, releases, context) { const curatedEntity = { ...entity, children: [], @@ -120,19 +121,19 @@ function curateEntity(entity, parent, releases) { } 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; return curatedEntity; } -function curateTag(tag) { +function curateTag(tag, context) { const curatedTag = { ...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.photos) curatedTag.photos = tag.photos.map(({ media }) => media); if (tag.poster) curatedTag.poster = tag.poster.media; @@ -140,14 +141,14 @@ function curateTag(tag) { return curatedTag; } -function curateStash(stash) { +function curateStash(stash, context) { const curatedStash = stash; if (stash.scenes || stash.scenesConnection?.scenes) { curatedStash.sceneTotal = stash.scenesConnection?.totalCount || null; curatedStash.scenes = (stash.scenesConnection?.scenes || stash.scenes).map((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.movies = (stash.moviesConnection?.movies || stash.movies).map((item) => ({ ...item, - movie: curateRelease(item.movie), + movie: curateRelease(item.movie, 'movie', context), })); } diff --git a/assets/js/entities/actions.js b/assets/js/entities/actions.js index 0aa0a037..f82d3416 100755 --- a/assets/js/entities/actions.js +++ b/assets/js/entities/actions.js @@ -1,6 +1,6 @@ import { graphql } from '../api'; // import { sitesFragment, releaseFields } from '../fragments'; -import { releaseFields, campaignsFragment } from '../fragments'; +import { releaseFields, batchFragment, campaignsFragment } from '../fragments'; import { curateEntity } from '../curate'; import getDateRange from '../get-date-range'; @@ -14,7 +14,7 @@ function initEntitiesActions(store, router) { }) { const { before, after, orderBy } = getDateRange(range); - const { entity } = await graphql(` + const { entity, batches: [lastBatch] } = await graphql(` query Entity( $entitySlug: String! $entityType: String! = "channel" @@ -110,6 +110,7 @@ function initEntitiesActions(store, router) { totalCount } } + ${batchFragment} } `, { entitySlug, @@ -130,7 +131,7 @@ function initEntitiesActions(store, router) { } return { - entity: curateEntity(entity, null, entity.connection.releases), + entity: curateEntity(entity, null, entity.connection.releases, { lastBatch: lastBatch.id }), totalCount: entity.connection.totalCount, }; } diff --git a/assets/js/fragments.js b/assets/js/fragments.js index b9e6334c..8ffe9dba 100755 --- a/assets/js/fragments.js +++ b/assets/js/fragments.js @@ -596,6 +596,12 @@ const releaseFragment = ` } `; +const batchFragment = ` + batches(first: 1, orderBy: CREATED_AT_DESC) { + id + } +`; + function getIncludedEntities(router) { 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(',') : []; @@ -662,6 +668,7 @@ function getIncludedActors(router) { export { actorFields, actorStashesFields, + batchFragment, campaignsFragment, mediaFields, mediaFragment, diff --git a/assets/js/releases/actions.js b/assets/js/releases/actions.js index e0bf7434..7b44687e 100755 --- a/assets/js/releases/actions.js +++ b/assets/js/releases/actions.js @@ -1,5 +1,6 @@ import { graphql } from '../api'; import { + batchFragment, releasesFragment, releaseFragment, releaseFields, @@ -14,7 +15,7 @@ function initReleasesActions(store, router) { async function fetchReleases({ _commit }, { limit = 10, pageNumber = 1, range = 'latest' }) { const { before, after, orderBy } = getDateRange(range); - const { connection: { releases, totalCount } } = await graphql(` + const { connection: { releases, totalCount }, batches: [lastBatch] } = await graphql(` query Releases( $hasAuth: Boolean! $userId: Int @@ -26,6 +27,7 @@ function initReleasesActions(store, router) { $exclude: [String!] ) { ${releasesFragment} + ${batchFragment} } `, { hasAuth: !!store.state.auth.user, @@ -39,7 +41,7 @@ function initReleasesActions(store, router) { }); return { - releases: releases.map((release) => curateRelease(release.release || release)), + releases: releases.map((release) => curateRelease(release.release || release, 'scene', { lastBatch: lastBatch.id })), totalCount, }; } diff --git a/assets/js/tags/actions.js b/assets/js/tags/actions.js index 1bc8442c..d9ee2cda 100755 --- a/assets/js/tags/actions.js +++ b/assets/js/tags/actions.js @@ -1,6 +1,7 @@ import { graphql, get } from '../api'; import { releaseFields, + batchFragment, } from '../fragments'; import { curateTag, curateRelease } from '../curate'; import getDateRange from '../get-date-range'; @@ -14,7 +15,7 @@ function initTagsActions(store, _router) { }) { const { before, after, orderBy } = getDateRange(range); - const { tagBySlug } = await graphql(` + const { tagBySlug, batches: [lastBatch] } = await graphql(` query Tag( $tagSlug:String! $offset: Int = 0, @@ -180,6 +181,7 @@ function initTagsActions(store, _router) { totalCount } } + ${batchFragment} } `, { tagSlug, @@ -195,7 +197,7 @@ function initTagsActions(store, _router) { return { 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, }; } diff --git a/assets/js/ui/actions.js b/assets/js/ui/actions.js index 3e45aefe..5ffeeb38 100755 --- a/assets/js/ui/actions.js +++ b/assets/js/ui/actions.js @@ -1,5 +1,5 @@ import { graphql, patch } from '../api'; -import { releaseFields, actorStashesFields } from '../fragments'; +import { releaseFields, batchFragment, actorStashesFields } from '../fragments'; import { curateRelease, curateActor, curateNotification } from '../curate'; function initUiActions(store, _router) { @@ -218,6 +218,7 @@ function initUiActions(store, _router) { } ${actorStashesFields} } + ${batchFragment} } `, { query, @@ -227,7 +228,7 @@ function initUiActions(store, _router) { }); 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)) || [], }; }