diff --git a/web/src/components/file-statistics.tsx b/web/src/components/file-statistics.tsx index fe96750..9b828fa 100644 --- a/web/src/components/file-statistics.tsx +++ b/web/src/components/file-statistics.tsx @@ -10,12 +10,16 @@ import { Image, Music, Network, - PauseCircle, Upload, + PauseCircle, + Upload, Video, } from "lucide-react"; -import { request } from "@/lib/api"; +import { request, telegramApi, type TelegramApiArg } from "@/lib/api"; import prettyBytes from "pretty-bytes"; -import { formatDistanceToNow } from "date-fns"; // Define a fetcher function to handle the API request +import { formatDistanceToNow } from "date-fns"; +import { Button } from "@/components/ui/button"; +import useSWRMutation from "swr/mutation"; +import type { TelegramApiResult } from "@/lib/types"; // Define a fetcher function to handle the API request // Interface defining the structure of the data returned from the API interface StatisticsData { @@ -42,11 +46,22 @@ interface FileStatisticsProps { const FileStatistics: React.FC = ({ telegramId }) => { // Use SWR for data fetching and caching - const { data, error } = useSWR( + const { data, error, mutate } = useSWR( `/telegram/${telegramId}/download-statistics`, request, ); + const { trigger: triggerReset, isMutating: isResetMutating } = useSWRMutation< + TelegramApiResult, + Error, + string, + TelegramApiArg + >("/telegram/api", telegramApi, { + onSuccess: () => { + void mutate(); + }, + }); + // Render an error message if the API call fails if (error) { return ( @@ -193,26 +208,42 @@ const FileStatistics: React.FC = ({ telegramId }) => { Network Statistics
-
+
{prettyBytes(data.networkStatistics.sentBytes)}
-
+
{prettyBytes(data.networkStatistics.receivedBytes)}
-

- Since: {formatDistanceToNow( - new Date(data.networkStatistics.sinceDate * 1000), - { - addSuffix: true, - }, - )} -

+
+ +

+ Since:{" "} + {formatDistanceToNow( + new Date(data.networkStatistics.sinceDate * 1000), + { + addSuffix: true, + }, + )} +

+