mirror of
https://github.com/jellyfin/jellyfin-web
synced 2025-03-30 19:56:21 +00:00
Refactor query keys to enum
This commit is contained in:
parent
dd539b89ca
commit
a7621d242d
7 changed files with 18 additions and 15 deletions
4
src/apps/dashboard/features/tasks/api/queryKey.ts
Normal file
4
src/apps/dashboard/features/tasks/api/queryKey.ts
Normal file
|
@ -0,0 +1,4 @@
|
|||
export enum QueryKey {
|
||||
Task = 'Task',
|
||||
Tasks = 'Tasks'
|
||||
};
|
|
@ -3,7 +3,7 @@ import { getScheduledTasksApi } from '@jellyfin/sdk/lib/utils/api/scheduled-task
|
|||
import { useMutation } from '@tanstack/react-query';
|
||||
import { useApi } from 'hooks/useApi';
|
||||
import { queryClient } from 'utils/query/queryClient';
|
||||
import { QUERY_KEY } from './useTasks';
|
||||
import { QueryKey } from './queryKey';
|
||||
|
||||
export const useStartTask = () => {
|
||||
const { api } = useApi();
|
||||
|
@ -15,7 +15,7 @@ export const useStartTask = () => {
|
|||
),
|
||||
onSuccess: () => {
|
||||
void queryClient.invalidateQueries({
|
||||
queryKey: [ QUERY_KEY ]
|
||||
queryKey: [ QueryKey.Tasks ]
|
||||
});
|
||||
}
|
||||
});
|
||||
|
|
|
@ -3,7 +3,7 @@ import { getScheduledTasksApi } from '@jellyfin/sdk/lib/utils/api/scheduled-task
|
|||
import { useMutation } from '@tanstack/react-query';
|
||||
import { useApi } from 'hooks/useApi';
|
||||
import { queryClient } from 'utils/query/queryClient';
|
||||
import { QUERY_KEY } from './useTasks';
|
||||
import { QueryKey } from './queryKey';
|
||||
|
||||
export const useStopTask = () => {
|
||||
const { api } = useApi();
|
||||
|
@ -15,7 +15,7 @@ export const useStopTask = () => {
|
|||
),
|
||||
onSuccess: () => {
|
||||
void queryClient.invalidateQueries({
|
||||
queryKey: [ QUERY_KEY ]
|
||||
queryKey: [ QueryKey.Tasks ]
|
||||
});
|
||||
}
|
||||
});
|
||||
|
|
|
@ -5,8 +5,7 @@ import { getScheduledTasksApi } from '@jellyfin/sdk/lib/utils/api/scheduled-task
|
|||
import { useQuery } from '@tanstack/react-query';
|
||||
|
||||
import { useApi } from 'hooks/useApi';
|
||||
|
||||
export const QUERY_KEY = 'Task';
|
||||
import { QueryKey } from './queryKey';
|
||||
|
||||
const fetchTask = async (
|
||||
api: Api,
|
||||
|
@ -22,7 +21,7 @@ export const useTask = (params: ScheduledTasksApiGetTaskRequest) => {
|
|||
const { api } = useApi();
|
||||
|
||||
return useQuery({
|
||||
queryKey: [ QUERY_KEY, params.taskId ],
|
||||
queryKey: [ QueryKey.Task, params.taskId ],
|
||||
queryFn: ({ signal }) =>
|
||||
fetchTask(api!, params, { signal }),
|
||||
enabled: !!api
|
||||
|
|
|
@ -5,8 +5,7 @@ import { getScheduledTasksApi } from '@jellyfin/sdk/lib/utils/api/scheduled-task
|
|||
import { useQuery } from '@tanstack/react-query';
|
||||
|
||||
import { useApi } from 'hooks/useApi';
|
||||
|
||||
export const QUERY_KEY = 'Tasks';
|
||||
import { QueryKey } from './queryKey';
|
||||
|
||||
const fetchTasks = async (
|
||||
api: Api,
|
||||
|
@ -22,7 +21,7 @@ export const useTasks = (params?: ScheduledTasksApiGetTasksRequest) => {
|
|||
const { api } = useApi();
|
||||
|
||||
return useQuery({
|
||||
queryKey: [ QUERY_KEY ],
|
||||
queryKey: [ QueryKey.Tasks ],
|
||||
queryFn: ({ signal }) =>
|
||||
fetchTasks(api!, params, { signal }),
|
||||
enabled: !!api
|
||||
|
|
|
@ -3,7 +3,7 @@ import { getScheduledTasksApi } from '@jellyfin/sdk/lib/utils/api/scheduled-task
|
|||
import { useMutation } from '@tanstack/react-query';
|
||||
import { useApi } from 'hooks/useApi';
|
||||
import { queryClient } from 'utils/query/queryClient';
|
||||
import { QUERY_KEY } from './useTask';
|
||||
import { QueryKey } from './queryKey';
|
||||
|
||||
export const useUpdateTask = () => {
|
||||
const { api } = useApi();
|
||||
|
@ -15,7 +15,7 @@ export const useUpdateTask = () => {
|
|||
),
|
||||
onSuccess: (_data, params) => {
|
||||
void queryClient.invalidateQueries({
|
||||
queryKey: [ QUERY_KEY, params.taskId ]
|
||||
queryKey: [ QueryKey.Task, params.taskId ]
|
||||
});
|
||||
}
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue