From 6ad794eae59939d788126dc48316aa9193f3360c Mon Sep 17 00:00:00 2001 From: thislight Date: Tue, 23 Jul 2024 08:28:47 +0800 Subject: [PATCH] Settings: prefetching toots --- src/settings/Settings.tsx | 10 +++++++++- src/settings/stores.ts | 6 +++++- src/timelines/Home.tsx | 7 +++++-- 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/src/settings/Settings.tsx b/src/settings/Settings.tsx index e93de43..40bbffd 100644 --- a/src/settings/Settings.tsx +++ b/src/settings/Settings.tsx @@ -23,9 +23,12 @@ import { css } from "solid-styled"; import { useSignedInProfiles } from "../masto/acct.js"; import { signOut, type Account } from "../accounts/stores.js"; import { intlFormat } from "date-fns"; +import { useStore } from "@nanostores/solid"; +import { $settings } from "./stores.js"; const Settings: ParentComponent = () => { const navigate = useNavigate(); + const settings$ = useStore($settings); const [profiles] = useSignedInProfiles(); @@ -96,7 +99,12 @@ const Settings: ParentComponent = () => { Prefetch Toots - + + $settings.setKey("prefetchTootsDisabled", !e.target.checked) + } + /> diff --git a/src/settings/stores.ts b/src/settings/stores.ts index 7d71ac0..d3ddc24 100644 --- a/src/settings/stores.ts +++ b/src/settings/stores.ts @@ -2,6 +2,10 @@ import { persistentMap } from "@nanostores/persistent"; type Settings = { onGoingOAuth2Process?: string + prefetchTootsDisabled?: boolean } -export const $settings = persistentMap("settings::", {}) +export const $settings = persistentMap("settings::", {}, { + encode: JSON.stringify, + decode: JSON.parse +}) diff --git a/src/timelines/Home.tsx b/src/timelines/Home.tsx index 0738a37..8d14d76 100644 --- a/src/timelines/Home.tsx +++ b/src/timelines/Home.tsx @@ -35,6 +35,8 @@ import { Create as CreateTootIcon } from "@suid/icons-material"; import { useTimeline } from "../masto/timelines"; import { makeEventListener } from "@solid-primitives/event-listener"; import BottomSheet from "../material/BottomSheet"; +import { $settings } from "../settings/stores"; +import { useStore } from "@nanostores/solid"; const TimelinePanel: Component<{ client: mastodon.rest.Client; @@ -153,12 +155,13 @@ const Home: ParentComponent = (props) => { useDocumentTitle("Timelines"); const now = createTimeSource(); + const settings$ = useStore($settings) const sessions = useSessions(); const client = () => sessions()[0].client; const [profile] = useAcctProfile(client); const [panelOffset, setPanelOffset] = createSignal(0); - const [prefetching, setPrefetching] = createSignal(true); + const prefetching = () => !settings$().prefetchTootsDisabled const [currentFocusOn, setCurrentFocusOn] = createSignal([]); const [focusRange, setFocusRange] = createSignal([0, 0] as readonly [ number, @@ -279,7 +282,7 @@ const Home: ParentComponent = (props) => { - setPrefetching((x) => !x)}> + $settings.setKey("prefetchTootsDisabled", !$settings.get().prefetchTootsDisabled)}> Prefetch Toots