Skip to content

Commit

Permalink
Merge pull request #183 from Suwayomi/main
Browse files Browse the repository at this point in the history
trackProgress
  • Loading branch information
Robonau authored Apr 9, 2024
2 parents 89d457b + 8f3fe91 commit bce13a4
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 2 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
14 changes: 12 additions & 2 deletions src/routes/(app)/manga/[MangaID]/chapter/[ChapterID]/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -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,
trackProgress,
updateChapter
} from '$lib/gql/Mutations';
import { ChapterTypeFragment } from '$lib/gql/Fragments';
export let data: PageData;
Expand Down Expand Up @@ -394,7 +398,13 @@
lastPageRead: pageIndex,
isRead: pageIndex >= maxPages * 0.8 ? true : null
})
.toPromise();
.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 bce13a4

Please sign in to comment.