🗑️ Remove deprecated code (#1225)
This commit is contained in:
90
src/widgets/dashDot/api.ts
Normal file
90
src/widgets/dashDot/api.ts
Normal file
@@ -0,0 +1,90 @@
|
||||
import { useConfigContext } from '~/config/provider';
|
||||
import { RouterInputs, api } from '~/utils/api';
|
||||
import { UsenetHistoryRequestParams, UsenetInfoRequestParams, UsenetPauseRequestParams, UsenetQueueRequestParams, UsenetResumeRequestParams } from '../useNet/types';
|
||||
|
||||
const POLLING_INTERVAL = 2000;
|
||||
|
||||
export const useGetUsenetInfo = ({ appId }: UsenetInfoRequestParams) => {
|
||||
const { name: configName } = useConfigContext();
|
||||
|
||||
return api.usenet.info.useQuery(
|
||||
{
|
||||
appId,
|
||||
configName: configName!,
|
||||
},
|
||||
{
|
||||
refetchInterval: POLLING_INTERVAL,
|
||||
keepPreviousData: true,
|
||||
retry: 2,
|
||||
enabled: !!appId,
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
export const useGetUsenetDownloads = (params: UsenetQueueRequestParams) => {
|
||||
const { name: configName } = useConfigContext();
|
||||
return api.usenet.queue.useQuery(
|
||||
{
|
||||
configName: configName!,
|
||||
...params,
|
||||
},
|
||||
{
|
||||
refetchInterval: POLLING_INTERVAL,
|
||||
keepPreviousData: true,
|
||||
retry: 2,
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
export const useGetUsenetHistory = (params: UsenetHistoryRequestParams) => {
|
||||
const { name: configName } = useConfigContext();
|
||||
return api.usenet.history.useQuery(
|
||||
{
|
||||
configName: configName!,
|
||||
...params,
|
||||
},
|
||||
{
|
||||
refetchInterval: POLLING_INTERVAL,
|
||||
keepPreviousData: true,
|
||||
retry: 2,
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
export const usePauseUsenetQueueMutation = (params: UsenetPauseRequestParams) => {
|
||||
const { name: configName } = useConfigContext();
|
||||
const { mutateAsync } = api.usenet.pause.useMutation();
|
||||
const utils = api.useContext();
|
||||
return async (variables: Omit<RouterInputs['usenet']['pause'], 'configName'>) => {
|
||||
await mutateAsync(
|
||||
{
|
||||
configName: configName!,
|
||||
...variables,
|
||||
},
|
||||
{
|
||||
onSettled() {
|
||||
utils.usenet.info.invalidate({ appId: params.appId });
|
||||
},
|
||||
}
|
||||
);
|
||||
};
|
||||
};
|
||||
|
||||
export const useResumeUsenetQueueMutation = (params: UsenetResumeRequestParams) => {
|
||||
const { name: configName } = useConfigContext();
|
||||
const { mutateAsync } = api.usenet.resume.useMutation();
|
||||
const utils = api.useContext();
|
||||
return async (variables: Omit<RouterInputs['usenet']['resume'], 'configName'>) => {
|
||||
await mutateAsync(
|
||||
{
|
||||
configName: configName!,
|
||||
...variables,
|
||||
},
|
||||
{
|
||||
onSettled() {
|
||||
utils.usenet.info.invalidate({ appId: params.appId });
|
||||
},
|
||||
}
|
||||
);
|
||||
};
|
||||
};
|
||||
@@ -18,7 +18,7 @@ import { useEffect } from 'react';
|
||||
|
||||
import { AppAvatar } from '../../components/AppAvatar';
|
||||
import { useConfigContext } from '../../config/provider';
|
||||
import { useGetDownloadClientsQueue } from '../../hooks/widgets/download-speed/useGetNetworkSpeed';
|
||||
import { useGetDownloadClientsQueue } from './useGetNetworkSpeed';
|
||||
import { useColorTheme } from '../../tools/color';
|
||||
import { humanFileSize } from '../../tools/humanFileSize';
|
||||
import {
|
||||
|
||||
14
src/widgets/download-speed/useGetNetworkSpeed.tsx
Normal file
14
src/widgets/download-speed/useGetNetworkSpeed.tsx
Normal file
@@ -0,0 +1,14 @@
|
||||
import { useConfigContext } from '~/config/provider';
|
||||
import { api } from '~/utils/api';
|
||||
|
||||
export const useGetDownloadClientsQueue = () => {
|
||||
const { name: configName } = useConfigContext();
|
||||
return api.download.get.useQuery(
|
||||
{
|
||||
configName: configName!,
|
||||
},
|
||||
{
|
||||
refetchInterval: 3000,
|
||||
}
|
||||
);
|
||||
};
|
||||
@@ -15,7 +15,7 @@ import { useTranslation } from 'next-i18next';
|
||||
import { AppAvatar } from '../../components/AppAvatar';
|
||||
import { useEditModeStore } from '../../components/Dashboard/Views/useEditModeStore';
|
||||
import { useConfigContext } from '../../config/provider';
|
||||
import { useGetMediaServers } from '../../hooks/widgets/media-servers/useGetMediaServers';
|
||||
import { useGetMediaServers } from './useGetMediaServers';
|
||||
import { defineWidget } from '../helper';
|
||||
import { IWidget } from '../widgets';
|
||||
import { TableRow } from './TableRow';
|
||||
|
||||
20
src/widgets/media-server/useGetMediaServers.tsx
Normal file
20
src/widgets/media-server/useGetMediaServers.tsx
Normal file
@@ -0,0 +1,20 @@
|
||||
import { useConfigContext } from '~/config/provider';
|
||||
import { api } from '~/utils/api';
|
||||
|
||||
interface GetMediaServersParams {
|
||||
enabled: boolean;
|
||||
}
|
||||
|
||||
export const useGetMediaServers = ({ enabled }: GetMediaServersParams) => {
|
||||
const { name: configName } = useConfigContext();
|
||||
|
||||
return api.mediaServer.all.useQuery(
|
||||
{
|
||||
configName: configName!,
|
||||
},
|
||||
{
|
||||
enabled,
|
||||
refetchInterval: 10 * 1000,
|
||||
}
|
||||
);
|
||||
};
|
||||
@@ -19,7 +19,7 @@ import relativeTime from 'dayjs/plugin/relativeTime';
|
||||
import { useTranslation } from 'next-i18next';
|
||||
|
||||
import { MIN_WIDTH_MOBILE } from '../../constants/constants';
|
||||
import { useGetDownloadClientsQueue } from '../../hooks/widgets/download-speed/useGetNetworkSpeed';
|
||||
import { useGetDownloadClientsQueue } from '../download-speed/useGetNetworkSpeed';
|
||||
import { NormalizedDownloadQueueResponse } from '../../types/api/downloads/queue/NormalizedDownloadQueueResponse';
|
||||
import { AppIntegrationType } from '../../types/app';
|
||||
import { defineWidget } from '../helper';
|
||||
|
||||
@@ -12,7 +12,7 @@ import {
|
||||
useGetUsenetInfo,
|
||||
usePauseUsenetQueueMutation,
|
||||
useResumeUsenetQueueMutation,
|
||||
} from '../../hooks/widgets/dashDot/api';
|
||||
} from '../dashDot/api';
|
||||
import { humanFileSize } from '../../tools/humanFileSize';
|
||||
import { AppIntegrationType } from '../../types/app';
|
||||
import { defineWidget } from '../helper';
|
||||
|
||||
@@ -18,7 +18,7 @@ import duration from 'dayjs/plugin/duration';
|
||||
import { useTranslation } from 'next-i18next';
|
||||
import { FunctionComponent, useState } from 'react';
|
||||
|
||||
import { useGetUsenetHistory } from '../../hooks/widgets/dashDot/api';
|
||||
import { useGetUsenetHistory } from '../dashDot/api';
|
||||
import { parseDuration } from '../../tools/client/parseDuration';
|
||||
import { humanFileSize } from '../../tools/humanFileSize';
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@ import duration from 'dayjs/plugin/duration';
|
||||
import { useTranslation } from 'next-i18next';
|
||||
import { FunctionComponent, useState } from 'react';
|
||||
|
||||
import { useGetUsenetDownloads } from '../../hooks/widgets/dashDot/api';
|
||||
import { useGetUsenetDownloads } from '../dashDot/api';
|
||||
import { humanFileSize } from '../../tools/humanFileSize';
|
||||
|
||||
dayjs.extend(duration);
|
||||
|
||||
@@ -18,3 +18,45 @@ export interface UsenetHistoryItem {
|
||||
id: string;
|
||||
time: number;
|
||||
}
|
||||
|
||||
export interface UsenetHistoryRequestParams {
|
||||
appId: string;
|
||||
offset: number;
|
||||
limit: number;
|
||||
}
|
||||
|
||||
export interface UsenetHistoryResponse {
|
||||
items: UsenetHistoryItem[];
|
||||
total: number;
|
||||
}
|
||||
|
||||
export interface UsenetInfoRequestParams {
|
||||
appId: string;
|
||||
}
|
||||
|
||||
export interface UsenetInfoResponse {
|
||||
paused: boolean;
|
||||
sizeLeft: number;
|
||||
speed: number;
|
||||
eta: number;
|
||||
}
|
||||
|
||||
export interface UsenetPauseRequestParams {
|
||||
appId: string;
|
||||
}
|
||||
|
||||
export interface UsenetQueueRequestParams {
|
||||
appId: string;
|
||||
offset: number;
|
||||
limit: number;
|
||||
}
|
||||
|
||||
export interface UsenetQueueResponse {
|
||||
items: UsenetQueueItem[];
|
||||
total: number;
|
||||
}
|
||||
|
||||
export interface UsenetResumeRequestParams {
|
||||
appId: string;
|
||||
nzbId?: string;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user