38 lines
1007 B
TypeScript
38 lines
1007 B
TypeScript
import { useState, useEffect } from "react";
|
|
import * as SecureStore from "expo-secure-store";
|
|
|
|
export interface Settings {
|
|
homeView: "dashboard" | "capture";
|
|
inputMode: "form" | "voice";
|
|
onboardingDone: boolean;
|
|
}
|
|
|
|
const DEFAULTS: Settings = {
|
|
homeView: "dashboard",
|
|
inputMode: "form",
|
|
onboardingDone: false,
|
|
};
|
|
|
|
export function useSettings() {
|
|
const [settings, setSettings] = useState<Settings>(DEFAULTS);
|
|
const [ready, setReady] = useState(false);
|
|
|
|
useEffect(() => {
|
|
(async () => {
|
|
const [hv, im, od] = await Promise.all([
|
|
SecureStore.getItemAsync("pref_home_view"),
|
|
SecureStore.getItemAsync("pref_input_mode"),
|
|
SecureStore.getItemAsync("onboarding_done"),
|
|
]);
|
|
setSettings({
|
|
homeView: (hv as Settings["homeView"]) ?? DEFAULTS.homeView,
|
|
inputMode: (im as Settings["inputMode"]) ?? DEFAULTS.inputMode,
|
|
onboardingDone: od === "true",
|
|
});
|
|
setReady(true);
|
|
})();
|
|
}, []);
|
|
|
|
return { settings, ready };
|
|
}
|