mirror of
https://github.com/cpvalente/ontime.git
synced 2026-08-31 20:09:11 +00:00
feat: editor layout
This commit is contained in:
committed by
Carlos Valente
parent
967e92e2c8
commit
da02ecd113
@@ -0,0 +1,29 @@
|
||||
import { useCallback } from 'react';
|
||||
import { EntryId, MaybeString } from 'ontime-types';
|
||||
|
||||
import { useCollapsedGroups } from './useCollapsedGroups';
|
||||
import { useEventSelection } from './useEventSelection';
|
||||
|
||||
type SelectAndRevealOptions = {
|
||||
id: EntryId;
|
||||
index: number;
|
||||
parent?: MaybeString;
|
||||
};
|
||||
|
||||
export function useSelectAndRevealEntry(rundownId: string) {
|
||||
const { expandGroup } = useCollapsedGroups(rundownId);
|
||||
const selectEntry = useEventSelection((state) => state.setSelectedEvents);
|
||||
const scrollToEntry = useEventSelection((state) => state.scrollToEntry);
|
||||
|
||||
return useCallback(
|
||||
({ id, index, parent }: SelectAndRevealOptions) => {
|
||||
expandGroup(parent);
|
||||
selectEntry({ id, index, selectMode: 'click' });
|
||||
// Wait one frame so collapsed-group expansion is reflected in rendered/visible entries before scrolling.
|
||||
requestAnimationFrame(() => {
|
||||
scrollToEntry(id);
|
||||
});
|
||||
},
|
||||
[expandGroup, scrollToEntry, selectEntry],
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user