Skip to content

Commit

Permalink
chore(web): fixing a few bugs (#849)
Browse files Browse the repository at this point in the history
  • Loading branch information
KaWaite authored Dec 1, 2023
1 parent 76f514f commit c8ad896
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 32 deletions.
6 changes: 0 additions & 6 deletions web/src/beta/features/Editor/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -179,11 +179,6 @@ const Editor: React.FC<Props> = ({ sceneId, projectId, workspaceId, tab }) => {
handleWidgetEditorToggle,
});

const handleTabChange = useCallback(
() => storyPanelRef.current?.handleCurrentPageChange(undefined),
[storyPanelRef],
);

return (
<DndProvider>
<Wrapper>
Expand All @@ -192,7 +187,6 @@ const Editor: React.FC<Props> = ({ sceneId, projectId, workspaceId, tab }) => {
projectId={projectId}
workspaceId={workspaceId}
currentTab={tab}
onTabChange={handleTabChange}
/>
<MainSection>
{leftPanel && (
Expand Down
3 changes: 0 additions & 3 deletions web/src/beta/features/Navbar/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ type Props = {
isDashboard?: boolean;
currentTab?: Tab;
page?: "editor" | "settings";
onTabChange?: () => void;
};

export const Tabs = ["map", "story", "widgets", "publish"] as const;
Expand All @@ -30,7 +29,6 @@ const Navbar: React.FC<Props> = ({
currentTab = "map",
isDashboard = false,
page = "editor",
onTabChange,
}) => {
const {
currentProject,
Expand All @@ -50,7 +48,6 @@ const Navbar: React.FC<Props> = ({
currentTab,
sceneId,
page,
onTabChange,
});

return (
Expand Down
5 changes: 2 additions & 3 deletions web/src/beta/features/Navbar/useRightSection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,11 @@ type Props = {
currentTab?: Tab;
sceneId?: string;
page: "editor" | "settings";
onTabChange?: () => void;
};

const useRightSide = ({ currentTab, page, sceneId, onTabChange }: Props) => {
const useRightSide = ({ currentTab, page, sceneId }: Props) => {
const t = useT();
const handleEditorNavigation = useEditorNavigation({ sceneId, onTabChange });
const handleEditorNavigation = useEditorNavigation({ sceneId });

const rightSide = useMemo(() => {
if (page === "editor") {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useMemo } from "react";
import { useCallback, useMemo, useState } from "react";

import { Story } from "@reearth/services/api/storytellingApi/utils";
import { useT } from "@reearth/services/i18n";
Expand Down Expand Up @@ -60,36 +60,45 @@ const PublicSettings: React.FC<Props> = ({
onUpdateProjectAlias,
}) => {
const t = useT();
const [selectedTab, selectTab] = useState(currentStory ? currentStory.id : "map");

const menu = useMemo(
() => [
{
id: "map",
title: t("Map"),
linkTo: `/settings/project/${project.id}/public/`,
active: !currentStory,
active: selectedTab === "map",
},
...stories.map(s => ({
id: s.id,
title: s.title,
linkTo: `/settings/project/${project.id}/public/${s.id}`,
active: s.id === currentStory?.id,
active: selectedTab === s.id,
})),
],
[stories, project.id, currentStory, t],
[stories, selectedTab, project.id, t],
);

const handleTabChange = useCallback((tab: string) => selectTab(tab), []);

return (
<InnerPage wide>
<InnerMenu>
{menu.map(s => (
<MenuItem key={s.id} text={s.title} active={s.active} linkTo={s.linkTo} />
<MenuItem
key={s.id}
text={s.title}
active={s.active}
linkTo={s.linkTo}
onClick={() => handleTabChange(s.id)}
/>
))}
</InnerMenu>
<SettingsWrapper>
{project.isArchived ? (
<ArchivedSettingNotice />
) : currentStory ? (
) : selectedTab === currentStory?.id ? (
<PublicSettingsDetail
key={currentStory.id}
settingsItem={currentStory}
Expand Down
10 changes: 5 additions & 5 deletions web/src/beta/features/PublishedVisualizer/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,12 @@ export default (alias?: string) => {
return {
align: align ?? "start",
padding: {
top: padding?.top ?? 6,
bottom: padding?.bottom ?? 6,
left: padding?.left ?? 6,
right: padding?.right ?? 6,
top: padding?.top || 6,
bottom: padding?.bottom || 6,
left: padding?.left || 6,
right: padding?.right || 6,
},
gap: area?.gap ?? 6,
gap: area?.gap || 6,
widgets: areaWidgets || [],
background: area?.background as string | undefined,
centered: area?.centered,
Expand Down
11 changes: 2 additions & 9 deletions web/src/beta/hooks/navigationHooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,15 @@ import { useNavigate } from "react-router-dom";

import { Tab } from "@reearth/beta/features/Navbar";

export const useEditorNavigation = ({
sceneId,
onTabChange,
}: {
sceneId?: string;
onTabChange?: () => void;
}) => {
export const useEditorNavigation = ({ sceneId }: { sceneId?: string }) => {
const navigate = useNavigate();

const handleNavigate = useCallback(
(tab: Tab) => {
if (!sceneId) return;
onTabChange?.();
navigate(`/scene/${sceneId}/${tab}`);
},
[sceneId, onTabChange, navigate],
[sceneId, navigate],
);

return sceneId ? handleNavigate : undefined;
Expand Down
5 changes: 5 additions & 0 deletions web/src/beta/lib/core/StoryPanel/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,11 @@ export default (
};
}, [currentPageId, selectedStory?.pages, visualizer, handleLayerReset]);

// Reset parent of core's current page on StoryPanel unmount
useEffect(() => {
return () => onCurrentPageChange?.();
}, [onCurrentPageChange]);

return {
pageInfo,
selectedPageId,
Expand Down

0 comments on commit c8ad896

Please sign in to comment.