-
-
Notifications
You must be signed in to change notification settings - Fork 65
/
index.tsx
176 lines (157 loc) · 5.51 KB
/
index.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
/**
* Configure contexts and render App
*/
import {
JSX,
Show,
createEffect,
createMemo,
createResource,
createSignal,
on,
onMount,
lazy,
} from "solid-js";
import { createStore } from "solid-js/store";
import { render } from "solid-js/web";
import { attachDevtoolsOverlay } from "@solid-devtools/overlay";
import * as i18n from "@solid-primitives/i18n";
import { Navigate, Route, Router } from "@solidjs/router";
import { QueryClient, QueryClientProvider } from "@tanstack/solid-query";
import { isTauri } from "@tauri-apps/api/core";
import { getCurrentWindow } from "@tauri-apps/api/window";
import FlowCheck from "@revolt/auth/src/flows/FlowCheck";
import FlowConfirmReset from "@revolt/auth/src/flows/FlowConfirmReset";
import FlowCreate from "@revolt/auth/src/flows/FlowCreate";
import FlowHome from "@revolt/auth/src/flows/FlowHome";
import FlowLogin from "@revolt/auth/src/flows/FlowLogin";
import FlowResend from "@revolt/auth/src/flows/FlowResend";
import FlowReset from "@revolt/auth/src/flows/FlowReset";
import FlowVerify from "@revolt/auth/src/flows/FlowVerify";
import {
I18nContext,
dict,
fetchLanguage,
language,
setLanguage,
} from "@revolt/i18n";
import { ModalRenderer, modalController } from "@revolt/modal";
import { state } from "@revolt/state";
import {
ApplyGlobalStyles,
FloatingManager,
KeybindsProvider,
Masks,
ProvideDirectives,
ThemeProvider,
Titlebar,
darkTheme,
} from "@revolt/ui";
/* @refresh reload */
import "@revolt/ui/styles";
import AuthPage from "./Auth";
import Interface from "./Interface";
import "./index.css";
import { DevelopmentPage } from "./interface/Development";
import { Friends } from "./interface/Friends";
import { HomePage } from "./interface/Home";
import { ServerHome } from "./interface/ServerHome";
import { ChannelPage } from "./interface/channels/ChannelPage";
import "./sentry";
import { registerKeybindsWithPriority } from "./shared/lib/priorityKeybind";
import { ConfirmDelete } from "./interface/ConfirmDelete";
attachDevtoolsOverlay();
/** TEMPORARY */
function MountTheme(props: { children: any }) {
const [accent, setAccent] = createSignal("#FF5733");
const [darkMode, setDarkMode] = createSignal(false);
(window as any)._demo_setAccent = setAccent;
(window as any)._demo_setDarkMode = setDarkMode;
const [theme, setTheme] = createStore(darkTheme(accent(), darkMode()));
createEffect(
on(
() => [accent(), darkMode()] as [string, boolean],
([accent, darkMode]) => setTheme(darkTheme(accent, darkMode))
)
);
return <ThemeProvider theme={theme}>{props.children}</ThemeProvider>;
}
/** END TEMPORARY */
/**
* Redirect PWA start to the last active path
*/function PWARedirect() {
return <Navigate href={state.layout.getLastActivePath()} />;
}
/**
* Open settings and redirect to last active path
*/
function SettingsRedirect() {
onMount(() => modalController.push({ type: "settings", config: "user" }));
return <PWARedirect />;
}
const client = new QueryClient();
function MountContext(props: { children?: JSX.Element }) {
const [dictionary] = createResource(language, fetchLanguage, {
initialValue: i18n.flatten(dict.en),
});
const t = createMemo(() => i18n.translator(dictionary, i18n.resolveTemplate));
const appWindow = isTauri() ? getCurrentWindow() : null;
return (
<I18nContext.Provider value={t()}>
<QueryClientProvider client={client}>
<Masks />
<MountTheme>
<ProvideDirectives>
<KeybindsProvider keybinds={() => state.keybinds.getKeybinds()}>
<Show when={window.__TAURI__}>
<Titlebar
isBuildDev={import.meta.env.DEV}
onMinimize={() => appWindow?.minimize?.()}
onMaximize={() => appWindow?.toggleMaximize?.()}
onClose={() => appWindow?.hide?.()}
/>
</Show>
{props.children}
</KeybindsProvider>
<ModalRenderer />
<FloatingManager />
<ApplyGlobalStyles />
</ProvideDirectives>
</MountTheme>
</QueryClientProvider>
</I18nContext.Provider>
);
}
registerKeybindsWithPriority();
state.hydrate().then(() =>
render(
() => (
<Router root={MountContext}>
<Route path="/login" component={AuthPage as never}>
<Route path="/delete/:token" component={ConfirmDelete} />
<Route path="/check" component={FlowCheck} />
<Route path="/create" component={FlowCreate} />
<Route path="/auth" component={FlowLogin} />
<Route path="/resend" component={FlowResend} />
<Route path="/reset" component={FlowReset} />
<Route path="/verify/:token" component={FlowVerify} />
<Route path="/reset/:token" component={FlowConfirmReset} />
<Route path="/*" component={FlowHome} />
</Route>
<Route path="/" component={Interface as never}>
<Route path="/pwa" component={PWARedirect} />
<Route path="/dev" component={DevelopmentPage} />
<Route path="/settings" component={SettingsRedirect} />
<Route path="/friends" component={Friends} />
<Route path="/server/:server/*">
<Route path="/channel/:channel/*" component={ChannelPage} />
<Route path="/*" component={ServerHome} />
</Route>
<Route path="/channel/:channel/*" component={ChannelPage} />
<Route path="/*" component={HomePage} />
</Route>
</Router>
),
document.getElementById("root") as HTMLElement
)
);