Skip to content

Commit

Permalink
fix: suppress screen flicker when judging useCore
Browse files Browse the repository at this point in the history
  • Loading branch information
rot1024 committed Feb 17, 2023
1 parent b51569e commit b1852dd
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 5 deletions.
5 changes: 4 additions & 1 deletion src/components/pages/EarthEditor/index.tsx
Expand Up @@ -34,7 +34,10 @@ const EarthEditor: React.FC<Props> = () => {
header={<Header />}
left={<LeftMenu />}
centerTop={<PrimitiveHeader />}
center={core ? <CoreCanvasArea inEditor /> : <CanvasArea inEditor />}
center={
typeof core == "boolean" &&
(core ? <CoreCanvasArea inEditor /> : <CanvasArea inEditor />)
}
right={<RightMenu />}
/>
</DndProvider>
Expand Down
3 changes: 2 additions & 1 deletion src/components/pages/Preview/index.tsx
Expand Up @@ -27,7 +27,8 @@ const PreviewPage: React.FC<Props> = () => {
<ThemeProvider>
<DndProvider>
<AuthenticationRequiredPage>
{core ? <CoreCanvasArea isBuilt /> : <CanvasArea isBuilt />}
{typeof core === "boolean" &&
(core ? <CoreCanvasArea isBuilt /> : <CanvasArea isBuilt />)}
</AuthenticationRequiredPage>
</DndProvider>
</ThemeProvider>
Expand Down
4 changes: 3 additions & 1 deletion src/components/pages/Published/index.tsx
Expand Up @@ -11,9 +11,11 @@ const PublishedPage: React.FC<{
alias?: string;
}> = ({ alias }) => {
const core = useCore("published", alias);

return (
<DndProvider>
{core ? <CorePublished alias={alias} /> : <Published alias={alias} />}
{typeof core === "boolean" &&
(core ? <CorePublished alias={alias} /> : <Published alias={alias} />)}
</DndProvider>
);
};
Expand Down
7 changes: 5 additions & 2 deletions src/util/use-core.ts
Expand Up @@ -5,7 +5,10 @@ import { PublishedData } from "@reearth/components/organisms/Published/core/type
import { useGetScenePropertyQuery } from "@reearth/gql";

// TODO: Remove this hook when we use reearth/core completely.
export const useCore = (type?: "published" | "earth_editor", alias?: string): boolean => {
export const useCore = (
type?: "published" | "earth_editor",
alias?: string,
): boolean | undefined => {
const query = useMemo(() => new URLSearchParams(window.location.search), []);
if (query.has("useCore") || type === undefined) {
return query.has("useCore");
Expand Down Expand Up @@ -33,7 +36,7 @@ export const useCore = (type?: "published" | "earth_editor", alias?: string): bo

if (type === "published") {
// eslint-disable-next-line react-hooks/rules-of-hooks
const [isCore, setIsCore] = useState(false);
const [isCore, setIsCore] = useState<boolean | undefined>(undefined);
// eslint-disable-next-line react-hooks/rules-of-hooks
const actualAlias = useMemo(
() => alias || new URLSearchParams(window.location.search).get("alias") || undefined,
Expand Down

0 comments on commit b1852dd

Please sign in to comment.