From d31ef908099076d9922eb909a97534f8df386bd6 Mon Sep 17 00:00:00 2001 From: Robonau <30987265+Robonau@users.noreply.github> Date: Tue, 9 Apr 2024 18:29:38 +0100 Subject: [PATCH 1/2] fix tracking cause server guys changed how it works for no reason --- .../[MangaID]/chapter/[ChapterID]/+page.svelte | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/routes/(app)/manga/[MangaID]/chapter/[ChapterID]/+page.svelte b/src/routes/(app)/manga/[MangaID]/chapter/[ChapterID]/+page.svelte index c63ded8a..5d9d81e3 100644 --- a/src/routes/(app)/manga/[MangaID]/chapter/[ChapterID]/+page.svelte +++ b/src/routes/(app)/manga/[MangaID]/chapter/[ChapterID]/+page.svelte @@ -27,7 +27,11 @@ } from '@urql/svelte'; import { getManga } from '$lib/gql/Queries'; import { type ResultOf } from '$lib/gql/graphql'; - import { fetchChapterPages, updateChapter } from '$lib/gql/Mutations'; + import { + fetchChapterPages, + updateChapter, + updateTrack + } from '$lib/gql/Mutations'; import { ChapterTypeFragment } from '$lib/gql/Fragments'; export let data: PageData; @@ -395,6 +399,18 @@ isRead: pageIndex >= maxPages * 0.8 ? true : null }) .toPromise(); + if (pageIndex >= maxPages * 0.8) { + $manga.data?.manga.trackRecords.nodes.forEach((e) => { + client.mutation(updateTrack, { + input: { + recordId: e.id, + lastChapterRead: $manga.data?.manga.chapters.nodes.find( + (e) => e.id === id + )?.chapterNumber + } + }); + }); + } updatedChaps.push(selector); setTimeout(() => { updatedChaps = updatedChaps.filter((e) => e !== selector); From 8f3fe914f6d6d8d523f6a2bb1b91573787c832d2 Mon Sep 17 00:00:00 2001 From: Robonau <30987265+Robonau@users.noreply.github> Date: Tue, 9 Apr 2024 18:54:02 +0100 Subject: [PATCH 2/2] trackProgress not update track --- src/lib/gql/Mutations.ts | 13 +++++++++++ src/lib/gql/graphqlClient.ts | 21 ++++++++++++++++++ .../chapter/[ChapterID]/+page.svelte | 22 +++++++------------ 3 files changed, 42 insertions(+), 14 deletions(-) diff --git a/src/lib/gql/Mutations.ts b/src/lib/gql/Mutations.ts index 12244ba7..33269386 100644 --- a/src/lib/gql/Mutations.ts +++ b/src/lib/gql/Mutations.ts @@ -929,3 +929,16 @@ export const fetchTrack = graphql(` } } `); + +export const trackProgress = graphql( + ` + mutation trackProgress($mangaId: Int!) { + trackProgress(input: { mangaId: $mangaId }) { + trackRecords { + ...TrackRecordTypeFragment + } + } + } + `, + [TrackRecordTypeFragment] +); diff --git a/src/lib/gql/graphqlClient.ts b/src/lib/gql/graphqlClient.ts index 06ce5126..736dd980 100644 --- a/src/lib/gql/graphqlClient.ts +++ b/src/lib/gql/graphqlClient.ts @@ -35,6 +35,7 @@ import type { setGlobalMeta, setMangaMeta, setServerSettings, + trackProgress, unbindTrack, updateExtension, updateMangaCategories, @@ -210,6 +211,13 @@ export const client = new Client({ const res = result as ResultOf; const variables = info.variables as VariablesOf; unbindTrackUpdater(res, variables, cache); + }, + trackProgress(result, _, cache, info) { + const res = result as ResultOf; + const variables = info.variables as VariablesOf< + typeof trackProgress + >; + trackProgressUpdater(res, variables, cache); } }, Query: { @@ -246,6 +254,19 @@ export const client = new Client({ ] }); +function trackProgressUpdater( + data: ResultOf | undefined, + vars: VariablesOf, + cache: Cache +) { + if (!data) return; + data.trackProgress.trackRecords.forEach((record) => { + cache.writeFragment(TrackRecordTypeFragment, record, { + id: record.id + }); + }); +} + function unbindTrackUpdater( data: ResultOf | undefined, vars: VariablesOf, diff --git a/src/routes/(app)/manga/[MangaID]/chapter/[ChapterID]/+page.svelte b/src/routes/(app)/manga/[MangaID]/chapter/[ChapterID]/+page.svelte index 5d9d81e3..683d7942 100644 --- a/src/routes/(app)/manga/[MangaID]/chapter/[ChapterID]/+page.svelte +++ b/src/routes/(app)/manga/[MangaID]/chapter/[ChapterID]/+page.svelte @@ -29,8 +29,8 @@ import { type ResultOf } from '$lib/gql/graphql'; import { fetchChapterPages, - updateChapter, - updateTrack + trackProgress, + updateChapter } from '$lib/gql/Mutations'; import { ChapterTypeFragment } from '$lib/gql/Fragments'; @@ -398,19 +398,13 @@ lastPageRead: pageIndex, isRead: pageIndex >= maxPages * 0.8 ? true : null }) - .toPromise(); - if (pageIndex >= maxPages * 0.8) { - $manga.data?.manga.trackRecords.nodes.forEach((e) => { - client.mutation(updateTrack, { - input: { - recordId: e.id, - lastChapterRead: $manga.data?.manga.chapters.nodes.find( - (e) => e.id === id - )?.chapterNumber - } - }); + .toPromise() + .then(() => { + if ($manga.data?.manga?.id) + client.mutation(trackProgress, { + mangaId: $manga.data?.manga?.id + }); }); - } updatedChaps.push(selector); setTimeout(() => { updatedChaps = updatedChaps.filter((e) => e !== selector);