mirror of
https://github.com/cpvalente/ontime.git
synced 2026-08-08 00:43:54 +00:00
0e6d6cd416
* refactor: allow secondary rundowns * ui: move dropdown * feat: follow loaded * ui: background edit warning ui: fix disable radio button * feat(ui): add loaded sufix in the rundown list * feat(ui): add direct link to background edit from rundown manager * fix: better fallback * fix: default to is isCurrentRundown for nav bar colour * chore: rename navigate to cuesheet --------- Co-authored-by: alex-arc <ac@omnivox.dk>
84 lines
2.6 KiB
TypeScript
84 lines
2.6 KiB
TypeScript
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query';
|
|
import { ProjectRundownsList } from 'ontime-types';
|
|
|
|
import { queryRefetchIntervalSlow } from '../../ontimeConfig';
|
|
import { PROJECT_RUNDOWNS } from '../api/constants';
|
|
import {
|
|
createRundown,
|
|
deleteRundown,
|
|
duplicateRundown,
|
|
fetchProjectRundownList,
|
|
loadRundown,
|
|
renameRundown,
|
|
} from '../api/rundown';
|
|
|
|
//TODO: make suspends so we don't have to deal with no value all over
|
|
/**
|
|
* Project rundowns
|
|
*/
|
|
export function useProjectRundowns() {
|
|
const { data, status, isError, refetch, isFetching } = useQuery<ProjectRundownsList>({
|
|
queryKey: PROJECT_RUNDOWNS,
|
|
queryFn: ({ signal }) => fetchProjectRundownList({ signal }),
|
|
placeholderData: (previousData, _previousQuery) => previousData,
|
|
refetchInterval: queryRefetchIntervalSlow,
|
|
});
|
|
return { data: data ?? { loaded: '', rundowns: [] }, status, isError, refetch, isFetching };
|
|
}
|
|
|
|
export function useMutateProjectRundowns() {
|
|
const ontimeQueryClient = useQueryClient();
|
|
|
|
const { mutateAsync: create } = useMutation({
|
|
mutationFn: createRundown,
|
|
onMutate: () => {
|
|
ontimeQueryClient.cancelQueries({ queryKey: PROJECT_RUNDOWNS });
|
|
},
|
|
onSuccess: (response) => {
|
|
ontimeQueryClient.setQueryData(PROJECT_RUNDOWNS, response.data);
|
|
},
|
|
});
|
|
|
|
const { mutateAsync: duplicate } = useMutation({
|
|
mutationFn: duplicateRundown,
|
|
onMutate: () => {
|
|
ontimeQueryClient.cancelQueries({ queryKey: PROJECT_RUNDOWNS });
|
|
},
|
|
onSuccess: (response) => {
|
|
ontimeQueryClient.setQueryData(PROJECT_RUNDOWNS, response.data);
|
|
},
|
|
});
|
|
|
|
const { mutateAsync: rename } = useMutation({
|
|
mutationFn: ([rundownId, title]: Parameters<typeof renameRundown>) => renameRundown(rundownId, title),
|
|
onMutate: () => {
|
|
ontimeQueryClient.cancelQueries({ queryKey: PROJECT_RUNDOWNS });
|
|
},
|
|
onSuccess: (response) => {
|
|
ontimeQueryClient.setQueryData(PROJECT_RUNDOWNS, response.data);
|
|
},
|
|
});
|
|
|
|
const { mutateAsync: remove } = useMutation({
|
|
mutationFn: deleteRundown,
|
|
onMutate: () => {
|
|
ontimeQueryClient.cancelQueries({ queryKey: PROJECT_RUNDOWNS });
|
|
},
|
|
onSuccess: (response) => {
|
|
ontimeQueryClient.setQueryData(PROJECT_RUNDOWNS, response.data);
|
|
},
|
|
});
|
|
|
|
const { mutateAsync: load } = useMutation({
|
|
mutationFn: loadRundown,
|
|
onMutate: () => {
|
|
ontimeQueryClient.cancelQueries({ queryKey: PROJECT_RUNDOWNS });
|
|
},
|
|
onSuccess: (response) => {
|
|
ontimeQueryClient.setQueryData(PROJECT_RUNDOWNS, response.data);
|
|
},
|
|
});
|
|
|
|
return { create, duplicate, remove, load, rename };
|
|
}
|