47 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 * as Components 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 { Button } = Components;
9
10
const strings: Record<RestartAdvice, string> = {
11
[RestartAdvice.NotNeeded]: "how did you even",
12
[RestartAdvice.ReloadSuggested]: "A reload might be needed to apply some of the changed options.",
13
[RestartAdvice.ReloadNeeded]: "A reload is needed to apply some of the changed options.",
14
[RestartAdvice.RestartNeeded]: "A restart is needed to apply some of the changed options."
15
};
16
17
const buttonStrings: Record<RestartAdvice, string> = {
18
[RestartAdvice.NotNeeded]: "huh?",
19
[RestartAdvice.ReloadSuggested]: "Reload",
20
[RestartAdvice.ReloadNeeded]: "Reload",
21
[RestartAdvice.RestartNeeded]: "Restart"
22
};
23
24
const actions: Record<RestartAdvice, () => void> = {
25
[RestartAdvice.NotNeeded]: () => {},
26
[RestartAdvice.ReloadSuggested]: () => window.location.reload(),
27
[RestartAdvice.ReloadNeeded]: () => window.location.reload(),
28
[RestartAdvice.RestartNeeded]: () => MoonbaseSettingsStore.restartDiscord()
29
};
30
31
const { CircleWarningIcon } = Components;
32
33
export default function RestartAdviceMessage() {
34
const restartAdvice = useStateFromStores([MoonbaseSettingsStore], () => MoonbaseSettingsStore.restartAdvice);
35
36
if (restartAdvice === RestartAdvice.NotNeeded) return null;
37
38
return (
39
<div className="moonbase-help-message-sticky">
40
<HelpMessage text={strings[restartAdvice]} icon={CircleWarningIcon} type="warning">
41
<Button color={Button.Colors.YELLOW} size={Button.Sizes.TINY} onClick={actions[restartAdvice]}>
42
{buttonStrings[restartAdvice]}
43
</Button>
44
</HelpMessage>
45
</div>
46
);
47
}
48