import { Button } from "@/components/Button"; import { Text } from "@/components/common/Text"; import { useDownload } from "@/providers/DownloadProvider"; import { clearLogs } from "@/utils/log"; import { useQuery } from "@tanstack/react-query"; import * as FileSystem from "expo-file-system"; import { useHaptic } from "@/hooks/useHaptic"; import { View } from "react-native"; import * as Progress from "react-native-progress"; import { toast } from "sonner-native"; import { ListGroup } from "../list/ListGroup"; import { ListItem } from "../list/ListItem"; export const StorageSettings = () => { const { deleteAllFiles, appSizeUsage } = useDownload(); 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("Error deleting files"); } }; const calculatePercentage = (value: number, total: number) => { return ((value / total) * 100).toFixed(2); }; return ( Storage {size && ( {Number(size.total - size.remaining).bytesToReadable()} of{" "} {size.total?.bytesToReadable()} used )} {size && ( <> )} {size && ( <> App {calculatePercentage(size.app, size.total)}% Phone{" "} {calculatePercentage( size.total - size.remaining - size.app, size.total )} % )} ); };