From 779014c1d943ebbe5a2653d475f30bd61e606680 Mon Sep 17 00:00:00 2001 From: debater-coder <52619668+debater-coder@users.noreply.github.com> Date: Tue, 26 Sep 2023 09:03:13 +1000 Subject: [PATCH] feat: amalgamate publications into notices --- apps/client/package.json | 2 +- .../src/consumers/timetablCms/schemas.ts | 59 --------- .../consumers/timetablCms/useTimetablNews.ts | 40 ------ .../Main/Announcements/Announcements.tsx | 119 ++++++------------ .../routes/Main/Publications/Publications.tsx | 13 -- .../src/routes/Main/Publications/index.ts | 1 - apps/client/src/services/AppRouter/pages.tsx | 13 +- 7 files changed, 41 insertions(+), 206 deletions(-) delete mode 100644 apps/client/src/consumers/timetablCms/schemas.ts delete mode 100644 apps/client/src/consumers/timetablCms/useTimetablNews.ts delete mode 100644 apps/client/src/routes/Main/Publications/Publications.tsx delete mode 100644 apps/client/src/routes/Main/Publications/index.ts diff --git a/apps/client/package.json b/apps/client/package.json index a791594..ba1e664 100644 --- a/apps/client/package.json +++ b/apps/client/package.json @@ -1,6 +1,6 @@ { "name": "client", - "version": "1.9.0-beta", + "version": "1.9.1-beta", "scripts": { "dev": "npm-run-all --parallel dev:*", "dev:run": "FORCE_COLOR=1 vite", diff --git a/apps/client/src/consumers/timetablCms/schemas.ts b/apps/client/src/consumers/timetablCms/schemas.ts deleted file mode 100644 index 80290ed..0000000 --- a/apps/client/src/consumers/timetablCms/schemas.ts +++ /dev/null @@ -1,59 +0,0 @@ -import { NoticeYear } from "../sbhsApi/schemas"; -import { z } from "zod"; - -export const timetablNewsSchema = z - .object({ - data: z.array( - z.object({ - attributes: z.object({ - title: z.string(), - content: z.string(), - createdAt: z.string(), - createdBy: z.object({ - data: z.object({ - attributes: z.object({ - firstname: z.string(), - lastname: z.string(), - }), - }), - }), - }), - }) - ), - }) - .transform((data) => { - const transformed = data.data.map((announcement) => ({ - years: [ - NoticeYear.YEAR7, - NoticeYear.YEAR8, - NoticeYear.YEAR9, - NoticeYear.YEAR10, - NoticeYear.YEAR11, - NoticeYear.YEAR12, - NoticeYear.STAFF, - ], - title: announcement.attributes.title, - content: announcement.attributes.content, - authorName: - announcement.attributes.createdBy.data.attributes.firstname + - " " + - announcement.attributes.createdBy.data.attributes.lastname, - date: announcement.attributes.createdAt, - })); - - return transformed; - }); - -// type TimetablNotice = { -// years: NoticeYear[]; -// title: string; -// content: string; -// dates: string[]; -// relativeWeight: number; -// isMeeting: boolean; -// meetingDate?: string | undefined; -// meetingTimeParsed?: string | undefined; -// meetingTime?: string | undefined; -// displayYears?: string | undefined; -// authorName?: string | undefined; -// } diff --git a/apps/client/src/consumers/timetablCms/useTimetablNews.ts b/apps/client/src/consumers/timetablCms/useTimetablNews.ts deleted file mode 100644 index 6d06ed0..0000000 --- a/apps/client/src/consumers/timetablCms/useTimetablNews.ts +++ /dev/null @@ -1,40 +0,0 @@ -import HTTPError from "../../errors/HTTPError"; -import NetworkError from "../../errors/NetworkError"; -import { timetablNewsSchema } from "./schemas"; -import { useQuery } from "@tanstack/react-query"; - -export const fetchTimetablNews = async () => { - let res; - try { - res = await fetch( - "https://cms.timetabl.app/api/announcements?populate[0]=createdBy&sort=id:desc" - ); - } catch (error) { - if (error instanceof TypeError) { - throw new NetworkError(error.message); - } else { - throw error; - } - } - if (!res.ok) { - throw new HTTPError(res.status); - } - - return res.json(); -}; - -const queryFn = async () => { - return timetablNewsSchema.parse(await fetchTimetablNews()); -}; - -const getQueryKey = () => ["/cms/news"]; - -export const useTimetablNews = () => { - return useQuery({ - queryKey: getQueryKey(), - queryFn, - }); -}; - -useTimetablNews.getQueryKey = getQueryKey; -useTimetablNews.queryFn = queryFn; diff --git a/apps/client/src/routes/Main/Announcements/Announcements.tsx b/apps/client/src/routes/Main/Announcements/Announcements.tsx index b77ac83..baa0f97 100644 --- a/apps/client/src/routes/Main/Announcements/Announcements.tsx +++ b/apps/client/src/routes/Main/Announcements/Announcements.tsx @@ -1,6 +1,5 @@ import Empty from "../../../components/Empty"; import { NoticeYear, TimetablNotice } from "../../../consumers/sbhsApi/schemas"; -// import { useTimetablNews } from "../../../services/timetablCms/useTimetablNews"; import { useDailyNotices } from "../../../consumers/sbhsApi/useDailyNotices"; import { Search2Icon } from "@chakra-ui/icons"; import { @@ -10,11 +9,6 @@ import { Flex, Heading, Skeleton, - Tab, - TabList, - TabPanel, - TabPanels, - Tabs, useDisclosure, Text, Input, @@ -25,12 +19,15 @@ import { FormLabel, Highlight, FormControl, + Alert, + AlertDescription, + AlertTitle, + Box, } from "@chakra-ui/react"; import { Prose } from "@nikolovlazar/chakra-ui-prose"; import DOMPurify from "dompurify"; import linkifyHtml from "linkify-html"; import { DateTime } from "luxon"; -import { micromark } from "micromark"; import { MegaphoneSimple } from "phosphor-react"; import { useState } from "react"; import { create } from "zustand"; @@ -74,14 +71,12 @@ function Announcement({ authorName, date, query, - markdown, }: { title: string; content: string; authorName?: string; date?: string; query: string; - markdown?: boolean; }) { const { isOpen, onToggle } = useDisclosure(); const [showShowMoreBtn, setShowShowMoreBtn] = useState(true); @@ -100,15 +95,12 @@ function Announcement({
- setShowShowMoreBtn((content?.offsetHeight ?? 0 / 24) > 1) + setShowShowMoreBtn((content?.offsetHeight ?? 0) / 24 > 1) } dangerouslySetInnerHTML={{ - __html: linkifyHtml( - DOMPurify.sanitize(markdown ? micromark(content) : content), - { - defaultProtocol: "https", - } - ), + __html: linkifyHtml(DOMPurify.sanitize(content), { + defaultProtocol: "https", + }), }} /> @@ -138,44 +130,22 @@ function Announcement({ function DailyNotices({ filter, query, - tab, dailyNoticesLoading, - timetablNewsLoading, dailyNotices, - timetablNews, }: { filter: NoticeYear; query: string; - tab: number; - timetablNewsLoading: boolean; dailyNoticesLoading: boolean; dailyNotices?: TimetablNotice[]; - timetablNews?: TimetablNotice[]; }) { - const notices = filterNotices( - tab ? timetablNews : dailyNotices, - filter, - query - ); + const notices = filterNotices(dailyNotices, filter, query); return ( - + {notices?.length ? ( notices?.map((notice, index) => { - return ( - - ); + return ; }) ) : ( { - setTabIndex(index); - }; - const [query, setQuery] = useState(""); + const [isDownloading, setIsDownloading] = useState(false); return ( - - + + + + + Read the latest edition of the High Notes + + + + + + + setQuery(event.target.value)} @@ -247,32 +226,12 @@ export default function Announcements() { - - - Daily Notices - Timetabl News - - - {[0, 1].map((tab) => ( - - - - ))} - - + ); } diff --git a/apps/client/src/routes/Main/Publications/Publications.tsx b/apps/client/src/routes/Main/Publications/Publications.tsx deleted file mode 100644 index f908068..0000000 --- a/apps/client/src/routes/Main/Publications/Publications.tsx +++ /dev/null @@ -1,13 +0,0 @@ -import PdfViewer from "../../../components/PdfViewer"; -import { Heading } from "@chakra-ui/react"; - -export default function Publications() { - return ( - <> - - Latest High Notes - - - - ); -} diff --git a/apps/client/src/routes/Main/Publications/index.ts b/apps/client/src/routes/Main/Publications/index.ts deleted file mode 100644 index adf3469..0000000 --- a/apps/client/src/routes/Main/Publications/index.ts +++ /dev/null @@ -1 +0,0 @@ -export { default } from "./Publications"; diff --git a/apps/client/src/services/AppRouter/pages.tsx b/apps/client/src/services/AppRouter/pages.tsx index e514141..af9dd77 100644 --- a/apps/client/src/services/AppRouter/pages.tsx +++ b/apps/client/src/services/AppRouter/pages.tsx @@ -1,7 +1,6 @@ import SpinnerSuspense from "../../components/SpinnerSuspense"; import { Barcode, - BookBookmark, ChatsTeardrop, House, IconWeight, @@ -88,17 +87,7 @@ export const pages: { pinned: TimetablPage[]; unpinned: TimetablPage[] } = { mirrored: false, element: , }, - { - path: "publications", - name: "Publications", - icon: BookBookmark, - mirrored: false, - element: ( - import("../../routes/Main/Publications"))} - /> - ), - }, + { path: "feedback", name: "Feedback",