mirror of
https://github.com/cpvalente/ontime.git
synced 2026-08-16 12:53:32 +00:00
1849b4d39f
* 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>
48 lines
1.4 KiB
TypeScript
48 lines
1.4 KiB
TypeScript
import { OntimeView, URLPreset } from 'ontime-types';
|
|
import { useSearchParams } from 'react-router';
|
|
|
|
import { useViewUrlPresets } from '../../hooks-query/useUrlPresets';
|
|
import { cx } from '../../utils/styleUtils';
|
|
import Button from '../buttons/Button';
|
|
|
|
import style from './ViewParamsPresets.module.scss';
|
|
|
|
/**
|
|
* Shows a list of presets for the current view
|
|
*/
|
|
export function ViewParamsPresets({ target }: { target: OntimeView }) {
|
|
const { viewPresets } = useViewUrlPresets(target);
|
|
const [searchParams, setSearchParams] = useSearchParams();
|
|
|
|
const handleRecall = (preset: URLPreset) => {
|
|
const newSearch = new URLSearchParams(preset.search);
|
|
newSearch.set('alias', preset.alias);
|
|
setSearchParams(newSearch);
|
|
};
|
|
|
|
if (viewPresets.length === 0) {
|
|
return null;
|
|
}
|
|
|
|
return (
|
|
<div className={style.presetSection}>
|
|
{viewPresets.map((preset) => {
|
|
const active = searchParams.get('alias') === preset.alias;
|
|
return (
|
|
<div key={preset.alias} className={cx([style.preset, active && style.active])}>
|
|
<div>{preset.alias}</div>
|
|
<Button
|
|
variant={active ? 'ghosted' : 'subtle-white'}
|
|
onClick={() => handleRecall(preset)}
|
|
disabled={active}
|
|
className={style.presetActions}
|
|
>
|
|
{active ? 'Applied' : 'Apply'}
|
|
</Button>
|
|
</div>
|
|
);
|
|
})}
|
|
</div>
|
|
);
|
|
}
|