mirror of
https://github.com/cpvalente/ontime.git
synced 2026-08-17 05:13:32 +00:00
feat: create group from entry selection
This commit is contained in:
@@ -90,15 +90,15 @@ export async function requestApplyDelay(delayId: EntryId): Promise<AxiosResponse
|
||||
/**
|
||||
* HTTP request for dissolving of a block
|
||||
*/
|
||||
export async function requestDissolveBlock(blockId: EntryId): Promise<AxiosResponse<MessageResponse>> {
|
||||
export async function requestDissolveBlock(blockId: EntryId): Promise<AxiosResponse<Rundown>> {
|
||||
return axios.post(`${rundownPath}/dissolve/${blockId}`);
|
||||
}
|
||||
|
||||
/**
|
||||
* HTTP request for grouping a list of entries into a block
|
||||
*/
|
||||
export async function requestGroupEntries(entryIds: EntryId[]): Promise<AxiosResponse<MessageResponse>> {
|
||||
return axios.post(`${rundownPath}/group`, { data: { ids: entryIds } });
|
||||
export async function requestGroupEntries(entryIds: EntryId[]): Promise<AxiosResponse<Rundown>> {
|
||||
return axios.post(`${rundownPath}/group`, { ids: entryIds });
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -27,6 +27,7 @@ import {
|
||||
requestDeleteAll,
|
||||
requestDissolveBlock,
|
||||
requestEventSwap,
|
||||
requestGroupEntries,
|
||||
SwapEntry,
|
||||
} from '../api/rundown';
|
||||
import { logAxiosError } from '../api/utils';
|
||||
@@ -521,6 +522,19 @@ export const useEntryActions = () => {
|
||||
*/
|
||||
const _dissolveBlockMutation = useMutation({
|
||||
mutationFn: requestDissolveBlock,
|
||||
onSuccess: (response) => {
|
||||
if (!response.data) return;
|
||||
|
||||
const { id, title, order, flatOrder, entries, revision } = response.data;
|
||||
queryClient.setQueryData<Rundown>(RUNDOWN, {
|
||||
id,
|
||||
title,
|
||||
order,
|
||||
flatOrder,
|
||||
entries,
|
||||
revision,
|
||||
});
|
||||
},
|
||||
onSettled: () => queryClient.invalidateQueries({ queryKey: RUNDOWN }),
|
||||
});
|
||||
|
||||
@@ -537,6 +551,43 @@ export const useEntryActions = () => {
|
||||
},
|
||||
[_dissolveBlockMutation],
|
||||
);
|
||||
|
||||
/**
|
||||
* Calls mutation to create a block with a selection
|
||||
* @private
|
||||
*/
|
||||
const _groupEntriesMutation = useMutation({
|
||||
mutationFn: requestGroupEntries,
|
||||
onSuccess: (response) => {
|
||||
if (!response.data) return;
|
||||
|
||||
const { id, title, order, flatOrder, entries, revision } = response.data;
|
||||
queryClient.setQueryData<Rundown>(RUNDOWN, {
|
||||
id,
|
||||
title,
|
||||
order,
|
||||
flatOrder,
|
||||
entries,
|
||||
revision,
|
||||
});
|
||||
},
|
||||
onSettled: () => queryClient.invalidateQueries({ queryKey: RUNDOWN }),
|
||||
});
|
||||
|
||||
/**
|
||||
* Create a block with a selection
|
||||
*/
|
||||
const groupEntries = useCallback(
|
||||
async (entryIds: EntryId[]) => {
|
||||
try {
|
||||
await _groupEntriesMutation.mutateAsync(entryIds);
|
||||
} catch (error) {
|
||||
logAxiosError('Error grouping entries', error);
|
||||
}
|
||||
},
|
||||
[_groupEntriesMutation],
|
||||
);
|
||||
|
||||
/**
|
||||
* Calls mutation to reorder an entry
|
||||
* @private
|
||||
@@ -575,17 +626,17 @@ export const useEntryActions = () => {
|
||||
|
||||
// Mutation finished, we update the rundown with the response
|
||||
onSuccess: (response) => {
|
||||
if (response.data) {
|
||||
const { id, title, order, flatOrder, entries, revision } = response.data;
|
||||
queryClient.setQueryData<Rundown>(RUNDOWN, {
|
||||
id,
|
||||
title,
|
||||
order,
|
||||
flatOrder,
|
||||
entries,
|
||||
revision,
|
||||
});
|
||||
}
|
||||
if (!response.data) return;
|
||||
|
||||
const { id, title, order, flatOrder, entries, revision } = response.data;
|
||||
queryClient.setQueryData<Rundown>(RUNDOWN, {
|
||||
id,
|
||||
title,
|
||||
order,
|
||||
flatOrder,
|
||||
entries,
|
||||
revision,
|
||||
});
|
||||
},
|
||||
|
||||
// Mutation finished, failed or successful
|
||||
@@ -688,6 +739,7 @@ export const useEntryActions = () => {
|
||||
deleteAllEntries,
|
||||
dissolveBlock,
|
||||
getEntryById,
|
||||
groupEntries,
|
||||
reorderEntry,
|
||||
swapEvents,
|
||||
updateEntry,
|
||||
|
||||
Reference in New Issue
Block a user