From a7b0f480acd819375d960bd24dab46bbb720878a Mon Sep 17 00:00:00 2001 From: thislight Date: Sat, 14 Sep 2024 19:55:37 +0800 Subject: [PATCH] Settings: ask user to refresh if update available --- src/settings/Settings.tsx | 71 +++++++++++++++++++++++---------------- tsconfig.json | 2 +- 2 files changed, 43 insertions(+), 30 deletions(-) diff --git a/src/settings/Settings.tsx b/src/settings/Settings.tsx index 56cca5e..9eebcac 100644 --- a/src/settings/Settings.tsx +++ b/src/settings/Settings.tsx @@ -1,4 +1,4 @@ -import { createResource, For, type ParentComponent } from "solid-js"; +import { For, Show, type ParentComponent } from "solid-js"; import Scaffold from "../material/Scaffold.js"; import { AppBar, @@ -10,25 +10,29 @@ import { ListItemSecondaryAction, ListItemText, ListSubheader, - NativeSelect, - Select, Switch, Toolbar, } from "@suid/material"; -import { Close as CloseIcon } from "@suid/icons-material"; +import { + Close as CloseIcon, + Refresh as RefreshIcon, +} from "@suid/icons-material"; import { useNavigate } from "@solidjs/router"; import { Title } from "../material/typography.jsx"; -import { useSessions } from "../masto/clients.js"; 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"; +import { useRegisterSW } from "virtual:pwa-register/solid"; const Settings: ParentComponent = () => { const navigate = useNavigate(); const settings$ = useStore($settings); + const { + needRefresh: [needRefresh], + } = useRegisterSW(); const [profiles] = useSignedInProfiles(); @@ -49,7 +53,10 @@ const Settings: ParentComponent = () => { - + @@ -65,12 +72,14 @@ const Settings: ParentComponent = () => { All Notifications - + + Sign in... + {({ account: acct, inf }) => ( @@ -79,12 +88,14 @@ const Settings: ParentComponent = () => { Notifications - + + Sign out + )} @@ -94,32 +105,23 @@ const Settings: ParentComponent = () => { Fonts - - $settings.setKey("prefetchTootsDisabled", !settings$().prefetchTootsDisabled) - }> + + + $settings.setKey( + "prefetchTootsDisabled", + !settings$().prefetchTootsDisabled, + ) + } + > Prefetch Toots - - - - -
  • - Controls - - Optimized UI - - - - - - - + +
  • This Application @@ -128,13 +130,24 @@ const Settings: ParentComponent = () => { About Tutu + - No updates + {needRefresh() + ? "An update is ready, restart the Tutu to apply" + : "No updates"} + + + window.location.reload()}> + + + + +
  • diff --git a/tsconfig.json b/tsconfig.json index 137e232..ccd018b 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -8,7 +8,7 @@ "esModuleInterop": true, "jsx": "preserve", "jsxImportSource": "solid-js", - "types": ["vite/client"], + "types": ["vite/client", "vite-plugin-pwa/solid"], "noEmit": true, "isolatedModules": true, }