From 717bec3991a8d7d48ac2033416f834aef07efb4d Mon Sep 17 00:00:00 2001 From: Florian Duros Date: Fri, 13 Dec 2024 15:09:39 +0100 Subject: [PATCH] Rename `Panel` into `State` --- .../tabs/user/EncryptionUserSettingsTab.tsx | 44 ++++++++----------- 1 file changed, 18 insertions(+), 26 deletions(-) diff --git a/src/components/views/settings/tabs/user/EncryptionUserSettingsTab.tsx b/src/components/views/settings/tabs/user/EncryptionUserSettingsTab.tsx index c4ed28117e7..c05738267b0 100644 --- a/src/components/views/settings/tabs/user/EncryptionUserSettingsTab.tsx +++ b/src/components/views/settings/tabs/user/EncryptionUserSettingsTab.tsx @@ -20,21 +20,21 @@ import { SettingsSection } from "../../shared/SettingsSection"; import { SettingsSubheader } from "../../SettingsSubheader"; /** - * The panel to show in the encryption settings tab. + * The state in the encryption settings tab. * - "loading": We are checking if the device is verified. * - "main": The main panel with all the sections (Key storage, recovery, advanced). * - "verification_required": The panel to show when the user needs to verify their session. * - "change_recovery_key": The panel to show when the user is changing their recovery key. * - "set_recovery_key": The panel to show when the user is setting up their recovery key. */ -type Panel = "loading" | "main" | "verification_required" | "change_recovery_key" | "set_recovery_key"; +type State = "loading" | "main" | "verification_required" | "change_recovery_key" | "set_recovery_key"; export function EncryptionUserSettingsTab(): JSX.Element { - const [panel, setPanel] = useState("loading"); - const checkVerificationRequired = useVerificationRequired(setPanel); + const [state, setState] = useState("loading"); + const checkVerificationRequired = useVerificationRequired(setState); let content: JSX.Element; - switch (panel) { + switch (state) { case "loading": content = ; break; @@ -44,26 +44,18 @@ export function EncryptionUserSettingsTab(): JSX.Element { case "main": content = ( setPanel("change_recovery_key")} - onSetUpRecoveryClick={() => setPanel("set_recovery_key")} - /> - ); - break; - case "set_recovery_key": - content = ( - setPanel("main")} - onFinish={() => setPanel("main")} + onChangingRecoveryKeyClick={() => setState("change_recovery_key")} + onSetUpRecoveryClick={() => setState("set_recovery_key")} /> ); break; case "change_recovery_key": + case "set_recovery_key": content = ( setPanel("main")} - onFinish={() => setPanel("main")} + isSetupFlow={state === "set_recovery_key"} + onCancelClick={() => setState("main")} + onFinish={() => setState("main")} /> ); break; @@ -74,11 +66,11 @@ export function EncryptionUserSettingsTab(): JSX.Element { /** * Hook to check if the user needs to verify their session. - * If the user needs to verify their session, the panel will be set to "verification_required". - * If the user doesn't need to verify their session, the panel will be set to "main". - * @param setPanel + * If the user needs to verify their session, the state will be set to "verification_required". + * If the user doesn't need to verify their session, the state will be set to "main". + * @param setState */ -function useVerificationRequired(setPanel: (panel: Panel) => void): () => Promise { +function useVerificationRequired(setState: (state: State) => void): () => Promise { const matrixClient = useMatrixClientContext(); const checkVerificationRequired = useCallback(async () => { @@ -86,9 +78,9 @@ function useVerificationRequired(setPanel: (panel: Panel) => void): () => Promis if (!crypto) return; const isCrossSigningReady = await crypto.isCrossSigningReady(); - if (isCrossSigningReady) setPanel("main"); - else setPanel("verification_required"); - }, [matrixClient, setPanel]); + if (isCrossSigningReady) setState("main"); + else setState("verification_required"); + }, [matrixClient, setState]); useEffect(() => { checkVerificationRequired();