diff options
author | Shin'ya Ueoka <ueokande@i-beam.org> | 2021-04-11 22:30:41 +0900 |
---|---|---|
committer | Shin'ya Ueoka <ueokande@i-beam.org> | 2021-04-11 22:34:55 +0900 |
commit | 8a5bba1da639355a25da8c279a9f1cf0a7300a9f (patch) | |
tree | 2f82e9184e2a249cff4a607764f88b724fae1013 /src/console/components/Console.tsx | |
parent | 6767b38c8e57c9f436936dc02ad1c8c4ffd043b2 (diff) |
Replace app state with Custom Hooks
Diffstat (limited to 'src/console/components/Console.tsx')
-rw-r--r-- | src/console/components/Console.tsx | 36 |
1 files changed, 21 insertions, 15 deletions
diff --git a/src/console/components/Console.tsx b/src/console/components/Console.tsx index c8642c8..db18fa0 100644 --- a/src/console/components/Console.tsx +++ b/src/console/components/Console.tsx @@ -3,31 +3,37 @@ import FindPrompt from "./FindPrompt"; import CommandPrompt from "./CommandPrompt"; import InfoMessage from "./InfoMessage"; import ErrorMessage from "./ErrorMessage"; -import AppContext from "./AppContext"; import { useColorSchemeRefresh } from "../colorscheme/hooks"; +import { + useCommandMode, + useErrorMessage, + useFindMode, + useInfoMessage, +} from "../app/hooks"; const Console: React.FC = () => { - const { state } = React.useContext(AppContext); const refreshColorScheme = useColorSchemeRefresh(); + const { visible: visibleCommand, initialInputValue } = useCommandMode(); + const { visible: visibleFind } = useFindMode(); + const { visible: visibleInfo, message: infoMessage } = useInfoMessage(); + const { visible: visibleError, message: errorMessage } = useErrorMessage(); React.useEffect(() => { - if (state.mode !== "") { + if (visibleCommand || visibleFind || visibleInfo || visibleError) { refreshColorScheme(); } - }, [state.mode]); + }, [visibleCommand, visibleFind, visibleInfo, visibleError]); - switch (state.mode) { - case "command": - return <CommandPrompt initialInputValue={state.consoleText} />; - case "find": - return <FindPrompt />; - case "info": - return <InfoMessage>{state.messageText}</InfoMessage>; - case "error": - return <ErrorMessage>{state.messageText}</ErrorMessage>; - default: - return null; + if (visibleCommand) { + return <CommandPrompt initialInputValue={initialInputValue} />; + } else if (visibleFind) { + return <FindPrompt />; + } else if (visibleInfo) { + return <InfoMessage>{infoMessage}</InfoMessage>; + } else if (visibleError) { + return <ErrorMessage>{errorMessage}</ErrorMessage>; } + return null; }; export default Console; |