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

Replace richtextblock with plain string component #861

Merged
merged 2 commits into from
Nov 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import { CustomerCaseSection as CustomerCaseSectionObject } from "studioShared/l
import ImageSection from "./image/ImageSection";
import QuoteBlock from "./quote/QuoteBlock";
import ResultsBlock from "./results/ResultsBlock";
import RichTextSection from "./richText/RichTextSection";
import SplitSection from "./splitSection/SplitSection";
import TextSection from "./text/TextSection";

export function CustomerCaseSection({
section,
Expand All @@ -14,8 +14,8 @@ export function CustomerCaseSection({
switch (section._type) {
case "splitSection":
return <SplitSection section={section} />;
case "richTextBlock":
return <RichTextSection section={section} />;
case "textBlock":
return <TextSection section={section} />;
case "quoteBlock":
return <QuoteBlock section={section} />;
case "imageBlock":
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import Text from "src/components/text/Text";
import { TextBlock } from "studioShared/lib/interfaces/textBlock";

import styles from "./textSection.module.css";

export interface TextSectionProps {
section: TextBlock;
}

export default function TextSection({ section }: TextSectionProps) {
return (
<div className={styles.wrapper}>
<div
className={
styles.content + (section.highlighted ? ` ${styles.highlighted}` : "")
}
>
<div className={styles.innerContent}>
<Text>{section.text}</Text>
</div>
</div>
</div>
);
}
2 changes: 1 addition & 1 deletion src/components/navigation/header/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ export const Header = ({

const showAnnouncement =
announcement !== null &&
announcement.text.length > 0 &&
announcement.text?.length > 0 &&
(!announcement.hideAfter || new Date(announcement.hideAfter) > new Date());

return (
Expand Down
2 changes: 1 addition & 1 deletion studio/utils/preview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
isPortableTextTextBlock,
} from "sanity";

// Convert rich text content to plaintext preview string
// This help method convert rich text content to plaintext so it could be used as preview in sanity studio
// (inspired by https://www.sanity.io/docs/previewing-block-content)
export function richTextPreview(
richText: PortableTextBlock[],
Expand Down
4 changes: 2 additions & 2 deletions studioShared/lib/interfaces/customerCases.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import { IImage } from "studio/lib/interfaces/media";
import { ImageBlock } from "./imageBlock";
import { QuoteBlock } from "./quoteBlock";
import { ResultsBlock } from "./resultsBlock";
import { RichTextBlock } from "./richTextBlock";
import { SplitSection } from "./splitSection";
import { TextBlock } from "./textBlock";

export interface CustomerCaseProjectInfo {
customer: string;
Expand All @@ -29,7 +29,7 @@ export interface CustomerCaseBase {
image: IImage;
}

export type BaseCustomerCaseSection = RichTextBlock | ImageBlock | QuoteBlock;
export type BaseCustomerCaseSection = TextBlock | ImageBlock | QuoteBlock;

export type CustomerCaseSection =
| BaseCustomerCaseSection
Expand Down
8 changes: 0 additions & 8 deletions studioShared/lib/interfaces/richTextBlock.ts

This file was deleted.

6 changes: 6 additions & 0 deletions studioShared/lib/interfaces/textBlock.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export interface TextBlock {
_key: string;
_type: "textBlock";
text: string;
highlighted?: boolean;
}
4 changes: 2 additions & 2 deletions studioShared/lib/queries/customerCases.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ export const CUSTOMER_CASES_QUERY = groq`
`;

export const BASE_SECTIONS_FRAGMENT = groq`
_type == "richTextBlock" => {
"richText": ${translatedFieldFragment("richText")},
_type == "textBlock" => {
"text": ${translatedFieldFragment("text")},
highlighted
},
_type == "imageBlock" => {
Expand Down
51 changes: 0 additions & 51 deletions studioShared/schemas/objects/richTextBlock.ts

This file was deleted.

2 changes: 1 addition & 1 deletion studioShared/schemas/objects/sections.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import imageBlock from "./imageBlock";
import listBlock from "./listBlock";
import quoteBlock from "./quoteBlock";
import richTextBlock from "./richTextBlock";
import richTextBlock from "./textBlock";

export const baseCustomerCaseSections = [
richTextBlock,
Expand Down
40 changes: 40 additions & 0 deletions studioShared/schemas/objects/textBlock.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { defineField } from "sanity";

import { firstTranslation } from "studio/utils/i18n";

const textBlock = defineField({
name: "textBlock",
title: "Text Block",
type: "object",
fields: [
{
name: "text",
title: "Text",
type: "internationalizedArrayText",
},
{
name: "highlighted",
title: "Highlighted",
type: "boolean",
description: "Display the text with a highlight frame",
initialValue: false,
},
],
preview: {
select: {
text: "text",
highlighted: "highlighted",
},
prepare({ text, highlighted }) {
return {
title: firstTranslation(text) ?? undefined,
subtitle:
typeof highlighted === "boolean" && highlighted
? "Highlighted"
: undefined,
};
},
},
});

export default textBlock;