Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(web): story page update #714

Merged
merged 44 commits into from
Oct 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
78daf07
update scene mutation
mkumbobeaty Sep 26, 2023
dc0b9b6
Displayed all available layers in right panel of story tab
mkumbobeaty Sep 26, 2023
67a4b7c
fix tanslation and type error
mkumbobeaty Sep 26, 2023
c02a812
Merge branch 'main' of github.com:reearth/reearth into chore/story-pa…
mkumbobeaty Sep 27, 2023
7cd1e19
added the update mutation
mkumbobeaty Sep 27, 2023
aecc205
add functionalities for update page
mkumbobeaty Sep 28, 2023
a537453
Merge branch 'main' of github.com:reearth/reearth into chore/storyPag…
mkumbobeaty Sep 28, 2023
c857ef6
improve update page functionality
mkumbobeaty Sep 28, 2023
e6f44ef
check layers base on selected page
mkumbobeaty Sep 28, 2023
0023ab0
improve on page update
mkumbobeaty Sep 28, 2023
5cd1e43
Merge branch 'main' of github.com:reearth/reearth into chore/storyPag…
mkumbobeaty Sep 29, 2023
1fbde7a
Merge branch 'main' of github.com:reearth/reearth into chore/storyPag…
mkumbobeaty Sep 29, 2023
3a767be
Merge branch 'main' of github.com:reearth/reearth into chore/storyPag…
mkumbobeaty Oct 2, 2023
27a068d
implement display layers on map based on selected page
mkumbobeaty Oct 2, 2023
f36bd3c
improve layer dispaly
mkumbobeaty Oct 2, 2023
f4bd806
fix bug
mkumbobeaty Oct 2, 2023
27e954c
update translation
mkumbobeaty Oct 2, 2023
5c75956
add improvement based on comments
mkumbobeaty Oct 3, 2023
af36d44
add select all layers functionalities
mkumbobeaty Oct 3, 2023
79b5fce
fix type error
mkumbobeaty Oct 3, 2023
ac0fd42
improve layer page in virtualizer
mkumbobeaty Oct 3, 2023
47e0509
fix translation error
mkumbobeaty Oct 4, 2023
cd42d27
Merge branch 'main' of github.com:reearth/reearth into chore/storyPag…
mkumbobeaty Oct 4, 2023
4ca8dee
refactor check layers
mkumbobeaty Oct 4, 2023
bfdfcea
Merge branch 'main' of github.com:reearth/reearth into chore/storyPag…
mkumbobeaty Oct 4, 2023
a9b8562
hide alllayers when no layer
mkumbobeaty Oct 5, 2023
4da9118
Merge branch 'main' of github.com:reearth/reearth into chore/storyPag…
mkumbobeaty Oct 5, 2023
bfba04c
Merge branch 'main' of github.com:reearth/reearth into chore/storyPag…
mkumbobeaty Oct 5, 2023
892847d
Merge branch 'main' of github.com:reearth/reearth into chore/storyPag…
mkumbobeaty Oct 6, 2023
20034d4
refactor layer display
mkumbobeaty Oct 6, 2023
b38c549
improve hide and show layers
mkumbobeaty Oct 6, 2023
0a762bc
add tab check on layer display
mkumbobeaty Oct 6, 2023
71db215
fix types
mkumbobeaty Oct 6, 2023
246f6aa
Merge branch 'main' of github.com:reearth/reearth into chore/storyPag…
mkumbobeaty Oct 10, 2023
3783939
Merge branch 'main' of github.com:reearth/reearth into chore/storyPag…
mkumbobeaty Oct 10, 2023
b618e5e
improve code redundant
mkumbobeaty Oct 11, 2023
cfc0c1a
Merge branch 'main' of github.com:reearth/reearth into chore/storyPag…
mkumbobeaty Oct 11, 2023
58122be
remove showStoryPanel
mkumbobeaty Oct 12, 2023
787094e
Merge branch 'main' of github.com:reearth/reearth into chore/storyPag…
mkumbobeaty Oct 12, 2023
ccf4ada
change name
mkumbobeaty Oct 13, 2023
8bf1ea2
fix type
mkumbobeaty Oct 13, 2023
21c7981
refactor layer visibility
mkumbobeaty Oct 13, 2023
cf398b8
remove console
mkumbobeaty Oct 13, 2023
ee83da5
improve layer process
mkumbobeaty Oct 14, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 59 additions & 0 deletions web/src/beta/features/Editor/Settings/hooks.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import { useState, useEffect, useMemo } from "react";

