this repo has no description
at v1.3.1 1.9 kB view raw
1import { useStateFromStores } from "@moonlight-mod/wp/discord/packages/flux"; 2import { MoonbaseSettingsStore } from "@moonlight-mod/wp/moonbase_stores"; 3import * as Components 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 { Button } = Components; 9 10const 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 17const buttonStrings: Record<RestartAdvice, string> = { 18 [RestartAdvice.NotNeeded]: "huh?", 19 [RestartAdvice.ReloadSuggested]: "Reload", 20 [RestartAdvice.ReloadNeeded]: "Reload", 21 [RestartAdvice.RestartNeeded]: "Restart" 22}; 23 24const 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 31const { CircleWarningIcon } = Components; 32 33export 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}