mirror of
https://github.com/ajnart/homarr.git
synced 2025-11-11 07:55:52 +01:00
♻️ Refactor torrent network traffic widget #616
This commit is contained in:
11
src/hooks/widgets/download-speed/useGetNetworkSpeed.tsx
Normal file
11
src/hooks/widgets/download-speed/useGetNetworkSpeed.tsx
Normal file
@@ -0,0 +1,11 @@
|
||||
import { useQuery } from '@tanstack/react-query';
|
||||
import { NormalizedDownloadQueueResponse } from '../../../types/api/downloads/queue/NormalizedDownloadQueueResponse';
|
||||
|
||||
export const useGetDownloadClientsQueue = () => useQuery({
|
||||
queryKey: ['network-speed'],
|
||||
queryFn: async (): Promise<NormalizedDownloadQueueResponse> => {
|
||||
const response = await fetch('/api/modules/downloads');
|
||||
return response.json();
|
||||
},
|
||||
refetchInterval: 3000,
|
||||
});
|
||||
@@ -1,27 +0,0 @@
|
||||
import { Query, useQuery } from '@tanstack/react-query';
|
||||
import axios from 'axios';
|
||||
import { NormalizedTorrentListResponse } from '../../../types/api/NormalizedTorrentListResponse';
|
||||
|
||||
interface TorrentsDataRequestParams {
|
||||
appId: string;
|
||||
refreshInterval: number;
|
||||
}
|
||||
|
||||
export const useGetTorrentData = (params: TorrentsDataRequestParams) =>
|
||||
useQuery({
|
||||
queryKey: ['torrentsData', params.appId],
|
||||
queryFn: fetchData,
|
||||
refetchOnWindowFocus: true,
|
||||
refetchInterval(_: any, query: Query) {
|
||||
if (query.state.fetchFailureCount < 3) {
|
||||
return params.refreshInterval;
|
||||
}
|
||||
return false;
|
||||
},
|
||||
enabled: !!params.appId,
|
||||
});
|
||||
|
||||
const fetchData = async (): Promise<NormalizedTorrentListResponse> => {
|
||||
const response = await axios.post('/api/modules/torrents');
|
||||
return response.data as NormalizedTorrentListResponse;
|
||||
};
|
||||
Reference in New Issue
Block a user