Skip to content

Commit

Permalink
Merge pull request #139 from Suwayomi/main
Browse files Browse the repository at this point in the history
some Tracking stuff
  • Loading branch information
Robonau authored Jan 23, 2024
2 parents 00b14c3 + 4849aaa commit dfc0420
Show file tree
Hide file tree
Showing 12 changed files with 299 additions and 147 deletions.
3 changes: 2 additions & 1 deletion schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -995,7 +995,8 @@ enum WebUIInterface {
input BindTrackInput {
clientMutationId: String
mangaId: Int!
trackSearchId: Int!
remoteId: LongString!
trackerId: Int!
}
input BooleanFilterInput {
distinctFrom: Boolean
Expand Down
2 changes: 2 additions & 0 deletions src/gql/Fragments.gql
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ fragment CategoryTypeFragment on CategoryType {
default
order
name
includeInDownload
includeInUpdate
mangas {
totalCount
}
Expand Down
40 changes: 34 additions & 6 deletions src/gql/Mutations.gql
Original file line number Diff line number Diff line change
Expand Up @@ -246,8 +246,20 @@ mutation updateCategoryOrder($id: Int!, $position: Int!) {
}
}

mutation createCategory($name: String!, $default: Boolean!) {
createCategory(input: { name: $name, default: $default }) {
mutation createCategory(
$name: String!
$default: Boolean!
$includeInDownload: IncludeOrExclude!
$includeInUpdate: IncludeOrExclude!
) {
createCategory(
input: {
name: $name
default: $default
includeInDownload: $includeInDownload
includeInUpdate: $includeInUpdate
}
) {
category {
...CategoryTypeFragment
}
Expand All @@ -262,8 +274,24 @@ mutation deleteCategory($categoryId: Int!) {
}
}

mutation updateCategory($id: Int!, $name: String = null, $default: Boolean = null) {
updateCategory(input: { id: $id, patch: { default: $default, name: $name } }) {
mutation updateCategory(
$id: Int!
$name: String = null
$default: Boolean = null
$includeInDownload: IncludeOrExclude = null
$includeInUpdate: IncludeOrExclude = null
) {
updateCategory(
input: {
id: $id
patch: {
default: $default
name: $name
includeInDownload: $includeInDownload
includeInUpdate: $includeInUpdate
}
}
) {
category {
...CategoryTypeFragment
}
Expand Down Expand Up @@ -460,8 +488,8 @@ mutation loginTrackerCredentials($password: String!, $trackerId: Int!, $username
}
}

mutation bindTrack($trackSearchId: Int!, $mangaId: Int!) {
bindTrack(input: { mangaId: $mangaId, trackSearchId: $trackSearchId }) {
mutation bindTrack($mangaId: Int!, $remoteId: LongString!, $trackerId: Int!) {
bindTrack(input: { mangaId: $mangaId, remoteId: $remoteId, trackerId: $trackerId }) {
trackRecord {
...TrackRecordTypeFragment
}
Expand Down
42 changes: 28 additions & 14 deletions src/lib/generated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ export type BackupRestoreStatus = {
export type BindTrackInput = {
clientMutationId?: InputMaybe<Scalars['String']['input']>;
mangaId: Scalars['Int']['input'];
trackSearchId: Scalars['Int']['input'];
remoteId: Scalars['LongString']['input'];
trackerId: Scalars['Int']['input'];
};

export type BindTrackPayload = {
Expand Down Expand Up @@ -2455,7 +2456,7 @@ export type SourceTypeFragmentFragment = { __typename?: 'SourceType', id: any, d

export type ExtensionTypeFragmentFragment = { __typename?: 'ExtensionType', name: string, repo?: string | null, versionName: string, pkgName: string, lang: string, iconUrl: string, isNsfw: boolean, isInstalled: boolean, isObsolete: boolean, hasUpdate: boolean };

export type CategoryTypeFragmentFragment = { __typename?: 'CategoryType', id: number, default: boolean, order: number, name: string, mangas: { __typename?: 'MangaNodeList', totalCount: number } };
export type CategoryTypeFragmentFragment = { __typename?: 'CategoryType', id: number, default: boolean, order: number, name: string, includeInDownload: IncludeOrExclude, includeInUpdate: IncludeOrExclude, mangas: { __typename?: 'MangaNodeList', totalCount: number } };

export type TrackerTypeFragmentFragment = { __typename?: 'TrackerType', authUrl?: string | null, icon: string, id: number, isLoggedIn: boolean, name: string };

Expand Down Expand Up @@ -2577,31 +2578,35 @@ export type UpdateCategoryOrderMutationVariables = Exact<{
}>;


export type UpdateCategoryOrderMutation = { __typename?: 'Mutation', updateCategoryOrder: { __typename?: 'UpdateCategoryOrderPayload', categories: Array<{ __typename?: 'CategoryType', id: number, default: boolean, order: number, name: string, mangas: { __typename?: 'MangaNodeList', totalCount: number } }> } };
export type UpdateCategoryOrderMutation = { __typename?: 'Mutation', updateCategoryOrder: { __typename?: 'UpdateCategoryOrderPayload', categories: Array<{ __typename?: 'CategoryType', id: number, default: boolean, order: number, name: string, includeInDownload: IncludeOrExclude, includeInUpdate: IncludeOrExclude, mangas: { __typename?: 'MangaNodeList', totalCount: number } }> } };

export type CreateCategoryMutationVariables = Exact<{
name: Scalars['String']['input'];
default: Scalars['Boolean']['input'];
includeInDownload: IncludeOrExclude;
includeInUpdate: IncludeOrExclude;
}>;


export type CreateCategoryMutation = { __typename?: 'Mutation', createCategory: { __typename?: 'CreateCategoryPayload', category: { __typename?: 'CategoryType', id: number, default: boolean, order: number, name: string, mangas: { __typename?: 'MangaNodeList', totalCount: number } } } };
export type CreateCategoryMutation = { __typename?: 'Mutation', createCategory: { __typename?: 'CreateCategoryPayload', category: { __typename?: 'CategoryType', id: number, default: boolean, order: number, name: string, includeInDownload: IncludeOrExclude, includeInUpdate: IncludeOrExclude, mangas: { __typename?: 'MangaNodeList', totalCount: number } } } };

export type DeleteCategoryMutationVariables = Exact<{
categoryId: Scalars['Int']['input'];
}>;


export type DeleteCategoryMutation = { __typename?: 'Mutation', deleteCategory: { __typename?: 'DeleteCategoryPayload', category?: { __typename?: 'CategoryType', id: number, default: boolean, order: number, name: string, mangas: { __typename?: 'MangaNodeList', totalCount: number } } | null } };
export type DeleteCategoryMutation = { __typename?: 'Mutation', deleteCategory: { __typename?: 'DeleteCategoryPayload', category?: { __typename?: 'CategoryType', id: number, default: boolean, order: number, name: string, includeInDownload: IncludeOrExclude, includeInUpdate: IncludeOrExclude, mangas: { __typename?: 'MangaNodeList', totalCount: number } } | null } };

export type UpdateCategoryMutationVariables = Exact<{
id: Scalars['Int']['input'];
name?: InputMaybe<Scalars['String']['input']>;
default?: InputMaybe<Scalars['Boolean']['input']>;
includeInDownload?: InputMaybe<IncludeOrExclude>;
includeInUpdate?: InputMaybe<IncludeOrExclude>;
}>;


export type UpdateCategoryMutation = { __typename?: 'Mutation', updateCategory: { __typename?: 'UpdateCategoryPayload', category: { __typename?: 'CategoryType', id: number, default: boolean, order: number, name: string, mangas: { __typename?: 'MangaNodeList', totalCount: number } } } };
export type UpdateCategoryMutation = { __typename?: 'Mutation', updateCategory: { __typename?: 'UpdateCategoryPayload', category: { __typename?: 'CategoryType', id: number, default: boolean, order: number, name: string, includeInDownload: IncludeOrExclude, includeInUpdate: IncludeOrExclude, mangas: { __typename?: 'MangaNodeList', totalCount: number } } } };

export type UpdateMangasCategoriesMutationVariables = Exact<{
addTo?: InputMaybe<Array<Scalars['Int']['input']> | Scalars['Int']['input']>;
Expand Down Expand Up @@ -2745,8 +2750,9 @@ export type LoginTrackerCredentialsMutationVariables = Exact<{
export type LoginTrackerCredentialsMutation = { __typename?: 'Mutation', loginTrackerCredentials: { __typename?: 'LoginTrackerCredentialsPayload', tracker: { __typename?: 'TrackerType', authUrl?: string | null, icon: string, id: number, isLoggedIn: boolean, name: string } } };

export type BindTrackMutationVariables = Exact<{
trackSearchId: Scalars['Int']['input'];
mangaId: Scalars['Int']['input'];
remoteId: Scalars['LongString']['input'];
trackerId: Scalars['Int']['input'];
}>;


Expand All @@ -2764,7 +2770,7 @@ export type CategoriesQueryVariables = Exact<{
}>;


export type CategoriesQuery = { __typename?: 'Query', categories: { __typename?: 'CategoryNodeList', nodes: Array<{ __typename?: 'CategoryType', id: number, default: boolean, order: number, name: string, mangas: { __typename?: 'MangaNodeList', totalCount: number } }> } };
export type CategoriesQuery = { __typename?: 'Query', categories: { __typename?: 'CategoryNodeList', nodes: Array<{ __typename?: 'CategoryType', id: number, default: boolean, order: number, name: string, includeInDownload: IncludeOrExclude, includeInUpdate: IncludeOrExclude, mangas: { __typename?: 'MangaNodeList', totalCount: number } }> } };

export type CategoryQueryVariables = Exact<{
id: Scalars['Int']['input'];
Expand Down Expand Up @@ -3018,6 +3024,8 @@ export const CategoryTypeFragmentFragmentDoc = gql`
default
order
name
includeInDownload
includeInUpdate
mangas {
totalCount
}
Expand Down Expand Up @@ -3252,8 +3260,10 @@ export const UpdateCategoryOrderDoc = gql`
}
${CategoryTypeFragmentFragmentDoc}`;
export const CreateCategoryDoc = gql`
mutation createCategory($name: String!, $default: Boolean!) {
createCategory(input: {name: $name, default: $default}) {
mutation createCategory($name: String!, $default: Boolean!, $includeInDownload: IncludeOrExclude!, $includeInUpdate: IncludeOrExclude!) {
createCategory(
input: {name: $name, default: $default, includeInDownload: $includeInDownload, includeInUpdate: $includeInUpdate}
) {
category {
...CategoryTypeFragment
}
Expand All @@ -3270,8 +3280,10 @@ export const DeleteCategoryDoc = gql`
}
${CategoryTypeFragmentFragmentDoc}`;
export const UpdateCategoryDoc = gql`
mutation updateCategory($id: Int!, $name: String = null, $default: Boolean = null) {
updateCategory(input: {id: $id, patch: {default: $default, name: $name}}) {
mutation updateCategory($id: Int!, $name: String = null, $default: Boolean = null, $includeInDownload: IncludeOrExclude = null, $includeInUpdate: IncludeOrExclude = null) {
updateCategory(
input: {id: $id, patch: {default: $default, name: $name, includeInDownload: $includeInDownload, includeInUpdate: $includeInUpdate}}
) {
category {
...CategoryTypeFragment
}
Expand Down Expand Up @@ -3482,8 +3494,10 @@ export const LoginTrackerCredentialsDoc = gql`
}
${TrackerTypeFragmentFragmentDoc}`;
export const BindTrackDoc = gql`
mutation bindTrack($trackSearchId: Int!, $mangaId: Int!) {
bindTrack(input: {mangaId: $mangaId, trackSearchId: $trackSearchId}) {
mutation bindTrack($mangaId: Int!, $remoteId: LongString!, $trackerId: Int!) {
bindTrack(
input: {mangaId: $mangaId, remoteId: $remoteId, trackerId: $trackerId}
) {
trackRecord {
...TrackRecordTypeFragment
}
Expand Down
10 changes: 1 addition & 9 deletions src/lib/simpleStores.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,7 @@ const mangaMetaDefaults = {
NavLayout: Layout.L,
preLoadNextChapter: true,
mobileFullScreenOnChapterPage: true,
doPageIndicator: false,
mangaUpdatesSeriesID: null as null | number
doPageIndicator: false
};
type mangaMeta = typeof mangaMetaDefaults;

Expand Down Expand Up @@ -234,13 +233,6 @@ export function MangaMeta(id: number) {
const MMeta = getManga({ variables: { id } });
const store = writable(get(Meta).mangaMetaDefaults);

if (get(store).mangaUpdatesSeriesID === undefined) {
store.update((n) => {
n.mangaUpdatesSeriesID = mangaMetaDefaults.mangaUpdatesSeriesID;
return n;
});
}

MMeta.subscribe((queryResult) => {
store.update((value) => {
return extractMangaMeta(value, queryResult);
Expand Down
58 changes: 57 additions & 1 deletion src/lib/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,19 @@
// file, You can obtain one at http://mozilla.org/MPL/2.0/.

import { get, type Writable } from 'svelte/store';
import { deleteDownloadedChapters, enqueueChapterDownloads, updateChapters } from './generated';
import {
deleteDownloadedChapters,
enqueueChapterDownloads,
updateChapters,
type BindTrackMutation,
type UpdateTrackMutation,
type GetMangaQuery,
GetMangaDoc
} from './generated';
import type { FetchResult } from '@apollo/client/link/core';

import { toastStore } from './simpleStores';
import type { ApolloCache } from '@apollo/client';

export type TriState = 0 | 1 | 2;

Expand Down Expand Up @@ -234,3 +243,50 @@ export function getObjectKeys<T extends object>(obj: T): (keyof T)[] {
export function getObjectEntries<T extends object>(obj: T): [keyof T, T[keyof T]][] {
return Object.entries(obj) as [keyof T, T[keyof T]][];
}

export function unbindUpdater(
cache: ApolloCache<unknown>,
{ data }: FetchResult<UpdateTrackMutation>,
MangaId: number,
tabSet: number
) {
if (!data) return;
const mangaData = structuredClone(
cache.readQuery<GetMangaQuery>({
query: GetMangaDoc,
variables: { id: MangaId }
})
);
if (!mangaData || !mangaData.manga) return;
const mga = mangaData.manga;
mga.trackRecords.nodes = mga.trackRecords.nodes.filter((ee) => ee.trackerId !== tabSet);
cache.writeQuery({
query: GetMangaDoc,
variables: { id: MangaId },
data: { manga: mga }
});
}

export function bindTrackUpdater(
cache: ApolloCache<unknown>,
{ data }: FetchResult<BindTrackMutation>,
MangaId: number,
tabSet: number
) {
if (!data || !data?.bindTrack?.trackRecord) return;
const mangaData = structuredClone(
cache.readQuery<GetMangaQuery>({
query: GetMangaDoc,
variables: { id: MangaId }
})
);
if (!mangaData || !mangaData.manga) return;
const mga = mangaData.manga;
mga.trackRecords.nodes = mga.trackRecords.nodes.filter((ee) => ee.trackerId !== tabSet);
mga.trackRecords.nodes.push(data.bindTrack.trackRecord);
cache.writeQuery({
query: GetMangaDoc,
variables: { id: MangaId },
data: { manga: mga }
});
}
44 changes: 34 additions & 10 deletions src/routes/(app)/browse/migrate/manga/[MangaID]/migrateModal.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,11 @@
updateMangas,
type CategoryQuery,
type GetMangaQuery,
type UpdateMangaCategoriesMutation
type UpdateMangaCategoriesMutation,
bindTrack,
updateTrack
} from '$lib/generated';
import { MangaMeta } from '$lib/simpleStores';
import { bindTrackUpdater, unbindUpdater } from '$lib/util';
import type { ApolloCache, FetchResult } from '@apollo/client';
import { ProgressRadial, getModalStore } from '@skeletonlabs/skeleton';
import type { SvelteComponent } from 'svelte';
Expand All @@ -37,7 +39,6 @@
let MigrateLoading = false;
let CopyLoading = false;
const mangaMeta = MangaMeta(id);
async function MigrateManga() {
MigrateLoading = true;
Expand All @@ -60,15 +61,17 @@
await updateMangas({
variables: { ids: id, inLibrary: true }
});
const ToDo: Promise<void>[] = [];
if (doChapters) {
await CopyMangaChapters();
ToDo.push(CopyMangaChapters());
}
if (doCategories) {
await CopyMangaCategories();
ToDo.push(CopyMangaCategories());
}
if (doTracking) {
await CopyMangaTracking();
ToDo.push(CopyMangaTracking());
}
await Promise.all(ToDo);
parent.onClose();
}
Expand Down Expand Up @@ -258,10 +261,31 @@
});
}
async function CopyMangaTracking() {
$mangaMeta.mangaUpdatesSeriesID =
JSON.parse(manga.meta.find((e) => e.key === 'VUI3_mangaUpdatesSeriesID')?.value ?? 'null') ??
null;
async function CopyMangaTracking(): Promise<void> {
const trackers = manga.trackRecords.nodes;
await Promise.all(
trackers.map(async (tracker) => {
try {
await updateTrack({
variables: {
input: {
unbind: true,
recordId: tracker.id
}
},
update: (a, b) => unbindUpdater(a, b, id, tracker.trackerId)
});
await bindTrack({
variables: {
mangaId: id,
trackerId: tracker.trackerId,
remoteId: tracker.remoteId
},
update: (a, b) => bindTrackUpdater(a, b, id, tracker.trackerId)
});
} catch {}
})
);
}
</script>

Expand Down
Loading

0 comments on commit dfc0420

Please sign in to comment.