| 1 | import { useAtomValue } from "@effect/atom-react"; |
| 2 | import { AsyncResult } from "effect/reactivity"; |
| 3 | |
| 4 | import { mobilePreferencesAtom } from "../../state/preferences"; |
| 5 | import { resolveLegacyPlanModeEnabled } from "../../state/legacy-plan-mode"; |
| 6 | |
| 7 | /** |
| 8 | * Mobile preferences are device-local, matching the desktop client setting. |
| 9 | * Keep the legacy composer mode hidden until the preference has loaded and is |
| 10 | * explicitly enabled. |
| 11 | */ |
| 12 | export function useLegacyPlanModeState(): { readonly enabled: boolean; readonly loaded: boolean } { |
| 13 | const preferences = useAtomValue(mobilePreferencesAtom); |
| 14 | const loaded = AsyncResult.isSuccess(preferences); |
| 15 | return { |
| 16 | enabled: resolveLegacyPlanModeEnabled({ |
| 17 | loaded, |
| 18 | preference: loaded ? preferences.value.planModeEnabled : undefined, |
| 19 | }), |
| 20 | loaded, |
| 21 | }; |
| 22 | } |