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,
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,
};
}

View File

@ -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),
}));
}

View File

@ -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,
};
}

View File

@ -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,

View File

@ -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,
};
}

View File

@ -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,
};
}

View File

@ -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)) || [],
};
}