mirror of
https://github.com/movie-web/native-app.git
synced 2025-09-13 18:13:25 +00:00
feat: download history
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import AsyncStorage from "@react-native-async-storage/async-storage";
|
||||
|
||||
import type { DownloadItem } from "~/hooks/DownloadManagerContext";
|
||||
import type { ThemeStoreOption } from "~/stores/theme";
|
||||
|
||||
interface ThemeSettings {
|
||||
@@ -31,3 +32,26 @@ export const saveTheme = async (newTheme: ThemeStoreOption) => {
|
||||
settings.themes.theme = newTheme;
|
||||
await saveSettings(settings);
|
||||
};
|
||||
|
||||
interface DownloadHistory {
|
||||
downloads: DownloadItem[];
|
||||
}
|
||||
|
||||
const downloadHistoryKey = "downloadHistory";
|
||||
|
||||
export const saveDownloadHistory = async (downloads: DownloadItem[]) => {
|
||||
const json = await AsyncStorage.getItem(downloadHistoryKey);
|
||||
const settings = json
|
||||
? (JSON.parse(json) as DownloadHistory)
|
||||
: { downloads: [] };
|
||||
settings.downloads = downloads;
|
||||
await AsyncStorage.setItem(downloadHistoryKey, JSON.stringify(settings));
|
||||
};
|
||||
|
||||
export const loadDownloadHistory = async (): Promise<DownloadItem[]> => {
|
||||
const json = await AsyncStorage.getItem(downloadHistoryKey);
|
||||
const settings = json
|
||||
? (JSON.parse(json) as DownloadHistory)
|
||||
: { downloads: [] };
|
||||
return settings.downloads;
|
||||
};
|
||||
|
Reference in New Issue
Block a user