mirror of
https://github.com/jjbrunton/Sauci.git
synced 2026-10-31 10:19:43 +00:00
52 lines
1.5 KiB
TypeScript
52 lines
1.5 KiB
TypeScript
import * as SecureStore from "expo-secure-store";
|
|
import { Platform } from "react-native";
|
|
|
|
const STORAGE_KEY = "matches_tutorial_seen";
|
|
|
|
async function getStorage(): Promise<boolean> {
|
|
try {
|
|
let data: string | null = null;
|
|
|
|
if (Platform.OS === "web") {
|
|
if (typeof window !== "undefined" && typeof window.localStorage !== "undefined") {
|
|
data = window.localStorage.getItem(STORAGE_KEY);
|
|
}
|
|
} else {
|
|
data = await SecureStore.getItemAsync(STORAGE_KEY);
|
|
}
|
|
|
|
return data === "true";
|
|
} catch (error) {
|
|
console.error("Error reading matches tutorial state:", error);
|
|
}
|
|
return false;
|
|
}
|
|
|
|
async function setStorage(seen: boolean): Promise<void> {
|
|
try {
|
|
const data = seen ? "true" : "false";
|
|
|
|
if (Platform.OS === "web") {
|
|
if (typeof window !== "undefined" && typeof window.localStorage !== "undefined") {
|
|
window.localStorage.setItem(STORAGE_KEY, data);
|
|
}
|
|
} else {
|
|
await SecureStore.setItemAsync(STORAGE_KEY, data);
|
|
}
|
|
} catch (error) {
|
|
console.error("Error saving matches tutorial state:", error);
|
|
}
|
|
}
|
|
|
|
export async function hasSeenMatchesTutorial(): Promise<boolean> {
|
|
return getStorage();
|
|
}
|
|
|
|
export async function markMatchesTutorialSeen(): Promise<void> {
|
|
await setStorage(true);
|
|
}
|
|
|
|
export async function resetMatchesTutorial(): Promise<void> {
|
|
await setStorage(false);
|
|
}
|