mirror of
https://github.com/cpvalente/ontime.git
synced 2026-08-31 03:49:11 +00:00
refactor: extract operator data loading
This commit is contained in:
committed by
Carlos Valente
parent
62c52bca07
commit
3662cd58f5
@@ -6,13 +6,10 @@ import ViewParamsEditor from '../../common/components/view-params-editor/ViewPar
|
|||||||
import useFollowComponent from '../../common/hooks/useFollowComponent';
|
import useFollowComponent from '../../common/hooks/useFollowComponent';
|
||||||
import { useSelectedEventId } from '../../common/hooks/useSocket';
|
import { useSelectedEventId } from '../../common/hooks/useSocket';
|
||||||
import { useWindowTitle } from '../../common/hooks/useWindowTitle';
|
import { useWindowTitle } from '../../common/hooks/useWindowTitle';
|
||||||
import useCustomFields from '../../common/hooks-query/useCustomFields';
|
|
||||||
import useProjectData from '../../common/hooks-query/useProjectData';
|
|
||||||
import { useRundownWithMetadata } from '../../common/hooks-query/useRundown';
|
|
||||||
import useSettings from '../../common/hooks-query/useSettings';
|
|
||||||
import { cx } from '../../common/utils/styleUtils';
|
import { cx } from '../../common/utils/styleUtils';
|
||||||
import { throttle } from '../../common/utils/throttle';
|
import { throttle } from '../../common/utils/throttle';
|
||||||
import { getDefaultFormat } from '../../common/utils/time';
|
import { getDefaultFormat } from '../../common/utils/time';
|
||||||
|
import Loader from '../../views/common/loader/Loader';
|
||||||
|
|
||||||
import EditModal from './edit-modal/EditModal';
|
import EditModal from './edit-modal/EditModal';
|
||||||
import FollowButton from './follow-button/FollowButton';
|
import FollowButton from './follow-button/FollowButton';
|
||||||
@@ -22,21 +19,31 @@ import StatusBar from './status-bar/StatusBar';
|
|||||||
import { getOperatorOptions, useOperatorOptions } from './operator.options';
|
import { getOperatorOptions, useOperatorOptions } from './operator.options';
|
||||||
import type { EditEvent } from './operator.types';
|
import type { EditEvent } from './operator.types';
|
||||||
import { getEventData } from './operator.utils';
|
import { getEventData } from './operator.utils';
|
||||||
|
import { OperatorData, useOperatorData } from './useOperatorData';
|
||||||
|
|
||||||
import style from './Operator.module.scss';
|
import style from './Operator.module.scss';
|
||||||
|
|
||||||
const selectedOffset = 50;
|
const selectedOffset = 50;
|
||||||
|
|
||||||
export default function Operator() {
|
export default function OperatorLoader() {
|
||||||
const { data, rundownMetadata, status } = useRundownWithMetadata();
|
const { data, status } = useOperatorData();
|
||||||
const { data: customFields, status: customFieldStatus } = useCustomFields();
|
|
||||||
const { data: projectData, status: projectDataStatus } = useProjectData();
|
|
||||||
|
|
||||||
const timeoutId = useRef<NodeJS.Timeout | null>(null);
|
useWindowTitle('Operator');
|
||||||
|
|
||||||
|
if (status === 'pending') {
|
||||||
|
return <Loader />;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (status === 'error') {
|
||||||
|
return <EmptyPage text='There was an error fetching data, please refresh the page.' />;
|
||||||
|
}
|
||||||
|
|
||||||
|
return <Operator {...data} />;
|
||||||
|
}
|
||||||
|
|
||||||
|
function Operator({ rundown, rundownMetadata, customFields, settings }: OperatorData) {
|
||||||
const { selectedEventId } = useSelectedEventId();
|
const { selectedEventId } = useSelectedEventId();
|
||||||
const { subscribe, mainSource, secondarySource, shouldEdit, hidePast, showStart } = useOperatorOptions();
|
const { subscribe, mainSource, secondarySource, shouldEdit, hidePast, showStart } = useOperatorOptions();
|
||||||
const { data: settings } = useSettings();
|
|
||||||
|
|
||||||
const [showEditPrompt, setShowEditPrompt] = useState(false);
|
const [showEditPrompt, setShowEditPrompt] = useState(false);
|
||||||
const [editEvent, setEditEvent] = useState<EditEvent | null>(null);
|
const [editEvent, setEditEvent] = useState<EditEvent | null>(null);
|
||||||
@@ -52,7 +59,7 @@ export default function Operator() {
|
|||||||
followTrigger: selectedEventId,
|
followTrigger: selectedEventId,
|
||||||
});
|
});
|
||||||
|
|
||||||
useWindowTitle('Operator');
|
const timeoutId = useRef<NodeJS.Timeout | null>(null);
|
||||||
|
|
||||||
// reset scroll if nothing is selected
|
// reset scroll if nothing is selected
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@@ -101,17 +108,10 @@ export default function Operator() {
|
|||||||
setEditEvent({ ...event });
|
setEditEvent({ ...event });
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
const missingData = !data || !customFields || !projectData;
|
|
||||||
const isLoading = status === 'pending' || customFieldStatus === 'pending' || projectDataStatus === 'pending';
|
|
||||||
|
|
||||||
// gather option data
|
// gather option data
|
||||||
const defaultFormat = getDefaultFormat(settings?.timeFormat);
|
const defaultFormat = getDefaultFormat(settings?.timeFormat);
|
||||||
const operatorOptions = useMemo(() => getOperatorOptions(customFields, defaultFormat), [customFields, defaultFormat]);
|
const operatorOptions = useMemo(() => getOperatorOptions(customFields, defaultFormat), [customFields, defaultFormat]);
|
||||||
|
|
||||||
if (missingData || isLoading) {
|
|
||||||
return <EmptyPage text='Loading...' />;
|
|
||||||
}
|
|
||||||
|
|
||||||
const canEdit = shouldEdit && subscribe.length;
|
const canEdit = shouldEdit && subscribe.length;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -126,8 +126,8 @@ export default function Operator() {
|
|||||||
)}
|
)}
|
||||||
|
|
||||||
<div className={style.operatorEvents} onWheel={handleScroll} onTouchMove={handleScroll} ref={scrollRef}>
|
<div className={style.operatorEvents} onWheel={handleScroll} onTouchMove={handleScroll} ref={scrollRef}>
|
||||||
{data.order.map((entryId) => {
|
{rundown.order.map((entryId) => {
|
||||||
const entry = data.entries[entryId];
|
const entry = rundown.entries[entryId];
|
||||||
if (isOntimeEvent(entry)) {
|
if (isOntimeEvent(entry)) {
|
||||||
const { isPast, isLinkedToLoaded, isLoaded, totalGap } = rundownMetadata[entryId];
|
const { isPast, isLinkedToLoaded, isLoaded, totalGap } = rundownMetadata[entryId];
|
||||||
// hide past events (if setting) and skipped events
|
// hide past events (if setting) and skipped events
|
||||||
@@ -172,7 +172,7 @@ export default function Operator() {
|
|||||||
<Fragment key={entry.id}>
|
<Fragment key={entry.id}>
|
||||||
<OperatorGroup key={entry.id} title={entry.title} />
|
<OperatorGroup key={entry.id} title={entry.title} />
|
||||||
{entry.entries.map((nestedEntryId) => {
|
{entry.entries.map((nestedEntryId) => {
|
||||||
const nestedEntry = data.entries[nestedEntryId];
|
const nestedEntry = rundown.entries[nestedEntryId];
|
||||||
if (!isOntimeEvent(nestedEntry)) {
|
if (!isOntimeEvent(nestedEntry)) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,30 @@
|
|||||||
|
import { CustomFields, Rundown, Settings } from 'ontime-types';
|
||||||
|
|
||||||
|
import useCustomFields from '../../common/hooks-query/useCustomFields';
|
||||||
|
import { useRundownWithMetadata } from '../../common/hooks-query/useRundown';
|
||||||
|
import useSettings from '../../common/hooks-query/useSettings';
|
||||||
|
import { RundownMetadataObject } from '../../common/utils/rundownMetadata';
|
||||||
|
import { aggregateQueryStatus, ViewData } from '../../views/utils/viewLoader.utils';
|
||||||
|
|
||||||
|
export interface OperatorData {
|
||||||
|
rundown: Rundown;
|
||||||
|
rundownMetadata: RundownMetadataObject;
|
||||||
|
customFields: CustomFields;
|
||||||
|
settings: Settings;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function useOperatorData(): ViewData<OperatorData> {
|
||||||
|
const { data: rundown, rundownMetadata, status: rundownStatus } = useRundownWithMetadata();
|
||||||
|
const { data: customFields, status: customFieldStatus } = useCustomFields();
|
||||||
|
const { data: settings, status: settingsStatus } = useSettings();
|
||||||
|
|
||||||
|
return {
|
||||||
|
data: {
|
||||||
|
rundown,
|
||||||
|
rundownMetadata,
|
||||||
|
customFields,
|
||||||
|
settings,
|
||||||
|
},
|
||||||
|
status: aggregateQueryStatus([rundownStatus, customFieldStatus, settingsStatus]),
|
||||||
|
};
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user