Skip to content

Commit

Permalink
trackProgress not update track
Browse files Browse the repository at this point in the history
  • Loading branch information
Robonau authored and Robonau committed Apr 9, 2024
1 parent d31ef90 commit 8f3fe91
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 14 deletions.
13 changes: 13 additions & 0 deletions src/lib/gql/Mutations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -929,3 +929,16 @@ export const fetchTrack = graphql(`
}
}
`);

export const trackProgress = graphql(
`
mutation trackProgress($mangaId: Int!) {
trackProgress(input: { mangaId: $mangaId }) {
trackRecords {
...TrackRecordTypeFragment
}
}
}
`,
[TrackRecordTypeFragment]
);
21 changes: 21 additions & 0 deletions src/lib/gql/graphqlClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import type {
setGlobalMeta,
setMangaMeta,
setServerSettings,
trackProgress,
unbindTrack,
updateExtension,
updateMangaCategories,
Expand Down Expand Up @@ -210,6 +211,13 @@ export const client = new Client({
const res = result as ResultOf<typeof unbindTrack>;
const variables = info.variables as VariablesOf<typeof unbindTrack>;
unbindTrackUpdater(res, variables, cache);
},
trackProgress(result, _, cache, info) {
const res = result as ResultOf<typeof trackProgress>;
const variables = info.variables as VariablesOf<
typeof trackProgress
>;
trackProgressUpdater(res, variables, cache);
}
},
Query: {
Expand Down Expand Up @@ -246,6 +254,19 @@ export const client = new Client({
]
});

function trackProgressUpdater(
data: ResultOf<typeof trackProgress> | undefined,
vars: VariablesOf<typeof trackProgress>,
cache: Cache
) {
if (!data) return;
data.trackProgress.trackRecords.forEach((record) => {
cache.writeFragment(TrackRecordTypeFragment, record, {
id: record.id
});
});
}

function unbindTrackUpdater(
data: ResultOf<typeof unbindTrack> | undefined,
vars: VariablesOf<typeof unbindTrack>,
Expand Down
22 changes: 8 additions & 14 deletions src/routes/(app)/manga/[MangaID]/chapter/[ChapterID]/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 8f3fe91

Please sign in to comment.