App: fix the clients change is not notified
This commit is contained in:
parent
fd47639bef
commit
bd3ad078a2
4 changed files with 122 additions and 79 deletions
39
src/App.tsx
39
src/App.tsx
|
@ -2,8 +2,9 @@ import { Route, Router } from "@solidjs/router";
|
|||
import { ThemeProvider } from "@suid/material";
|
||||
import {
|
||||
Component,
|
||||
createEffect,
|
||||
createMemo,
|
||||
createRenderEffect,
|
||||
createSignal,
|
||||
ErrorBoundary,
|
||||
lazy,
|
||||
onCleanup,
|
||||
|
@ -12,9 +13,8 @@ import { useRootTheme } from "./material/mui.js";
|
|||
import {
|
||||
Provider as ClientProvider,
|
||||
createMastoClientFor,
|
||||
type Session,
|
||||
} from "./masto/clients.js";
|
||||
import { $accounts } from "./accounts/stores.js";
|
||||
import { $accounts, updateAcctInf } from "./accounts/stores.js";
|
||||
import { useStore } from "@nanostores/solid";
|
||||
import { DateFnScope, useLanguage } from "./platform/i18n.jsx";
|
||||
|
||||
|
@ -28,6 +28,7 @@ const TootBottomSheet = lazy(() => import("./timelines/TootBottomSheet.js"));
|
|||
const MotionSettings = lazy(() => import("./settings/Motions.js"));
|
||||
const LanguageSettings = lazy(() => import("./settings/Language.js"));
|
||||
const RegionSettings = lazy(() => import("./settings/Region.jsx"));
|
||||
const UnexpectedError = lazy(() => import("./UnexpectedError.js"));
|
||||
|
||||
const Routing: Component = () => {
|
||||
return (
|
||||
|
@ -56,14 +57,30 @@ const Routing: Component = () => {
|
|||
const App: Component = () => {
|
||||
const theme = useRootTheme();
|
||||
const accts = useStore($accounts);
|
||||
const clientStore = createSignal<Session[]>([]);
|
||||
const lang = useLanguage();
|
||||
|
||||
createRenderEffect(() => {
|
||||
const [, setClients] = clientStore;
|
||||
setClients(
|
||||
accts().map((x) => ({ account: x, client: createMastoClientFor(x) })),
|
||||
);
|
||||
const clients = createMemo(() => {
|
||||
return accts().map((x) => ({
|
||||
account: x,
|
||||
client: createMastoClientFor(x),
|
||||
}));
|
||||
});
|
||||
|
||||
createEffect(() => {
|
||||
const neededUpdates = accts()
|
||||
.map((x, i) => [i, x] as const)
|
||||
.filter(([, x]) => !x.inf);
|
||||
if (neededUpdates.length > 0) {
|
||||
// FIXME: we might need some kind of concurrent control
|
||||
Promise.all(neededUpdates.map(([i]) => updateAcctInf(i))).then(
|
||||
(x) => {
|
||||
console.info("acct info updated for %d acct(s)", x.length);
|
||||
},
|
||||
(reason) => {
|
||||
console.error("acct info update is fail", reason);
|
||||
},
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
createRenderEffect(() => {
|
||||
|
@ -76,8 +93,6 @@ const App: Component = () => {
|
|||
root.removeAttribute("lang");
|
||||
});
|
||||
|
||||
const UnexpectedError = lazy(() => import("./UnexpectedError.js"));
|
||||
|
||||
return (
|
||||
<ErrorBoundary
|
||||
fallback={(err, reset) => {
|
||||
|
@ -87,7 +102,7 @@ const App: Component = () => {
|
|||
>
|
||||
<ThemeProvider theme={theme()}>
|
||||
<DateFnScope>
|
||||
<ClientProvider value={clientStore}>
|
||||
<ClientProvider value={clients}>
|
||||
<Routing />
|
||||
</ClientProvider>
|
||||
</DateFnScope>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue