Skip to content

Commit

Permalink
Merge pull request #110 from Suwayomi/main
Browse files Browse the repository at this point in the history
spread vs structuredClone on FF is an issue
  • Loading branch information
Robonau authored Dec 11, 2023
2 parents 6bb327e + f031e2e commit 60bed17
Show file tree
Hide file tree
Showing 7 changed files with 91 additions and 81 deletions.
38 changes: 20 additions & 18 deletions src/routes/(app)/(library)/LibraryMassCategoryModal.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -54,61 +54,63 @@
mangaIds.forEach((id) => {
try {
const { manga } = {
...cache.readQuery<GetMangaQuery>({
const mangaData = structuredClone(
cache.readQuery<GetMangaQuery>({
query: GetMangaDoc,
variables: { id }
})
};
if (!manga) return;
manga.categories.nodes = selectedCategories.map((categoryId) => ({
);
if (!mangaData) return;
mangaData.manga.categories.nodes = selectedCategories.map((categoryId) => ({
__typename: 'CategoryType',
id: categoryId
}));
cache.writeQuery({
query: GetMangaDoc,
variables: { id },
data: { manga }
data: mangaData
});
} catch (error) {}
});
const currentCategoryId = $tab ?? 0;
const { category: currentCategory } = {
...cache.readQuery<CategoryQuery>({
const currentCategoryData = structuredClone(
cache.readQuery<CategoryQuery>({
query: CategoryDoc,
variables: { id: currentCategoryId }
})
};
if (!currentCategory) return;
const mangas = currentCategory.mangas.nodes.filter((manga) => mangaIds.includes(manga.id));
);
if (!currentCategoryData) return;
const mangas = currentCategoryData.category.mangas.nodes.filter((manga) =>
mangaIds.includes(manga.id)
);
$categories.data.categories.nodes.forEach(({ id }) => {
try {
const { category: oldCategoryData } = {
...cache.readQuery<CategoryQuery>({
const oldCategoryData = structuredClone(
cache.readQuery<CategoryQuery>({
query: CategoryDoc,
variables: { id }
})
};
);
if (!oldCategoryData) return;
if (defaultCategory.includes(id)) {
const mangasToAdd: CategoryQuery['category']['mangas']['nodes'] = [];
mangas.forEach((manga) => {
if (!oldCategoryData.mangas.nodes.find((m) => m.id === manga.id)) {
if (!oldCategoryData.category.mangas.nodes.find((m) => m.id === manga.id)) {
mangasToAdd.push(manga);
}
});
oldCategoryData.mangas.nodes.push(...mangasToAdd);
oldCategoryData.category.mangas.nodes.push(...mangasToAdd);
} else {
oldCategoryData.mangas.nodes = oldCategoryData.mangas.nodes.filter(
oldCategoryData.category.mangas.nodes = oldCategoryData.category.mangas.nodes.filter(
(m) => !mangaIds.includes(m.id)
);
}
cache.writeQuery({
query: CategoryDoc,
variables: { id },
data: { category: oldCategoryData }
data: oldCategoryData
});
} catch {}
});
Expand Down
2 changes: 1 addition & 1 deletion src/routes/(app)/browse/globalSearch.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
$: filteredSources, $query, onQueryChange();
function onQueryChange() {
const Query = $query;
alterableRaw = [...(filteredSources ?? [])];
alterableRaw = structuredClone(filteredSources);
queue.clear();
if (Query) {
filteredSources?.forEach(async (souc) => {
Expand Down
48 changes: 25 additions & 23 deletions src/routes/(app)/manga/[MangaID]/(manga)/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,16 @@
) {
if (!data) return;
const magna = { ...$manga.data.manga };
magna.chapters.totalCount = data.fetchChapters.chapters.length;
magna.chapters.nodes = data.fetchChapters.chapters;
const magna2 = {
...$manga.data.manga,
totalCount: data.fetchChapters.chapters.length,
nodes: data.fetchChapters.chapters
};
cache.writeQuery({
query: GetMangaDoc,
variables: { id: magna.id },
data: { manga: magna }
variables: { id: magna2.id },
data: { manga: magna2 }
});
}
Expand All @@ -60,23 +61,24 @@
) {
if (!data) return;
const magna = { ...$manga.data.manga };
magna.artist = data.fetchManga.manga.artist;
magna.author = data.fetchManga.manga.author;
magna.description = data.fetchManga.manga.description;
magna.downloadCount = data.fetchManga.manga.downloadCount;
magna.genre = data.fetchManga.manga.genre;
magna.id = data.fetchManga.manga.id;
magna.inLibrary = data.fetchManga.manga.inLibrary;
magna.lastFetchedAt = data.fetchManga.manga.lastFetchedAt;
magna.meta = data.fetchManga.manga.meta;
magna.realUrl = data.fetchManga.manga.realUrl;
magna.source = data.fetchManga.manga.source;
magna.status = data.fetchManga.manga.status;
magna.thumbnailUrl = data.fetchManga.manga.thumbnailUrl;
magna.title = data.fetchManga.manga.title;
magna.unreadCount = data.fetchManga.manga.unreadCount;
const magna = {
...$manga.data.manga,
artist: data.fetchManga.manga.artist,
author: data.fetchManga.manga.author,
description: data.fetchManga.manga.description,
downloadCount: data.fetchManga.manga.downloadCount,
genre: data.fetchManga.manga.genre,
id: data.fetchManga.manga.id,
inLibrary: data.fetchManga.manga.inLibrary,
lastFetchedAt: data.fetchManga.manga.lastFetchedAt,
meta: data.fetchManga.manga.meta,
realUrl: data.fetchManga.manga.realUrl,
source: data.fetchManga.manga.source,
status: data.fetchManga.manga.status,
thumbnailUrl: data.fetchManga.manga.thumbnailUrl,
title: data.fetchManga.manga.title,
unreadCount: data.fetchManga.manga.unreadCount
};
cache.writeQuery({
query: GetMangaDoc,
Expand Down
52 changes: 28 additions & 24 deletions src/routes/(app)/manga/[MangaID]/(manga)/MangaCatagoryModal.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -88,38 +88,38 @@
nodes.forEach((newNode) => {
if (oldNodes.find((oldNode) => oldNode.id === newNode.id)) return;
try {
const { category } = structuredClone(
cache.readQuery({
const categoryData = structuredClone(
cache.readQuery<CategoryQuery>({
query: CategoryDoc,
variables: { id: newNode.id }
})
) as CategoryQuery;
category.mangas.nodes.push(currentManga);
);
if (!categoryData) return;
categoryData.category.mangas.nodes.push(currentManga);
cache.writeQuery({
query: CategoryDoc,
variables: { id: newNode.id },
data: { category }
data: categoryData
});
} catch {}
});
// add to 0 if now in default
if (nodes.length === 0 && oldNodes.length > 0) {
try {
const { category } = structuredClone(
cache.readQuery({
const categoryData = structuredClone(
cache.readQuery<CategoryQuery>({
query: CategoryDoc,
variables: { id: 0 }
})
) as CategoryQuery;
category.mangas.nodes.push(currentManga);
);
if (!categoryData) return;
categoryData.category.mangas.nodes.push(currentManga);
cache.writeQuery({
query: CategoryDoc,
variables: { id: 0 },
data: { category }
data: categoryData
});
} catch {}
}
Expand All @@ -129,39 +129,43 @@
oldNodes.forEach((oldNode) => {
if (nodes.find((newNode) => oldNode.id === newNode.id)) return;
try {
const { category } = structuredClone(
cache.readQuery({
const categoryData = structuredClone(
cache.readQuery<CategoryQuery>({
query: CategoryDoc,
variables: { id: oldNode.id }
})
) as CategoryQuery;
category.mangas.nodes = category.mangas.nodes.filter((e) => e.id !== manga.id);
);
if (!categoryData) return;
categoryData.category.mangas.nodes = categoryData.category.mangas.nodes.filter(
(e) => e.id !== manga.id
);
cache.writeQuery({
query: CategoryDoc,
variables: { id: oldNode.id },
data: { category }
data: categoryData
});
} catch {}
});
// remove from 0 if no longer in default
if (oldNodes.length === 0 && nodes.length > 0) {
//remove from default
try {
const { category } = structuredClone(
cache.readQuery({
const categoryData = structuredClone(
cache.readQuery<CategoryQuery>({
query: CategoryDoc,
variables: { id: 0 }
})
) as CategoryQuery;
category.mangas.nodes = category.mangas.nodes.filter((e) => e.id !== manga.id);
);
if (!categoryData) return;
categoryData.category.mangas.nodes = categoryData.category.mangas.nodes.filter(
(e) => e.id !== manga.id
);
cache.writeQuery({
query: CategoryDoc,
variables: { id: 0 },
data: { category }
data: categoryData
});
} catch {}
}
Expand Down
6 changes: 3 additions & 3 deletions src/routes/(app)/manga/[MangaID]/(manga)/chaptersSide.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,12 @@
fetchPolicy: 'network-only'
});
fetchChapter.then((e) => {
const mangaData = {
...cache.readQuery<GetMangaQuery>({
const mangaData = structuredClone(
cache.readQuery<GetMangaQuery>({
query: GetMangaDoc,
variables: { id: MangaID }
})
};
);
if (!mangaData || !mangaData.manga) return;
const mga = mangaData.manga;
Expand Down
14 changes: 8 additions & 6 deletions src/routes/(app)/settings/categories/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -53,17 +53,19 @@
{ data }: Omit<FetchResult<DeleteCategoryMutation>, 'context'>
) {
if (!data) return;
const { categories } = structuredClone(
cache.readQuery({
const categoriesData = structuredClone(
cache.readQuery<CategoriesQuery>({
query: CategoriesDoc
})
) as CategoriesQuery;
categories.nodes = categories.nodes.filter((e) => e.id !== data.deleteCategory.category?.id);
);
if (!categoriesData) return;
categoriesData.categories.nodes = categoriesData.categories.nodes.filter(
(e) => e.id !== data.deleteCategory.category?.id
);
cache.writeQuery({
query: CategoriesDoc,
data: { categories }
data: categoriesData
});
}
Expand Down
12 changes: 6 additions & 6 deletions src/routes/(app)/settings/categories/CategoriesNewModal.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,17 @@
{ data }: Omit<FetchResult<CreateCategoryMutation>, 'context'>
) {
if (!data) return;
const { categories } = structuredClone(
cache.readQuery({
const categoriesData = structuredClone(
cache.readQuery<CategoriesQuery>({
query: CategoriesDoc
})
) as CategoriesQuery;
categories.nodes.push(data.createCategory.category);
);
if (!categoriesData) return;
categoriesData.categories.nodes.push(data.createCategory.category);
cache.writeQuery({
query: CategoriesDoc,
data: { categories }
data: categoriesData
});
}
Expand Down

0 comments on commit 60bed17

Please sign in to comment.