Skip to content

Commit

Permalink
chore(web): visualizer clock update (#782)
Browse files Browse the repository at this point in the history
  • Loading branch information
mkumbobeaty authored Nov 8, 2023
1 parent f5ab499 commit 9c4c84a
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export default ({ value, onChange, setDateTime }: Props) => {
setDateTime?.(formattedDateTime);
onChange?.(formattedDateTime);
}
}, [offsetFromUTC, selectedTimezone, date, time, setDateTime, onChange]);
}, [offsetFromUTC, selectedTimezone.timezone, date, time, setDateTime, onChange]);

const handleTimezoneSelect = useCallback(
(newValue: string) => {
Expand Down Expand Up @@ -81,7 +81,7 @@ export default ({ value, onChange, setDateTime }: Props) => {
time,
selectedTimezone,
offsetFromUTC,
onTimeChange: handleTimeChange,
handleTimeChange,
onTimezoneSelect: handleTimezoneSelect,
onDateChange: handleDateChange,
onDateTimeApply: handleApplyChange,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ const EditPanel: React.FC<Props> = ({ onChange, onClose, value, setDateTime }) =
selectedTimezone,
offsetFromUTC,
onDateChange,
onTimeChange,
onTimezoneSelect,
onDateTimeApply,
handleTimeChange,
} = useHooks({ value, onChange, setDateTime });

const isButtonDisabled = useMemo(() => {
Expand All @@ -45,7 +45,7 @@ const EditPanel: React.FC<Props> = ({ onChange, onClose, value, setDateTime }) =
<TextWrapper>
<Label>{t("Time")}</Label>

<Input type="time" value={time} onChange={onTimeChange} />
<Input type="time" value={time} onChange={handleTimeChange} />
</TextWrapper>
<SelectWrapper>
<Label>{t("Time Zone")}</Label>
Expand Down
1 change: 0 additions & 1 deletion web/src/beta/features/Editor/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ const Editor: React.FC<Props> = ({ sceneId, projectId, workspaceId, tab }) => {
handleFlyTo,
handleCameraUpdate,
} = useHooks({ sceneId, tab });

const {
selectedStory,
storyPanelRef,
Expand Down
2 changes: 1 addition & 1 deletion web/src/beta/features/Editor/useRightPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,13 @@ export default ({
scene,
tab,
layerStyles,
nlsLayers,
sceneId,
currentCamera,
selectedLayerStyleId,
selectedSceneSetting,
sceneSettings,
currentPage,
nlsLayers,
onFlyTo,
onLayerStyleValueUpdate,
onLayerConfigUpdate,
Expand Down
3 changes: 1 addition & 2 deletions web/src/beta/features/Editor/useStorytelling.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ export default function ({ sceneId }: Props) {
} = useStorytellingAPI();

const { stories } = useStoriesQuery({ sceneId });

const { installableStoryBlocks } = useInstallableStoryBlocksQuery({ sceneId });

const selectedStory = useMemo(() => (stories?.length ? stories[0] : undefined), [stories]);
Expand All @@ -50,7 +49,7 @@ export default function ({ sceneId }: Props) {
storyPanelRef?.current?.handleCurrentPageChange(pageId);
}
},
[selectedStoryPageId, selectedStory?.pages, storyPanelRef],
[selectedStoryPageId, selectedStory?.pages],
);

const handlePageDuplicate = useCallback(async (pageId: string) => {
Expand Down
3 changes: 2 additions & 1 deletion web/src/beta/lib/core/Map/useTimelineManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ export type TimelineCommitter = {
| "widgetContext"
| "pluginAPI"
| "featureResource"
| "storyTimelineBlock";
| "storyTimelineBlock"
| "storyPage";
id?: string;
};

Expand Down
32 changes: 30 additions & 2 deletions web/src/beta/lib/core/StoryPanel/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,34 @@ export default (
[selectedPageId, isEditable],
);

const onTimeChange = useCallback(
(time: Date) => {
return visualizer?.current?.timeline?.current?.commit({
cmd: "SET_TIME",
payload: {
start: visualizer?.current?.timeline?.current?.computedTimeline?.start,
current: time,
stop: visualizer?.current?.timeline?.current?.computedTimeline?.stop,
},
committer: { source: "storyPage", id: currentPageId },
});
},
[currentPageId, visualizer],
);

const handlePageTime = useCallback(
(page: StoryPage) => {
const timePointField = page.property?.timePoint;
const currentTime = timePointField?.timePoint?.value;
if (!currentTime) onTimeChange?.(new Date());
else {
const getNewDate = new Date(currentTime.substring(0, 19)).getTime();
return onTimeChange?.(new Date(getNewDate));
}
},
[onTimeChange],
);

const handleCurrentPageChange = useCallback(
(pageId: string, disableScrollIntoView?: boolean) => {
if (pageId === currentPageId) return;
Expand All @@ -76,7 +104,7 @@ export default (
isAutoScrolling.current = true;
element?.scrollIntoView({ behavior: "smooth" });
}

handlePageTime(newPage);
const cameraAnimation = newPage.property?.cameraAnimation;

const destination = cameraAnimation?.cameraPosition?.value;
Expand All @@ -86,7 +114,7 @@ export default (

visualizer.current?.engine.flyTo({ ...destination }, { duration });
},
[selectedStory?.pages, currentPageId, visualizer, onCurrentPageChange],
[currentPageId, selectedStory?.pages, onCurrentPageChange, handlePageTime, visualizer],
);

const pageInfo = useMemo(() => {
Expand Down

0 comments on commit 9c4c84a

Please sign in to comment.