mirror of
https://github.com/streamyfin/streamyfin.git
synced 2026-06-03 12:38:26 +01:00
fix: refactor settings location for notifications
This commit is contained in:
@@ -22,6 +22,7 @@ import { ListItem } from "../list/ListItem";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import DisabledSetting from "@/components/settings/DisabledSetting";
|
||||
import Dropdown from "@/components/common/Dropdown";
|
||||
import { RECENTLY_ADDED_SENT_NOTIFICATIONS_ITEM_IDS_KEY } from "@/utils/recently-added-notifications";
|
||||
|
||||
export const OtherSettings: React.FC = () => {
|
||||
const router = useRouter();
|
||||
@@ -202,14 +203,6 @@ export const OtherSettings: React.FC = () => {
|
||||
}
|
||||
/>
|
||||
</ListItem>
|
||||
<ListItem title={"Recently added notifications"}>
|
||||
<Switch
|
||||
value={settings.recentlyAddedNotifications}
|
||||
onValueChange={(recentlyAddedNotifications) =>
|
||||
updateSettings({ recentlyAddedNotifications })
|
||||
}
|
||||
/>
|
||||
</ListItem>
|
||||
</ListGroup>
|
||||
</DisabledSetting>
|
||||
);
|
||||
|
||||
50
components/settings/RecentlyAddedNotifications.tsx
Normal file
50
components/settings/RecentlyAddedNotifications.tsx
Normal file
@@ -0,0 +1,50 @@
|
||||
import settings from "@/app/(auth)/(tabs)/(home)/settings";
|
||||
import { Switch, View } from "react-native";
|
||||
import { ListGroup } from "../list/ListGroup";
|
||||
import { ListItem } from "../list/ListItem";
|
||||
import { useSettings } from "@/utils/atoms/settings";
|
||||
import React, { useCallback, useEffect, useMemo } from "react";
|
||||
import { BACKGROUND_FETCH_TASK_RECENTLY_ADDED } from "@/utils/background-tasks";
|
||||
import { storage } from "@/utils/mmkv";
|
||||
import { RECENTLY_ADDED_SENT_NOTIFICATIONS_ITEM_IDS_KEY } from "@/utils/recently-added-notifications";
|
||||
import * as TaskManager from "expo-task-manager";
|
||||
import * as BackgroundFetch from "expo-background-fetch";
|
||||
|
||||
export const RecentlyAddedNotificationsSettings: React.FC = ({ ...props }) => {
|
||||
const [settings, updateSettings] = useSettings();
|
||||
|
||||
const clearRecentlyAddedNotifications = useCallback(() => {
|
||||
storage.delete(RECENTLY_ADDED_SENT_NOTIFICATIONS_ITEM_IDS_KEY);
|
||||
}, []);
|
||||
|
||||
const recentlyAddedNotificationsItemIds = useMemo(() => {
|
||||
const s = storage.getString(RECENTLY_ADDED_SENT_NOTIFICATIONS_ITEM_IDS_KEY);
|
||||
if (!s) return [] as string[];
|
||||
try {
|
||||
const t: string[] = JSON.parse(s);
|
||||
return t;
|
||||
} catch (e) {
|
||||
throw new Error("Failed to parse recently added notifications item ids");
|
||||
}
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<View className="mb-4" {...props}>
|
||||
<ListGroup title={"Recently Added Notifications"}>
|
||||
<ListItem title={"Recently added notifications"}>
|
||||
<Switch
|
||||
value={settings.recentlyAddedNotifications}
|
||||
onValueChange={(recentlyAddedNotifications) =>
|
||||
updateSettings({ recentlyAddedNotifications })
|
||||
}
|
||||
/>
|
||||
</ListItem>
|
||||
<ListItem
|
||||
textColor="red"
|
||||
onPress={clearRecentlyAddedNotifications}
|
||||
title={`Reset recently added notifications (${recentlyAddedNotificationsItemIds.length})`}
|
||||
/>
|
||||
</ListGroup>
|
||||
</View>
|
||||
);
|
||||
};
|
||||
@@ -44,20 +44,6 @@ export const StorageSettings = () => {
|
||||
return ((value / total) * 100).toFixed(2);
|
||||
};
|
||||
|
||||
const clearRecentlyAddedNotifications = useCallback(() => {
|
||||
storage.delete(RECENTLY_ADDED_SENT_NOTIFICATIONS_ITEM_IDS_KEY);
|
||||
}, []);
|
||||
|
||||
const recentlyAddedNotificationsItemIds = useMemo(() => {
|
||||
const s = storage.getString(RECENTLY_ADDED_SENT_NOTIFICATIONS_ITEM_IDS_KEY);
|
||||
if (!s) return [] as string[];
|
||||
try {
|
||||
const t: string[] = JSON.parse(s);
|
||||
return t;
|
||||
} catch (e) {
|
||||
throw new Error("Failed to parse recently added notifications item ids");
|
||||
}
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<View>
|
||||
@@ -127,13 +113,7 @@ export const StorageSettings = () => {
|
||||
title={t("home.settings.storage.delete_all_downloaded_files")}
|
||||
/>
|
||||
</ListGroup>
|
||||
<ListGroup>
|
||||
<ListItem
|
||||
textColor="red"
|
||||
onPress={clearRecentlyAddedNotifications}
|
||||
title={`Reset recently added notifications (${recentlyAddedNotificationsItemIds.length})`}
|
||||
/>
|
||||
</ListGroup>
|
||||
|
||||
</View>
|
||||
);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user