Skip to content

Commit

Permalink
fix: Grid - cursor moving duration not matched
Browse files Browse the repository at this point in the history
  • Loading branch information
winetree94 committed Sep 7, 2023
1 parent 535fff2 commit c86c472
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 12 deletions.
13 changes: 3 additions & 10 deletions src/components/timeline/Timeline.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import { TimeLineTrack } from '../../model/timeline/timeline';
import styles from './Timeline.module.scss';
import { useAppDispatch, useAppSelector } from 'store/hooks';
import { SettingsActions } from 'store/settings';
import { EffectSelectors } from 'store/effect';
import { memo, useCallback, useMemo } from 'react';
import { store } from 'store';
import { isEqual } from 'lodash';
Expand Down Expand Up @@ -79,17 +78,11 @@ export const Timeline = memo((props: TimelineProps) => {
});
const dispatch = useAppDispatch();
const queueIndex = useAppSelector(SettingSelectors.queueIndex);
const queuePosition = useAppSelector(SettingSelectors.queuePosition);
const queueStart = useAppSelector(SettingSelectors.queueStart);

const queueIndexString = useMemo(() => queueIndex.toString(), [queueIndex]);
const maxDurationByIndex = useAppSelector(EffectSelectors.maxDurationByIndex);

const duration = useMemo(() => {
return queuePosition === 'forward'
? maxDurationByIndex[queueIndex] || 0
: maxDurationByIndex[queueIndex + 1] || 0;
}, [maxDurationByIndex, queueIndex, queuePosition]);
const duration = useAppSelector(
SettingSelectors.currentPageNextQueueIndexMaxDuration,
);

const columnDefs: GridColumnDef<TimeLineTrack>[] = useMemo(() => {
return [
Expand Down
31 changes: 29 additions & 2 deletions src/store/settings/selectors.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { RootState } from 'store';
import { createSelector, EntityId } from '@reduxjs/toolkit';
import { createSelector } from '@reduxjs/toolkit';
import { ObjectSelectors } from 'store/object/selectors';
import { QueueDocumentSettings } from './model';
import { EffectSelectors } from 'store/effect/selectors';
Expand Down Expand Up @@ -322,7 +322,7 @@ const currentPageQueueIndexEffectsByObjectId = createSelector(
);

const currentPageQueueIndexMaxDuration = createSelector(
[currentPageQueueIndexEffects],
[currentPageQueueIndexEffects, queuePosition],
(effects) => {
return effects.reduce((acc, effect) => {
if (acc < effect.duration + effect.delay) {
Expand All @@ -333,6 +333,32 @@ const currentPageQueueIndexMaxDuration = createSelector(
},
);

const currentPageNextQueueIndexMaxDuration = createSelector(
[currentPageEffects, queueIndex, queuePosition],
(effects, queueIndex, queuePosition) => {
const effectsMap = effects.reduce<Record<string, QueueEffectType[]>>(
(result, effect) => {
if (!result[effect.index]) {
result[effect.index] = [];
}
result[effect.index].push(effect);
return result;
},
{},
);

const targetIndex =
queuePosition === 'forward' ? queueIndex : queueIndex + 1;

return (effectsMap[targetIndex] || []).reduce((acc, effect) => {
if (acc < effect.duration + effect.delay) {
acc = effect.duration + effect.delay;
}
return acc;
}, 0);
},
);

export const SettingSelectors = {
pageId,
queueIndex,
Expand Down Expand Up @@ -366,5 +392,6 @@ export const SettingSelectors = {
currentPageEffects,
currentPageQueueIndexEffects,
currentPageQueueIndexEffectsByObjectId,
currentPageNextQueueIndexMaxDuration,
currentPageQueueIndexMaxDuration,
};

0 comments on commit c86c472

Please sign in to comment.