refactor: code review cleanup

This commit is contained in:
cv
2023-09-01 20:09:09 +02:00
parent 124eb9a6ea
commit 5245da7ce7
4 changed files with 18 additions and 18 deletions
@@ -7,7 +7,11 @@ import { millisToDelayString } from '../../utils/dateConfig';
import style from './DelayIndicator.module.scss'; import style from './DelayIndicator.module.scss';
export default function DelayIndicator(props: { delayValue?: number }) { interface DelayIndicatorProps {
delayValue?: number;
}
export default function DelayIndicator(props: DelayIndicatorProps) {
const { delayValue } = props; const { delayValue } = props;
if (typeof delayValue === 'number') { if (typeof delayValue === 'number') {
@@ -48,7 +48,7 @@ export default function useFollowComponent(props: UseFollowComponentProps) {
const scrollToRefComponent = useCallback( const scrollToRefComponent = useCallback(
(componentRef = followRef, containerRef = scrollRef, offset = topOffset) => { (componentRef = followRef, containerRef = scrollRef, offset = topOffset) => {
if (followRef.current && containerRef.current) { if (componentRef.current && containerRef.current) {
// @ts-expect-error -- we know this are not null // @ts-expect-error -- we know this are not null
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
scrollToComponent(componentRef!, scrollRef!, offset); scrollToComponent(componentRef!, scrollRef!, offset);
+11 -15
View File
@@ -1,7 +1,7 @@
import { useEffect, useRef, useState } from 'react'; import { useEffect, useRef, useState } from 'react';
import { useSearchParams } from 'react-router-dom'; import { useSearchParams } from 'react-router-dom';
import { SupportedEvent, UserFields } from 'ontime-types'; import { isOntimeEvent, SupportedEvent, UserFields } from 'ontime-types';
import { getLastEvent } from 'ontime-utils'; import { getFirstEvent, getLastEvent } from 'ontime-utils';
import NavigationMenu from '../../common/components/navigation-menu/NavigationMenu'; import NavigationMenu from '../../common/components/navigation-menu/NavigationMenu';
import Empty from '../../common/components/state/Empty'; import Empty from '../../common/components/state/Empty';
@@ -63,9 +63,9 @@ export default function Operator() {
}; };
const handleScroll = () => { const handleScroll = () => {
if (selectedRef && scrollRef) { if (selectedRef?.current && scrollRef?.current) {
const selectedRect = selectedRef.current?.getBoundingClientRect(); const selectedRect = selectedRef.current.getBoundingClientRect();
const scrollerRect = scrollRef.current?.getBoundingClientRect(); const scrollerRect = scrollRef.current.getBoundingClientRect();
if (selectedRect && scrollerRect) { if (selectedRect && scrollerRect) {
const distanceFromTop = selectedRect.top - scrollerRect.top; const distanceFromTop = selectedRect.top - scrollerRect.top;
const hasScrolledOutOfThreshold = distanceFromTop < -8 || distanceFromTop > selectedOffset; const hasScrolledOutOfThreshold = distanceFromTop < -8 || distanceFromTop > selectedOffset;
@@ -74,14 +74,10 @@ export default function Operator() {
} }
}; };
if ( const missingData = !data || !userFields || !projectData;
!data || const isLoading = status === 'loading' || userFieldsStatus === 'loading' || projectDataStatus === 'loading';
status === 'loading' ||
!userFields || if (missingData || isLoading) {
userFieldsStatus === 'loading' ||
!projectData ||
projectDataStatus === 'loading'
) {
return <Empty text='Loading...' />; return <Empty text='Loading...' />;
} }
@@ -94,7 +90,7 @@ export default function Operator() {
let isPast = Boolean(featureData.selectedEventId); let isPast = Boolean(featureData.selectedEventId);
const hidePast = isStringBoolean(searchParams.get('hidepast')); const hidePast = isStringBoolean(searchParams.get('hidepast'));
const firstEvent = getLastEvent(data); const firstEvent = getFirstEvent(data);
const lastEvent = getLastEvent(data); const lastEvent = getLastEvent(data);
return ( return (
@@ -114,7 +110,7 @@ export default function Operator() {
<div className={style.operatorEvents} onScroll={handleScroll} ref={scrollRef}> <div className={style.operatorEvents} onScroll={handleScroll} ref={scrollRef}>
{data.map((entry) => { {data.map((entry) => {
if (entry.type === SupportedEvent.Event) { if (isOntimeEvent(entry)) {
const isSelected = featureData.selectedEventId === entry.id; const isSelected = featureData.selectedEventId === entry.id;
if (isSelected) { if (isSelected) {
isPast = false; isPast = false;
+1 -1
View File
@@ -1,5 +1,5 @@
// runtime utils // runtime utils
export { getFirst, getLastEvent, getNext, getPrevious } from './src/rundown-utils/rundownUtils.js'; export { getFirst, getFirstEvent, getLastEvent, getNext, getPrevious } from './src/rundown-utils/rundownUtils.js';
export { validatePlayback } from './src/validate-action/validatePlayback.js'; export { validatePlayback } from './src/validate-action/validatePlayback.js';
// rundown utils // rundown utils