import { NLSLayer } from "@reearth/services/api/layersApi/utils";
import { Page } from "@reearth/services/api/storytellingApi/utils";

type SettingProps = {
onPageUpdate?: (id: string, layers: string[]) => void;
layers?: NLSLayer[];
selectedPage?: Page;
};
export default ({ layers, selectedPage, onPageUpdate }: SettingProps) => {
const pageId = useMemo(() => {
return selectedPage?.id;
}, [selectedPage?.id]);

const selectedLayerIds = useMemo(() => {
return selectedPage?.layersIds || [];
}, [selectedPage]);

const allLayersSelected = useMemo(() => {
const allLayerIds = layers?.map(layer => layer.id) || [];
return selectedLayerIds.length >= allLayerIds.length;
}, [layers, selectedLayerIds.length]);

const [checkedLayers, setCheckedLayer] = useState<string[]>(selectedLayerIds);
const [allCheckedLayers, setAllCheckedLayers] = useState(allLayersSelected);

useEffect(() => {
setCheckedLayer(selectedLayerIds);
setAllCheckedLayers(allLayersSelected);
}, [selectedLayerIds, allLayersSelected]);

const handleLayerCheck = (layerId: string) => {
if (!pageId) return;
setCheckedLayer(prev => {
const updatedLayers = prev.includes(layerId)
? prev.filter(id => id !== layerId)
: [...prev, layerId];

onPageUpdate?.(pageId, updatedLayers);
return updatedLayers ? updatedLayers : prev;
});
};

const handleAllLayersCheck = () => {
if (!pageId) return;
const updatedCheckedLayers = allCheckedLayers ? [] : layers?.map(layer => layer.id) || [];
setCheckedLayer(updatedCheckedLayers);
setAllCheckedLayers(!allCheckedLayers);
onPageUpdate?.(pageId, updatedCheckedLayers);
};

return {
checkedLayers,
allCheckedLayers,
handleLayerCheck,
handleAllLayersCheck,
};
};
53 changes: 44 additions & 9 deletions web/src/beta/features/Editor/Settings/index.tsx
Original file line number Diff line number Diff line change
@@ -1,24 +1,27 @@
import { useState } from "react";

import CheckBoxField from "@reearth/beta/components/CheckboxField";
import FieldComponents from "@reearth/beta/components/fields/PropertyFields";
import SidePanelSectionField from "@reearth/beta/components/SidePanelSectionField";
import type { FlyTo } from "@reearth/beta/lib/core/types";
import type { Camera } from "@reearth/beta/utils/value";
import { NLSLayer } from "@reearth/services/api/layersApi/utils";
import type { Item } from "@reearth/services/api/propertyApi/utils";
import { Page } from "@reearth/services/api/storytellingApi/utils";
import { useT } from "@reearth/services/i18n";
import { styled } from "@reearth/services/theme";

import { Tab } from "../../Navbar";

import useHooks from "./hooks";

type Props = {
propertyId: string;
propertyItems?: Item[];
currentCamera?: Camera;
layers?: NLSLayer[];
selectedPage?: Page;
tab?: Tab;
onFlyTo?: FlyTo;
onPageUpdate?: (id: string, layers: string[]) => void;
};

