Things
This commit is contained in:
37
apk/lib/recorder-settings.ts
Normal file
37
apk/lib/recorder-settings.ts
Normal file
@@ -0,0 +1,37 @@
|
||||
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"],
|
||||
]);
|
||||
}
|
||||
Reference in New Issue
Block a user