38 lines
1.0 KiB
TypeScript
38 lines
1.0 KiB
TypeScript
import AsyncStorage from "@react-native-async-storage/async-storage";
|
|
|
|
export const STORAGE_KEYS = {
|
|
authToken: "recorder.authToken",
|
|
backendUrl: "recorder.backendUrl",
|
|
fieldName: "recorder.fieldName",
|
|
};
|
|
|
|
export type RecorderSettings = {
|
|
authToken: string;
|
|
backendUrl: string;
|
|
fieldName: string;
|
|
};
|
|
|
|
export async function loadRecorderSettings(): Promise<RecorderSettings> {
|
|
const entries = await AsyncStorage.multiGet([
|
|
STORAGE_KEYS.backendUrl,
|
|
STORAGE_KEYS.authToken,
|
|
STORAGE_KEYS.fieldName,
|
|
]);
|
|
|
|
const values = Object.fromEntries(entries);
|
|
|
|
return {
|
|
authToken: values[STORAGE_KEYS.authToken] ?? "",
|
|
backendUrl: values[STORAGE_KEYS.backendUrl] ?? "",
|
|
fieldName: values[STORAGE_KEYS.fieldName] ?? "file",
|
|
};
|
|
}
|
|
|
|
export async function saveRecorderSettings(settings: RecorderSettings) {
|
|
await AsyncStorage.multiSet([
|
|
[STORAGE_KEYS.backendUrl, settings.backendUrl],
|
|
[STORAGE_KEYS.authToken, settings.authToken],
|
|
[STORAGE_KEYS.fieldName, settings.fieldName || "file"],
|
|
]);
|
|
}
|