const Settings: React.FC<Props> = ({
Expand All @@ -27,22 +30,44 @@ const Settings: React.FC<Props> = ({
currentCamera,
layers,
tab,
selectedPage,
onFlyTo,
onPageUpdate,
}) => {
const t = useT();
const [layerCheck, setLayerCheck] = useState(true);
const { allCheckedLayers, checkedLayers, handleAllLayersCheck, handleLayerCheck } = useHooks({
layers,
selectedPage,
onPageUpdate,
});

return (
<Wrapper>
{tab == "story" && (
<SidePanelSectionField title={t("Layers")}>
{layers?.map((layer, idx) => (
<Layer key={idx}>
<CheckBoxField onClick={setLayerCheck} checked={layerCheck} label={layer.title} />
</Layer>
))}
{layers && layers?.length > 0 && (
<LayerWrapper>
<AllLayers>
<CheckBoxField
label={t("All Layers")}
onClick={handleAllLayersCheck}
checked={allCheckedLayers}
/>
</AllLayers>
{layers?.map((layer, idx) => (
<Layer key={idx}>
<CheckBoxField
onClick={() => handleLayerCheck(layer.id)}
checked={checkedLayers.includes(layer.id)}
label={layer.title}
/>
</Layer>
))}
</LayerWrapper>
)}
</SidePanelSectionField>
)}

{propertyItems?.map((i, idx) => (
<SidePanelSectionField title={i.title ?? "Undefined"} key={idx}>
<FieldComponents
Expand Down Expand Up @@ -71,6 +96,16 @@ const Item = styled.div`
border-radius: 4px;
`;

const LayerWrapper = styled.div`
border: 1px solid ${({ theme }) => theme.outline.weak};
border-radius: 4px;
`;

const Layer = styled.div`
padding: 4px;
padding: 6px 4px;
`;

const AllLayers = styled.div`
border-bottom: 1px solid ${({ theme }) => theme.outline.weak};
padding: 6px 4px;
`;
14 changes: 13 additions & 1 deletion web/src/beta/features/Editor/Visualizer/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
useStorytellingFetcher,
usePropertyFetcher,
} from "@reearth/services/api";
import type { Page } from "@reearth/services/api/storytellingApi/utils";
import { config } from "@reearth/services/config";
import {
useSceneMode,
Expand All @@ -31,10 +32,14 @@
sceneId,
isBuilt,
storyId,
currentPage,
showStoryPanel,
}: {
sceneId?: string;
isBuilt?: boolean;
storyId?: string;
currentPage?: Page;
showStoryPanel?: boolean;
}) => {
const { useUpdateWidget, useUpdateWidgetAlignSystem } = useWidgetsFetcher();
const { useGetLayersQuery } = useLayersFetcher();
Expand Down Expand Up @@ -87,14 +92,21 @@
[selected],
);

const layers = useMemo(() => processLayers(nlsLayers), [nlsLayers]);
const layers = useMemo(() => {
const processedLayers = processLayers(nlsLayers);
if (!showStoryPanel) return processedLayers;
return processedLayers?.map(layer => ({
...layer,
visible: currentPage?.layersIds?.includes(layer.id),
}));
}, [nlsLayers, showStoryPanel, currentPage?.layersIds]);

// TODO: Use GQL value
const rootLayerId = "";

const widgets = convertWidgets(scene);
// TODO: Fix to use exact type through GQL typing
const sceneProperty: any = useMemo(

Check warning on line 109 in web/src/beta/features/Editor/Visualizer/hooks.ts

View workflow job for this annotation

GitHub Actions / ci-web / ci

Unexpected any. Specify a different type
() => ({
tiles: [
{
Expand Down Expand Up @@ -131,7 +143,7 @@
vt: T,
selectedLayer?: Layer,
) => {
const propertyId = (selectedLayer?.infobox?.blocks?.find(b => b.id === blockId) as any)

Check warning on line 146 in web/src/beta/features/Editor/Visualizer/hooks.ts

View workflow job for this annotation

GitHub Actions / ci-web / ci

Unexpected any. Specify a different type
?.propertyId as string | undefined;
if (!propertyId) return;

Expand Down
10 changes: 5 additions & 5 deletions web/src/beta/features/Editor/Visualizer/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import type { MapRef } from "@reearth/beta/lib/core/Map/ref";
import StoryPanel, { type InstallableStoryBlock } from "@reearth/beta/lib/core/StoryPanel";
import CoreVisualizer, { type Props as VisualizerProps } from "@reearth/beta/lib/core/Visualizer";
import type { Camera } from "@reearth/beta/utils/value";
import type { Story } from "@reearth/services/api/storytellingApi/utils";
import type { Story, Page } from "@reearth/services/api/storytellingApi/utils";
import { config } from "@reearth/services/config";
import { styled } from "@reearth/services/theme";

Expand All @@ -20,7 +20,7 @@ export type Props = {
// storytelling
showStoryPanel?: boolean;
selectedStory?: Story;
currentPageId?: string;
currentPage?: Page;
isAutoScrolling?: MutableRefObject<boolean>;
installableBlocks?: InstallableStoryBlock[];
onCurrentPageChange: (id: string, disableScrollIntoView?: boolean) => void;
Expand All @@ -36,7 +36,7 @@ const Visualizer: React.FC<Props> = ({
currentCamera,
showStoryPanel,
selectedStory,
currentPageId,
currentPage,
isAutoScrolling,
installableBlocks,
onCurrentPageChange,
Expand Down Expand Up @@ -76,7 +76,7 @@ const Visualizer: React.FC<Props> = ({
handleDropLayer,
zoomToLayer,
handleMount,
} = useHooks({ sceneId, isBuilt, storyId: selectedStory?.id });
} = useHooks({ sceneId, isBuilt, storyId: selectedStory?.id, currentPage, showStoryPanel });

const renderInfoboxInsertionPopUp = useCallback<
NonNullable<VisualizerProps["renderInfoboxInsertionPopup"]>
Expand Down Expand Up @@ -133,7 +133,7 @@ const Visualizer: React.FC<Props> = ({
{showStoryPanel && (
<StoryPanel
selectedStory={selectedStory}
currentPageId={currentPageId}
currentPageId={currentPage?.id}
isAutoScrolling={isAutoScrolling}
installableBlocks={installableBlocks}
isEditable={!!inEditor}
Expand Down
4 changes: 3 additions & 1 deletion web/src/beta/features/Editor/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ const Editor: React.FC<Props> = ({ sceneId, projectId, workspaceId, tab }) => {
handlePageAdd,
handlePageMove,
handleStoryBlockMove: onStoryBlockMove,
handlePageUpdate,
} = useStorytelling({
sceneId,
onFlyTo: handleFlyTo,
Expand Down Expand Up @@ -94,6 +95,7 @@ const Editor: React.FC<Props> = ({ sceneId, projectId, workspaceId, tab }) => {
currentCamera,
showSceneSettings: selectedSceneSetting,
onFlyTo: handleFlyTo,
onPageUpdate: handlePageUpdate,
});

const { secondaryNavbar } = useSecondaryNavbar({
Expand Down Expand Up @@ -138,7 +140,7 @@ const Editor: React.FC<Props> = ({ sceneId, projectId, workspaceId, tab }) => {
sceneId={sceneId}
showStoryPanel={selectedProjectType === "story"}
selectedStory={selectedStory}
currentPageId={currentPage?.id}
currentPage={currentPage}
isAutoScrolling={isAutoScrolling}
installableBlocks={installableStoryBlocks}
currentCamera={currentCamera}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,14 @@ type Props = {
layers?: NLSLayer[];
tab?: Tab;
onFlyTo?: FlyTo;
onPageUpdate?: (id: string, layers: string[]) => void;
};

const StoryRightPanel: React.FC<Props> = ({
selectedPage,
currentCamera,
layers,
onPageUpdate,
tab,
onFlyTo,
}) => {
Expand All @@ -48,7 +50,9 @@ const StoryRightPanel: React.FC<Props> = ({
propertyItems={propertyItems}
currentCamera={currentCamera}
layers={layers}
selectedPage={selectedPage}
tab={tab}
onPageUpdate={onPageUpdate}
onFlyTo={onFlyTo}
/>
),
Expand Down
14 changes: 13 additions & 1 deletion web/src/beta/features/Editor/useRightPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ type Props = {
showSceneSettings?: boolean;
currentCamera?: Camera;
onFlyTo?: FlyTo;
onPageUpdate?: (id: string, layers: string[]) => void;
};

export default ({
Expand All @@ -27,6 +28,7 @@ export default ({
currentPage,
showSceneSettings,
currentCamera,
onPageUpdate,
onFlyTo,
}: Props) => {
const rightPanel = useMemo<ReactNode | undefined>(() => {
Expand All @@ -48,6 +50,7 @@ export default ({
layers={nlsLayers}
tab={tab}
onFlyTo={onFlyTo}
onPageUpdate={onPageUpdate}
/>
);
case "widgets":
Expand All @@ -57,7 +60,16 @@ export default ({
default:
return undefined;
}
}, [tab, sceneId, showSceneSettings, currentCamera, onFlyTo, currentPage, nlsLayers]);
}, [
tab,
sceneId,
showSceneSettings,
currentCamera,
currentPage,
nlsLayers,
onFlyTo,
onPageUpdate,
]);

return {
rightPanel,
Expand Down
15 changes: 15 additions & 0 deletions web/src/beta/features/Editor/useStorytelling.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export default function ({ sceneId, onFlyTo }: Props) {
useDeleteStoryPage,
useMoveStoryPage,
useMoveStoryBlock,
useUpdateStoryPage,
useInstallableStoryBlocksQuery,
} = useStorytellingAPI();

Expand Down Expand Up @@ -138,6 +139,19 @@ export default function ({ sceneId, onFlyTo }: Props) {
[useMoveStoryBlock, selectedStory],
);

const handlePageUpdate = useCallback(
async (pageId: string, layers: string[]) => {
if (!selectedStory) return;
await useUpdateStoryPage({
sceneId,
storyId: selectedStory.id,
pageId,
layers,
});
},
[sceneId, selectedStory, useUpdateStoryPage],
);

return {
selectedStory,
currentPage,
Expand All @@ -149,5 +163,6 @@ export default function ({ sceneId, onFlyTo }: Props) {
handlePageAdd,
handlePageMove,
handleStoryBlockMove,
handlePageUpdate,
};
}
6 changes: 3 additions & 3 deletions web/src/beta/lib/core/engines/Cesium/Feature/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -98,13 +98,13 @@ export default function Feature({
const useSceneSphericalHarmonicCoefficients =
!!props.sceneProperty?.light?.sphericalHarmonicCoefficients;
const useSceneSpecularEnvironmentMaps = !!props.sceneProperty?.light?.specularEnvironmentMaps;

const isVisible = layer.layer.visible !== false || isHidden;
const componentId =
urlMD5 +
generateIDWithMD5(
`${layer.id}_${
f?.id ?? ""
}_${k}_${isHidden}_${useSceneSphericalHarmonicCoefficients}_${useSceneSpecularEnvironmentMaps}_${
}_${k}_${isVisible}_${useSceneSphericalHarmonicCoefficients}_${useSceneSpecularEnvironmentMaps}_${
JSON.stringify(f?.[k]) ?? ""
}`,
);
Expand Down Expand Up @@ -143,7 +143,7 @@ export default function Feature({
geometry={f?.geometry}
feature={f}
layer={layer}
isVisible={layer.layer.visible !== false && !isHidden}
isVisible={isVisible}
/>
);

Expand Down
Loading
Loading