From 7601bf0c9c80a8260efad37024ba2a31e29d1272 Mon Sep 17 00:00:00 2001 From: Hsu Zhong Jun <27919917+dcshzj@users.noreply.github.com> Date: Thu, 14 Sep 2023 15:36:34 +0800 Subject: [PATCH] feat(announcements): introduce preview component --- src/layouts/EditHomepage/HomepagePreview.tsx | 14 ++ .../homepage/AnnouncementsSection.tsx | 170 ++++++++++++++++++ 2 files changed, 184 insertions(+) create mode 100644 src/templates/homepage/AnnouncementsSection.tsx diff --git a/src/layouts/EditHomepage/HomepagePreview.tsx b/src/layouts/EditHomepage/HomepagePreview.tsx index aaf4017455..bb86e43de8 100644 --- a/src/layouts/EditHomepage/HomepagePreview.tsx +++ b/src/layouts/EditHomepage/HomepagePreview.tsx @@ -5,6 +5,7 @@ import { useParams } from "react-router-dom" import editorStyles from "styles/isomer-cms/pages/Editor.module.scss" +import { TemplateAnnouncementsSection } from "templates/homepage/AnnouncementsSection" import TemplateHeroSection from "templates/homepage/HeroSection" import TemplateInfobarSection from "templates/homepage/InfobarSection" import TemplateInfopicLeftSection from "templates/homepage/InfopicLeftSection" @@ -166,6 +167,19 @@ export const HomepagePreview = ({ )} )} + {/* Announcements section */} + {EditorHomepageFrontmatterSection.isAnnouncements(section) && ( + <> + } + /> + + )} ))} diff --git a/src/templates/homepage/AnnouncementsSection.tsx b/src/templates/homepage/AnnouncementsSection.tsx new file mode 100644 index 0000000000..bf1e562535 --- /dev/null +++ b/src/templates/homepage/AnnouncementsSection.tsx @@ -0,0 +1,170 @@ +import { forwardRef } from "react" + +import editorStyles from "styles/isomer-cms/pages/Editor.module.scss" + +import { getClassNames } from "templates/utils/stylingUtils" + +import { AnnouncementsSection } from "types/homepage" + +type TemplateAnnouncementsSectionProps = Omit< + AnnouncementsSection, + "announcement_items" +> & { + announcementItems: AnnouncementsSection["announcement_items"] + sectionIndex: number +} + +export const TemplateAnnouncementsSection = forwardRef< + HTMLDivElement, + TemplateAnnouncementsSectionProps +>( + ( + { + title, + subtitle, + announcementItems, + sectionIndex, + }: TemplateAnnouncementsSectionProps, + ref + ) => { + return ( +
+
+
+
+
+ <> + {subtitle && ( +

+ {subtitle} +

+ )} + {title && ( +

+ {title} +

+ )} + +
+ + {announcementItems && + announcementItems.map((announcement, index) => { + return ( + <> +
+
+

+ {announcement.title} +

+

+ {announcement.date} +

+
+
+

{announcement.announcement}

+ {announcement.link_text && announcement.link_url && ( +
+
+ {announcement.link_text} +
+
+ )} +
+
+ {announcementItems && + announcementItems.length === index + 1 ? ( +
+ ) : ( +
+ )} + + ) + })} + +
+
+
+
+
+ ) + } +)