import { Text } from "@/components/common/Text"; import { Colors } from "@/constants/Colors"; import { useHaptic } from "@/hooks/useHaptic"; import { useDownload } from "@/providers/DownloadProvider"; import { useQuery } from "@tanstack/react-query"; import * as FileSystem from "expo-file-system"; import { useTranslation } from "react-i18next"; import { View } from "react-native"; import { toast } from "sonner-native"; import { ListGroup } from "../list/ListGroup"; import { ListItem } from "../list/ListItem"; export const StorageSettings = () => { const { deleteAllFiles, appSizeUsage } = useDownload(); const { t } = useTranslation(); const successHapticFeedback = useHaptic("success"); const errorHapticFeedback = useHaptic("error"); const { data: size, isLoading: appSizeLoading } = useQuery({ queryKey: ["appSize", appSizeUsage], queryFn: async () => { const app = await appSizeUsage; const remaining = await FileSystem.getFreeDiskStorageAsync(); const total = await FileSystem.getTotalDiskCapacityAsync(); return { app, remaining, total, used: (total - remaining) / total }; }, }); const onDeleteClicked = async () => { try { await deleteAllFiles(); successHapticFeedback(); } catch (e) { errorHapticFeedback(); toast.error(t("home.settings.toasts.error_deleting_files")); } }; const calculatePercentage = (value: number, total: number) => { return ((value / total) * 100).toFixed(2); }; return ( {t("home.settings.storage.storage_title")} {size && ( {t("home.settings.storage.size_used", { used: Number(size.total - size.remaining).bytesToReadable(), total: size.total?.bytesToReadable(), })} )} {size && ( <> )} {size && ( <> {t("home.settings.storage.app_usage", { usedSpace: calculatePercentage(size.app, size.total), })} {t("home.settings.storage.device_usage", { availableSpace: calculatePercentage( size.total - size.remaining - size.app, size.total, ), })} )} ); };