mirror of
https://github.com/cpvalente/ontime.git
synced 2026-09-01 20:39:18 +00:00
refactor: pad block row with extra columns
This commit is contained in:
@@ -0,0 +1,12 @@
|
|||||||
|
/**
|
||||||
|
* Allows lazy evaluation and caching of a functions result
|
||||||
|
*/
|
||||||
|
export function lazyEvaluate<T>(fn: () => T): () => T {
|
||||||
|
let result: T | undefined;
|
||||||
|
return function () {
|
||||||
|
if (result === undefined) {
|
||||||
|
result = fn();
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
import { memo } from 'react';
|
import { memo, useRef } from 'react';
|
||||||
|
|
||||||
import { useCurrentBlockId } from '../../../../common/hooks/useSocket';
|
import { useCurrentBlockId } from '../../../../common/hooks/useSocket';
|
||||||
|
|
||||||
@@ -7,21 +7,37 @@ import style from '../CuesheetTable.module.scss';
|
|||||||
interface BlockRowProps {
|
interface BlockRowProps {
|
||||||
hidePast: boolean;
|
hidePast: boolean;
|
||||||
title: string;
|
title: string;
|
||||||
|
columnCount: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
function BlockRow(props: BlockRowProps) {
|
function BlockRow(props: BlockRowProps) {
|
||||||
const { hidePast, title } = props;
|
const { hidePast, title, columnCount } = props;
|
||||||
const { currentBlockId } = useCurrentBlockId();
|
const { currentBlockId } = useCurrentBlockId();
|
||||||
|
const firstCellRef = useRef<null | HTMLTableCellElement>(null);
|
||||||
|
|
||||||
if (hidePast && !currentBlockId) {
|
if (hidePast && !currentBlockId) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const paddingRows = new Array(columnCount - 1).fill(null);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<tr className={style.blockRow}>
|
<tr className={style.blockRow}>
|
||||||
<td tabIndex={-1} role='cell'>
|
<td tabIndex={-1} role='cell' ref={firstCellRef}>
|
||||||
{title}
|
{title}
|
||||||
</td>
|
</td>
|
||||||
|
{paddingRows.map((_value, index) => {
|
||||||
|
return (
|
||||||
|
<td
|
||||||
|
key={index}
|
||||||
|
tabIndex={-1}
|
||||||
|
role='cell'
|
||||||
|
onFocus={() => {
|
||||||
|
firstCellRef.current?.focus();
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
})}
|
||||||
</tr>
|
</tr>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
+5
-1
@@ -4,6 +4,7 @@ import Color from 'color';
|
|||||||
import { isOntimeBlock, isOntimeDelay, isOntimeEvent, OntimeRundownEntry } from 'ontime-types';
|
import { isOntimeBlock, isOntimeDelay, isOntimeEvent, OntimeRundownEntry } from 'ontime-types';
|
||||||
|
|
||||||
import { useSelectedEventId } from '../../../../common/hooks/useSocket';
|
import { useSelectedEventId } from '../../../../common/hooks/useSocket';
|
||||||
|
import { lazyEvaluate } from '../../../../common/utils/lazyEvaluate';
|
||||||
import { getAccessibleColour } from '../../../../common/utils/styleUtils';
|
import { getAccessibleColour } from '../../../../common/utils/styleUtils';
|
||||||
import { useCuesheetOptions } from '../../../cuesheet/cuesheet.options';
|
import { useCuesheetOptions } from '../../../cuesheet/cuesheet.options';
|
||||||
|
|
||||||
@@ -24,6 +25,8 @@ export default function CuesheetBody(props: CuesheetBodyProps) {
|
|||||||
const { selectedEventId } = useSelectedEventId();
|
const { selectedEventId } = useSelectedEventId();
|
||||||
const { hideDelays, hidePast } = useCuesheetOptions();
|
const { hideDelays, hidePast } = useCuesheetOptions();
|
||||||
|
|
||||||
|
const getColumnCount = lazyEvaluate(() => table.getVisibleFlatColumns().length);
|
||||||
|
|
||||||
let eventIndex = 0;
|
let eventIndex = 0;
|
||||||
// for the first event, it will be past if there is something selected
|
// for the first event, it will be past if there is something selected
|
||||||
let isPast = Boolean(selectedEventId);
|
let isPast = Boolean(selectedEventId);
|
||||||
@@ -38,7 +41,8 @@ export default function CuesheetBody(props: CuesheetBodyProps) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (isOntimeBlock(entry)) {
|
if (isOntimeBlock(entry)) {
|
||||||
return <BlockRow key={key} title={entry.title} hidePast={isPast && hidePast} />;
|
const columnCount = getColumnCount();
|
||||||
|
return <BlockRow columnCount={columnCount} key={key} title={entry.title} hidePast={isPast && hidePast} />;
|
||||||
}
|
}
|
||||||
if (isOntimeDelay(entry)) {
|
if (isOntimeDelay(entry)) {
|
||||||
if (isPast && hidePast) {
|
if (isPast && hidePast) {
|
||||||
|
|||||||
Reference in New Issue
Block a user