-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
68 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import React, { ReactNode } from "react"; | ||
import Loader from "./Loader"; | ||
import { Flex, Box, Text, Grid, FlexProps } from "@chakra-ui/react"; | ||
import { IoMdTime } from "react-icons/io"; | ||
import { formatDate } from "@lib/."; | ||
import { HiNewspaper } from "react-icons/hi2"; | ||
|
||
export interface NewsPanelProps extends FlexProps { | ||
header?: string; | ||
date?: string | null; | ||
identifier?: string | null; | ||
children?: ReactNode; | ||
isLoading?: boolean; | ||
} | ||
|
||
const NewsPanel = ({ header = "Loading...", date, identifier, children, isLoading = false, borderRadius = "md", ...props }: NewsPanelProps) => { | ||
return ( | ||
<Flex key={identifier} width="100%" flexDirection="column" color="black" bgColor="#fff" borderRadius={borderRadius} {...props}> | ||
<Flex bg="#f5f5f5" borderBottomWidth="1px" borderTopWidth="1px" borderColor="#ddd" borderRadius={borderRadius}> | ||
<Grid margin="10px" width="100%" templateColumns="1fr auto"> | ||
<Flex flexDirection="row" alignItems="center" gap="5px"> | ||
<HiNewspaper /> | ||
<Text>{header}</Text> | ||
</Flex> | ||
{date && ( | ||
<Box display="flex" alignItems="center" justifyContent="flex-end"> | ||
<IoMdTime /> | ||
<Text>{formatDate(date)}</Text> | ||
</Box> | ||
)} | ||
</Grid> | ||
</Flex> | ||
<Box padding="10px">{isLoading ? <Loader /> : children}</Box> | ||
</Flex> | ||
); | ||
}; | ||
|
||
export default NewsPanel; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,21 @@ | ||
import sanitize from "sanitize-html"; | ||
import Panel from "../components/Panel"; | ||
import NewsPanel from "../components/NewsPanel"; | ||
import React from "react"; | ||
import { trpc } from "@util/trpc"; | ||
import { Flex } from "@chakra-ui/react"; | ||
|
||
export default function Index() { | ||
const news = trpc.news.all.useQuery(); | ||
|
||
if (!news.data || news.error) { | ||
if (news.error) { | ||
// TODO: properly handle errors | ||
console.error(news.error); | ||
} | ||
return <Panel isLoading={true} />; | ||
} | ||
|
||
// TODO: paginate? | ||
|
||
return ( | ||
<> | ||
{news.data.map((post) => ( | ||
<Panel key={`news-${post.id}`} header={post.title} date={post.createdAt}> | ||
<Flex flexDir="column" gap="10px"> | ||
{news.data?.map((post) => ( | ||
<NewsPanel borderRadius="none" key={`news-${post.id}`} header={post.title} date={post.createdAt}> | ||
<div dangerouslySetInnerHTML={{ __html: sanitize(post.content) }} /> | ||
</Panel> | ||
</NewsPanel> | ||
))} | ||
</> | ||
</Flex> | ||
); | ||
} |