Skip to content

Commit

Permalink
Merge pull request #244 from Suwayomi/main
Browse files Browse the repository at this point in the history
fix extensions auto re-loading
  • Loading branch information
Robonau authored Nov 21, 2024
2 parents 13521c7 + 512d278 commit 3d23eee
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 38 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ jobs:
working-directory: ./build
run: zip -r Suwayomi-VUI-Web-${{ needs.GenTag.outputs.value }}.zip ./*
- name: Release
uses: softprops/action-gh-release@v1
uses: softprops/action-gh-release@v2
with:
files: |
./build/Suwayomi-VUI-Web-${{ needs.GenTag.outputs.value }}.zip
Expand Down
20 changes: 13 additions & 7 deletions src/lib/gql/graphqlClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ import type {
updateTrack
} from './Mutations';
import type { ResultOf, VariablesOf } from '$lib/gql/graphql';
import { lastFetched } from '../../../src/routes/(app)/browse/extensions/ExtensionsStores';
import { introspection } from '../../graphql-env';
import { gmState } from '$lib/simpleStores.svelte';
import type { DownloadChanged } from './Subscriptions';
Expand Down Expand Up @@ -631,14 +630,21 @@ function fetchExtensionsUpdater(
) {
if (!data?.fetchExtensions) return;
let filteredExtensions = data.fetchExtensions.extensions;
if (!gmState.value.nsfw)
filteredExtensions = filteredExtensions.filter((e) => !e.isNsfw);
filteredExtensions.forEach((e) => {
cache.writeFragment(ExtensionTypeFragment, e, {
isNsfw: gmState.value.nsfw ? null : false
import('$lib/simpleStores.svelte').then((mod) => {
const gmState = mod.gmState;
if (!gmState.value.nsfw)
filteredExtensions = filteredExtensions.filter((e) => !e.isNsfw);
filteredExtensions.forEach((e) => {
cache.writeFragment(ExtensionTypeFragment, e, {
isNsfw: gmState.value.nsfw ? null : false
});
});
import('../../../src/routes/(app)/browse/extensions/ExtensionsStores').then(
(mod) => {
mod.lastFetched.value = new Date();
}
);
});
lastFetched.set(new Date());
}

function updateMangasCategoriesUpdater(
Expand Down
48 changes: 25 additions & 23 deletions src/lib/simpleStores.svelte.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,44 +118,46 @@ const trueDefaults = {

const metaKeyBase = 'VUI3_';

class LocalStore<T> {
private val = $state<T>() as T;
type json<T> = {
stringify: (value: T) => string;
parse: (value: string) => T;
};

export class LocalStore<T> {
value = $state<T>() as T;
private key = '';
private serializer: json<T> = JSON;

constructor(key: string, value: T) {
this.val = value;
constructor(key: string, value: T, serializer: json<T> = JSON) {
this.value = value;
this.key = key;
this.serializer = serializer;
if (browser) {
const item = localStorage.getItem(this.key);
if (item) this.val = this.deserialize(item);
}
$effect.root(() => {
$effect(() => {
localStorage.setItem(key, this.serialize(this.value));
if (item) this.value = this.deserialize(item);
$effect.root(() => {
$effect(() => {
localStorage.setItem(key, this.serialize(this.value));
});
});
});
}
}

private serialize(value: T): string {
return JSON.stringify(value);
return this.serializer.stringify(value);
}

private deserialize(item: string): T {
return JSON.parse(item);
}

get value() {
return this.val;
}

set value(value: T) {
this.val = value;
localStorage.setItem(this.key, this.serialize(value));
return this.serializer.parse(item);
}
}

function localStore<T>(key: string, value: T) {
return new LocalStore(key, value);
export function localStore<T>(
key: string,
value: T,
serializer: json<T> = JSON
) {
return new LocalStore(key, value, serializer);
}

function convertOldTriState(value: unknown): TriState {
Expand Down
4 changes: 2 additions & 2 deletions src/routes/(app)/browse/extensions/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,12 @@
checkIfFetchNewExtensions();
async function checkIfFetchNewExtensions() {
if ($lastFetched.getTime() > new Date().getTime() - 60000) {
if (lastFetched.value.getTime() < new Date().getTime() - 60000) {
await ErrorHelp(
'failed to fetch new extensions',
client.mutation(fetchExtensions, {}).toPromise()
);
$lastFetched = new Date();
lastFetched.value = new Date();
}
extensions = queryState({
client,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
'failed to fetch new extensions',
client.mutation(fetchExtensions, {}).toPromise()
);
$lastFetched = new Date();
lastFetched.value = new Date();
loading = false;
}
Expand Down
7 changes: 3 additions & 4 deletions src/routes/(app)/browse/extensions/ExtensionsStores.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,14 @@
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.

import { localStore } from '$lib/simpleStores.svelte';
import { localStorageStore } from '@skeletonlabs/skeleton';
import * as devalue from 'devalue';

export const lastFetched = localStorageStore<Date>(
export const lastFetched = localStore(
'lastFetchedExtensions',
new Date(0),
{
serializer: devalue
}
devalue
);

export const langFilter = localStorageStore<Set<string>>(
Expand Down

0 comments on commit 3d23eee

Please sign in to comment.