forked from aeharding/voyager
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.ts
48 lines (36 loc) · 988 Bytes
/
app.ts
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
import React, { useEffect, useState } from "react";
const DEFAULT_LEMMY_SERVERS = [
"lemmy.world",
"lemmy.ml",
"beehaw.org",
"sh.itjust.works",
];
let _customServers = DEFAULT_LEMMY_SERVERS;
export function getCustomServers() {
return _customServers;
}
export function getDefaultServer() {
return _customServers[0];
}
async function getConfig() {
const response = await fetch("/_config");
const { customServers } = await response.json();
if (customServers?.length) {
_customServers = customServers;
}
}
// Only needs to be done once for app load
const config = getConfig();
interface ConfigProviderProps {
children?: React.ReactNode;
}
export default function ConfigProvider({ children }: ConfigProviderProps) {
const [configLoaded, setConfigLoaded] = useState(false);
useEffect(() => {
// Config is not necessary for app to run
config.finally(() => {
setConfigLoaded(true);
});
}, []);
if (configLoaded) return children;
}