43 lines
1.9 kB
1
import { useStateFromStores } from "@moonlight-mod/wp/discord/packages/flux";
2
import { MoonbaseSettingsStore } from "@moonlight-mod/wp/moonbase_stores";
3
import { Button, CircleWarningIcon } from "@moonlight-mod/wp/discord/components/common/index";
4
import React from "@moonlight-mod/wp/react";
5
import { RestartAdvice } from "../../types";
6
import HelpMessage from "./HelpMessage";
7
8
const strings: Record<RestartAdvice, string> = {
9
[RestartAdvice.NotNeeded]: "how did you even",
10
[RestartAdvice.ReloadSuggested]: "A reload might be needed to apply some of the changed options.",
11
[RestartAdvice.ReloadNeeded]: "A reload is needed to apply some of the changed options.",
12
[RestartAdvice.RestartNeeded]: "A restart is needed to apply some of the changed options."
13
};
14
15
const buttonStrings: Record<RestartAdvice, string> = {
16
[RestartAdvice.NotNeeded]: "huh?",
17
[RestartAdvice.ReloadSuggested]: "Reload",
18
[RestartAdvice.ReloadNeeded]: "Reload",
19
[RestartAdvice.RestartNeeded]: "Restart"
20
};
21
22
const actions: Record<RestartAdvice, () => void> = {
23
[RestartAdvice.NotNeeded]: () => {},
24
[RestartAdvice.ReloadSuggested]: () => window.location.reload(),
25
[RestartAdvice.ReloadNeeded]: () => window.location.reload(),
26
[RestartAdvice.RestartNeeded]: () => MoonbaseSettingsStore.restartDiscord()
27
};
28
29
export default function RestartAdviceMessage() {
30
const restartAdvice = useStateFromStores([MoonbaseSettingsStore], () => MoonbaseSettingsStore.restartAdvice);
31
32
if (restartAdvice === RestartAdvice.NotNeeded) return null;
33
34
return (
35
<div className="moonbase-help-message-sticky">
36
<HelpMessage text={strings[restartAdvice]} icon={CircleWarningIcon} type="warning">
37
<Button color={Button.Colors.YELLOW} size={Button.Sizes.TINY} onClick={actions[restartAdvice]}>
38
{buttonStrings[restartAdvice]}
39
</Button>
40
</HelpMessage>
41
</div>
42
);
43
}
44