this repo has no description
1import { useStateFromStores } from "@moonlight-mod/wp/discord/packages/flux";
2import { MoonbaseSettingsStore } from "@moonlight-mod/wp/moonbase_stores";
3import { Button, CircleWarningIcon } from "@moonlight-mod/wp/discord/components/common/index";
4import React from "@moonlight-mod/wp/react";
5import { RestartAdvice } from "../../types";
6import HelpMessage from "./HelpMessage";
7
8const 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
15const buttonStrings: Record<RestartAdvice, string> = {
16 [RestartAdvice.NotNeeded]: "huh?",
17 [RestartAdvice.ReloadSuggested]: "Reload",
18 [RestartAdvice.ReloadNeeded]: "Reload",
19 [RestartAdvice.RestartNeeded]: "Restart"
20};
21
22const 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
29export 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}