Skip to content

Commit

Permalink
chore: fix page title empty string (#762)
Browse files Browse the repository at this point in the history
Co-authored-by: nina992 <[email protected]>
  • Loading branch information
nina992 and nina992 authored Oct 30, 2023
1 parent 3df69f8 commit 44e573f
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import PopoverMenuContent from "@reearth/beta/components/PopoverMenuContent";
import Action from "@reearth/beta/features/Editor/tabs/story/LeftPanel/Action";
import PageItemWrapper from "@reearth/beta/features/Editor/tabs/story/LeftPanel/PageItemWrapper";
import { getFieldValue } from "@reearth/beta/lib/core/StoryPanel/utils";
import { isEmptyString } from "@reearth/beta/utils/util";
import type { Page } from "@reearth/services/api/storytellingApi/utils";
import { useT } from "@reearth/services/i18n";
import { styled } from "@reearth/services/theme";
Expand Down Expand Up @@ -60,6 +61,7 @@ const ContentPage: React.FC<Props> = ({
renderItem={(storyPage, i) => {
const title = (getFieldValue(storyPage.property.items ?? [], "title", "title") ??
t("Untitled")) as string;
const hasEmptySpace = isEmptyString(title);
return (
<PageItemWrapper
key={storyPage.id}
Expand Down Expand Up @@ -99,7 +101,7 @@ const ContentPage: React.FC<Props> = ({
]}
/>
}>
{title}
{hasEmptySpace || !title ? t("Untitled") : title}
</ListItem>
</PageItemWrapper>
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { useMemo } from "react";

import Text from "@reearth/beta/components/Text";
import { isEmptyString } from "@reearth/beta/utils/util";
import { ValueTypes } from "@reearth/beta/utils/value";
import { useT } from "@reearth/services/i18n";
import { styled } from "@reearth/services/theme";
Expand All @@ -24,6 +25,7 @@ const TitleBlock: React.FC<Props> = ({ block, isSelected, ...props }) => {
() => property?.title?.color?.value as ValueTypes["string"],
[property?.title?.color?.value],
);
const hasEmptySpace = isEmptyString(title);

return (
<BlockWrapper
Expand All @@ -34,8 +36,8 @@ const TitleBlock: React.FC<Props> = ({ block, isSelected, ...props }) => {
property={property}
dndEnabled={false}
{...props}>
<Title size="h2" hasText={!!title} color={color} customColor>
{title ?? t("Untitled")}
<Title size="h2" hasText={!!title && !hasEmptySpace} color={color} customColor>
{hasEmptySpace || !title ? t("Untitled") : title}
</Title>
</BlockWrapper>
);
Expand Down
4 changes: 4 additions & 0 deletions web/src/beta/utils/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,7 @@ export function checkIfFileType(url: string, fileTypes: string) {

return regex.test(url);
}

export const isEmptyString = function (text: string): boolean {
return text === null || /^ *$/.test(text);
};

0 comments on commit 44e573f

Please sign in to comment.