2024-07-14 12:28:44 +00:00
|
|
|
import { Route, Router } from "@solidjs/router";
|
|
|
|
import { ThemeProvider } from "@suid/material";
|
2024-07-15 05:59:10 +00:00
|
|
|
import {
|
|
|
|
Component,
|
2024-10-11 08:39:42 +00:00
|
|
|
createEffect,
|
|
|
|
createMemo,
|
2024-07-15 05:59:10 +00:00
|
|
|
createRenderEffect,
|
|
|
|
ErrorBoundary,
|
|
|
|
lazy,
|
2024-09-26 09:23:40 +00:00
|
|
|
onCleanup,
|
2024-07-15 05:59:10 +00:00
|
|
|
} from "solid-js";
|
2024-07-14 12:28:44 +00:00
|
|
|
import { useRootTheme } from "./material/mui.js";
|
2024-07-15 05:59:10 +00:00
|
|
|
import {
|
|
|
|
Provider as ClientProvider,
|
|
|
|
createMastoClientFor,
|
|
|
|
} from "./masto/clients.js";
|
2024-10-11 08:39:42 +00:00
|
|
|
import { $accounts, updateAcctInf } from "./accounts/stores.js";
|
2024-07-15 05:59:10 +00:00
|
|
|
import { useStore } from "@nanostores/solid";
|
2024-09-26 09:23:40 +00:00
|
|
|
import { DateFnScope, useLanguage } from "./platform/i18n.jsx";
|
2024-07-14 12:28:44 +00:00
|
|
|
|
|
|
|
const AccountSignIn = lazy(() => import("./accounts/SignIn.js"));
|
2024-07-15 05:59:10 +00:00
|
|
|
const AccountMastodonOAuth2Callback = lazy(
|
|
|
|
() => import("./accounts/MastodonOAuth2Callback.js"),
|
|
|
|
);
|
|
|
|
const TimelineHome = lazy(() => import("./timelines/Home.js"));
|
2024-07-22 13:57:04 +00:00
|
|
|
const Settings = lazy(() => import("./settings/Settings.js"));
|
2024-08-12 09:25:03 +00:00
|
|
|
const TootBottomSheet = lazy(() => import("./timelines/TootBottomSheet.js"));
|
2024-10-09 10:45:19 +00:00
|
|
|
const MotionSettings = lazy(() => import("./settings/Motions.js"));
|
2024-10-09 15:27:20 +00:00
|
|
|
const LanguageSettings = lazy(() => import("./settings/Language.js"));
|
|
|
|
const RegionSettings = lazy(() => import("./settings/Region.jsx"));
|
2024-10-11 08:39:42 +00:00
|
|
|
const UnexpectedError = lazy(() => import("./UnexpectedError.js"));
|
2024-07-14 12:28:44 +00:00
|
|
|
|
|
|
|
const Routing: Component = () => {
|
|
|
|
return (
|
|
|
|
<Router>
|
2024-07-22 13:57:04 +00:00
|
|
|
<Route path="/" component={TimelineHome}>
|
|
|
|
<Route path=""></Route>
|
2024-10-09 10:45:19 +00:00
|
|
|
<Route path="/settings" component={Settings}>
|
|
|
|
<Route path=""></Route>
|
2024-10-09 15:27:20 +00:00
|
|
|
<Route path="/language" component={LanguageSettings}></Route>
|
|
|
|
<Route path="/region" component={RegionSettings}></Route>
|
2024-10-09 10:45:19 +00:00
|
|
|
<Route path="/motions" component={MotionSettings}></Route>
|
|
|
|
</Route>
|
2024-08-12 09:25:03 +00:00
|
|
|
<Route path="/:acct/:id" component={TootBottomSheet}></Route>
|
2024-07-22 13:57:04 +00:00
|
|
|
</Route>
|
2024-07-14 12:28:44 +00:00
|
|
|
<Route path={"/accounts"}>
|
|
|
|
<Route path={"/sign-in"} component={AccountSignIn} />
|
2024-07-15 05:59:10 +00:00
|
|
|
<Route
|
|
|
|
path={"/oauth2/mastodon"}
|
|
|
|
component={AccountMastodonOAuth2Callback}
|
|
|
|
/>
|
2024-07-14 12:28:44 +00:00
|
|
|
</Route>
|
|
|
|
</Router>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
const App: Component = () => {
|
|
|
|
const theme = useRootTheme();
|
2024-07-15 05:59:10 +00:00
|
|
|
const accts = useStore($accounts);
|
2024-09-26 09:23:40 +00:00
|
|
|
const lang = useLanguage();
|
2024-07-15 05:59:10 +00:00
|
|
|
|
2024-10-11 08:39:42 +00:00
|
|
|
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);
|
|
|
|
},
|
|
|
|
);
|
|
|
|
}
|
2024-07-15 05:59:10 +00:00
|
|
|
});
|
|
|
|
|
2024-09-26 09:23:40 +00:00
|
|
|
createRenderEffect(() => {
|
|
|
|
const root = document.querySelector(":root")!;
|
|
|
|
root.setAttribute("lang", lang());
|
|
|
|
});
|
|
|
|
|
|
|
|
onCleanup(() => {
|
|
|
|
const root = document.querySelector(":root")!;
|
|
|
|
root.removeAttribute("lang");
|
|
|
|
});
|
|
|
|
|
2024-07-14 12:28:44 +00:00
|
|
|
return (
|
2024-07-15 05:59:10 +00:00
|
|
|
<ErrorBoundary
|
|
|
|
fallback={(err, reset) => {
|
|
|
|
console.error(err);
|
2024-08-05 08:24:34 +00:00
|
|
|
return <UnexpectedError error={err} />;
|
2024-07-15 05:59:10 +00:00
|
|
|
}}
|
|
|
|
>
|
|
|
|
<ThemeProvider theme={theme()}>
|
2024-09-26 09:23:40 +00:00
|
|
|
<DateFnScope>
|
2024-10-11 08:39:42 +00:00
|
|
|
<ClientProvider value={clients}>
|
2024-09-26 09:23:40 +00:00
|
|
|
<Routing />
|
|
|
|
</ClientProvider>
|
|
|
|
</DateFnScope>
|
2024-07-15 05:59:10 +00:00
|
|
|
</ThemeProvider>
|
|
|
|
</ErrorBoundary>
|
2024-07-14 12:28:44 +00:00
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default App;
|