Files
ontime/apps/client/src/views/countdown/CountdownSelect.tsx
T
Carlos Valente 1849b4d39f Deps migration (#1988)
* chore: migrate eslint to oxlint

* chore: migrate prettier to oxfmt

* chore: migrate typescript

* chore: toThrow should have a expected value

* chore: cast test value as Day

* chore: small title fix

* chore: mocks should be hoisted

* chore: incorrect async useage

* chore: test should be inside description

* chore: test sohuld include an expeced

* chore: oxfmt

---------

Co-authored-by: alex-Arc <omnivox@LAPTOP-RC5SNBVV.localdomain>
2026-03-08 16:22:12 +01:00

99 lines
3.4 KiB
TypeScript

import { EntryId, PlayableEvent } from 'ontime-types';
import { useState } from 'react';
import { IoArrowBack, IoClose, IoSaveOutline } from 'react-icons/io5';
import { useNavigate } from 'react-router';
import Button from '../../common/components/buttons/Button';
import { ExtendedEntry } from '../../common/utils/rundownMetadata';
import { cx } from '../../common/utils/styleUtils';
import ClockTime from '../common/clock-time/ClockTime';
import { makeSubscriptionsUrl } from './countdown.utils';
import './Countdown.scss';
interface CountdownSelectProps {
events: ExtendedEntry<PlayableEvent>[];
subscriptions: EntryId[];
disableEdit: () => void;
}
export default function CountdownSelect({ events, subscriptions, disableEdit }: CountdownSelectProps) {
const [selected, setSelected] = useState<EntryId[]>(subscriptions);
const navigate = useNavigate();
/**
* Toggles an entry from the selected set
*/
const toggleSelect = (entryId: EntryId) => {
setSelected((prev) => {
if (prev.includes(entryId)) {
// If the entry is already selected, remove it
return prev.filter((id) => id !== entryId);
}
return [...prev, entryId];
});
};
/**
* Creates a URL with the selected subscriptions
* and navigates to it
*/
const applySelection = () => {
// we remove events that no longer exist to avoid stale subscriptions
const filteredSelected = selected.filter((id) => events.some((event) => event.id === id));
const url = makeSubscriptionsUrl(window.location.href, filteredSelected);
disableEdit();
setSelected([]);
navigate(url.search.toString());
};
// make a copy of the selected array for quick lookup
const selectedIds = new Set(selected);
return (
<div className='list-container'>
{events.map((event, index) => {
const title = event.title || '{no title}';
const isSelected = selectedIds.has(event.id);
return (
<div
key={index}
role='button'
tabIndex={0}
onClick={() => toggleSelect(event.id)}
onKeyDown={(e) => {
if (e.key === 'Enter' || e.key === ' ') {
toggleSelect(event.id);
e.stopPropagation();
}
}}
className={cx(['sub', isSelected && 'sub--selected'])}
>
<div className='sub__binder' style={{ '--user-color': event?.colour ?? '' }} />
<div className='sub__schedule'>
<ClockTime value={event.timeStart} preferredFormat12='h:mm a' preferredFormat24='HH:mm' />
<ClockTime value={event.timeEnd} preferredFormat12='h:mm a' preferredFormat24='HH:mm' />
</div>
<div className='sub__label'>{isSelected ? 'Click to remove' : 'Click to add'}</div>
<div className='sub__title'>{title}</div>
</div>
);
})}
<div className='fab-container'>
<Button variant='subtle' size='xlarge' onClick={disableEdit}>
<IoArrowBack /> Go back
</Button>
<Button variant='subtle' size='xlarge' onClick={() => setSelected([])} disabled={selected.length === 0}>
<IoClose /> Clear
</Button>
<Button variant='primary' size='xlarge' disabled={events.length < 1} onClick={applySelection}>
<IoSaveOutline /> Save
</Button>
</div>
</div>
);
}