Skip to content

Commit db51348

Browse files
committed
navbar improvements and refactored news
1 parent c4f4d44 commit db51348

File tree

6 files changed

+102
-65
lines changed

6 files changed

+102
-65
lines changed

src/components/Label.tsx

+2-7
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,9 @@ export interface LabelProps extends TagProps {
77
margin?: string;
88
}
99

10-
const Label = ({
11-
colorScheme = "violet",
12-
fontSize = "md",
13-
margin = "4px",
14-
children,
15-
}: LabelProps) => {
10+
const Label = ({ colorScheme = "violet", fontSize = "md", margin = "4px", children, ...props }: LabelProps) => {
1611
return (
17-
<Tag variant="solid" colorScheme={colorScheme}>
12+
<Tag variant="solid" colorScheme={colorScheme} {...props}>
1813
<Box fontSize={fontSize} margin={margin}>
1914
{children}
2015
</Box>

src/components/Logo.tsx

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { Text, Image } from "@chakra-ui/react";
2+
import { TopBarItem } from "@layout/TopBar/TopBarItem";
3+
import Link from "@component/Link";
4+
import Label from "./Label";
5+
6+
export const Logo = () => {
7+
return (
8+
<Link href="/" style={{ height: "100%", textDecoration: "none" }}>
9+
<TopBarItem paddingLeft={0} userSelect="none" pointerEvents="none">
10+
<Image height="35px" boxSize="35px" src="/images/header.png" alt="shibaac" />
11+
<Text fontSize="lg" color="white" ml="10px">
12+
Shibaac
13+
</Text>
14+
<Label fontSize="xs" margin="0" marginLeft={1}>
15+
Alpha
16+
</Label>
17+
</TopBarItem>
18+
</Link>
19+
);
20+
};

src/components/NewsCard.tsx

+65
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
import { Text, VStack, StackProps, HStack, Image, Heading } from "@chakra-ui/react";
2+
import { IoMdTime } from "react-icons/io";
3+
import { formatDate } from "@lib/.";
4+
import { HiNewspaper } from "react-icons/hi2";
5+
import { useColors } from "@hook/useColors";
6+
import sanitize from "sanitize-html";
7+
import Link from "./Link";
8+
9+
const maxChars = 180;
10+
11+
export interface NewsCardProps extends StackProps {
12+
header?: string;
13+
date?: string | null;
14+
html: string;
15+
id: string;
16+
image?: string;
17+
}
18+
19+
export const NewsCard = ({ date, html, header, image, id, ...props }: NewsCardProps) => {
20+
const { bgColor, textColor } = useColors();
21+
22+
return (
23+
<HStack color={textColor} bgColor={bgColor} gap={10} align="start" {...props}>
24+
<Link href={`/news/${id}`}>
25+
<Image
26+
src={image ?? "https://archive.org/download/placeholder-image/placeholder-image.jpg"}
27+
maxW="200px"
28+
alt="Placeholder"
29+
borderRadius="md"
30+
/>
31+
</Link>
32+
<VStack align="start" maxW="100%">
33+
<Heading size="md">{header}</Heading>
34+
<Text color="whiteAlpha.600" fontSize="xs">
35+
By author
36+
</Text>
37+
<Text
38+
w="full"
39+
maxW="100%"
40+
marginTop={2}
41+
overflowWrap="break-word"
42+
whiteSpace="normal"
43+
wordBreak="break-word"
44+
fontSize="sm"
45+
dangerouslySetInnerHTML={{ __html: sanitize(html.length > maxChars ? html.slice(0, maxChars) + "..." : html) }}
46+
/>
47+
</VStack>
48+
{/* <Flex bgColor={bgColor} borderBottomWidth="1px" borderTopWidth="1px" borderColor="#ddd" borderRadius={borderRadius}>
49+
<Grid margin="10px" width="100%" templateColumns="1fr auto">
50+
<Flex flexDirection="row" alignItems="center" gap="5px">
51+
<HiNewspaper />
52+
<Text color={textColor}>{header}</Text>
53+
</Flex>
54+
{date && (
55+
<Box display="flex" alignItems="center" justifyContent="flex-end">
56+
<IoMdTime />
57+
<Text>{formatDate(date)}</Text>
58+
</Box>
59+
)}
60+
</Grid>
61+
</Flex>
62+
<Box padding="10px">{isLoading ? <Loader /> : children}</Box> */}
63+
</HStack>
64+
);
65+
};

src/components/NewsPanel.tsx

-41
This file was deleted.

src/layout/TopBar/index.tsx

+3-10
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
import { Text, Image, HStack, Spacer } from "@chakra-ui/react";
1+
import { Text, HStack, Spacer } from "@chakra-ui/react";
22
import { TopBarItem } from "./TopBarItem";
33
import { trpc } from "@util/trpc";
44
import Link from "@component/Link";
55
import { TopBarSeparator } from "./TopBarSeparator";
66
import { FaDiscord, FaGithub } from "react-icons/fa";
77
import { TbBrandYoutubeFilled } from "react-icons/tb";
88
import DropdownButton from "@component/DropdownButton";
9-
import { useRouter } from "next/router";
109
import { DarkModeButton } from "@component/DarkModeButton";
1110
import { NavBar } from "@component/NavBar";
1211
import { IoIosSearch } from "react-icons/io";
12+
import { Logo } from "@component/Logo";
1313

1414
export interface NavigationItems {
1515
text: string;
@@ -47,14 +47,7 @@ export const TopBar = () => {
4747
return (
4848
<NavBar justifyContent="flex-start" paddingX="14em">
4949
<HStack>
50-
<Link href="/" style={{ height: "100%", textDecoration: "none" }}>
51-
<TopBarItem paddingLeft={0} userSelect="none" pointerEvents="none">
52-
<Image height="35px" boxSize="35px" src="/images/header.png" alt="shibaac" />
53-
<Text fontSize="lg" color="white" ml="10px">
54-
Shibaac
55-
</Text>
56-
</TopBarItem>
57-
</Link>
50+
<Logo />
5851
<DarkModeButton aria-label="Toggle Dark Mode" />
5952
<Link href="/character" title="Search Character" color="white" _hover={{ color: "violet.300" }}>
6053
<IoIosSearch size="25px" />

src/pages/index.tsx

+12-7
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
import sanitize from "sanitize-html";
2-
import NewsPanel from "../components/NewsPanel";
3-
import React from "react";
1+
import { NewsCard } from "../components/NewsCard";
42
import { trpc } from "@util/trpc";
53
import { Content } from "@component/Content";
4+
import { Heading } from "@chakra-ui/react";
65

76
export default function Index() {
87
const news = trpc.news.all.useQuery();
@@ -11,11 +10,17 @@ export default function Index() {
1110

1211
return (
1312
<Content>
14-
<Content.Body>
13+
<Content.Body maxW="unset" gap={5}>
14+
<Heading size="lg">News</Heading>
1515
{news.data?.map((post) => (
16-
<NewsPanel borderRadius="none" key={`news-${post.id}`} header={post.title} date={post.createdAt}>
17-
<div dangerouslySetInnerHTML={{ __html: sanitize(post.content) }} />
18-
</NewsPanel>
16+
<NewsCard
17+
key={`news-${post.id}`}
18+
id={String(post.id)}
19+
image={post.imageUrl ?? undefined}
20+
header={post.title}
21+
date={post.createdAt}
22+
html={post.content}
23+
/>
1924
))}
2025
</Content.Body>
2126
</Content>

0 commit comments

Comments
 (0)