Skip to content

Commit

Permalink
replace richtextblock with plain string component
Browse files Browse the repository at this point in the history
  • Loading branch information
anemne committed Nov 5, 2024
1 parent b6d8f9b commit dcabe0c
Show file tree
Hide file tree
Showing 13 changed files with 79 additions and 112 deletions.
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
20 changes: 0 additions & 20 deletions studio/utils/preview.ts

This file was deleted.

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;

0 comments on commit dcabe0c

Please sign in to comment.