Skip to content

Commit

Permalink
navbar improvements and refactored news
Browse files Browse the repository at this point in the history
  • Loading branch information
nekiro committed Dec 26, 2024
1 parent c4f4d44 commit db51348
Show file tree
Hide file tree
Showing 6 changed files with 102 additions and 65 deletions.
9 changes: 2 additions & 7 deletions src/components/Label.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,9 @@ export interface LabelProps extends TagProps {
margin?: string;
}

const Label = ({
colorScheme = "violet",
fontSize = "md",
margin = "4px",
children,
}: LabelProps) => {
const Label = ({ colorScheme = "violet", fontSize = "md", margin = "4px", children, ...props }: LabelProps) => {
return (
<Tag variant="solid" colorScheme={colorScheme}>
<Tag variant="solid" colorScheme={colorScheme} {...props}>
<Box fontSize={fontSize} margin={margin}>
{children}
</Box>
Expand Down
20 changes: 20 additions & 0 deletions src/components/Logo.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { Text, Image } from "@chakra-ui/react";
import { TopBarItem } from "@layout/TopBar/TopBarItem";
import Link from "@component/Link";
import Label from "./Label";

export const Logo = () => {
return (
<Link href="/" style={{ height: "100%", textDecoration: "none" }}>
<TopBarItem paddingLeft={0} userSelect="none" pointerEvents="none">
<Image height="35px" boxSize="35px" src="/images/header.png" alt="shibaac" />
<Text fontSize="lg" color="white" ml="10px">
Shibaac
</Text>
<Label fontSize="xs" margin="0" marginLeft={1}>
Alpha
</Label>
</TopBarItem>
</Link>
);
};
65 changes: 65 additions & 0 deletions src/components/NewsCard.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import { Text, VStack, StackProps, HStack, Image, Heading } from "@chakra-ui/react";
import { IoMdTime } from "react-icons/io";
import { formatDate } from "@lib/.";
import { HiNewspaper } from "react-icons/hi2";
import { useColors } from "@hook/useColors";
import sanitize from "sanitize-html";
import Link from "./Link";

const maxChars = 180;

export interface NewsCardProps extends StackProps {
header?: string;
date?: string | null;
html: string;
id: string;
image?: string;
}

export const NewsCard = ({ date, html, header, image, id, ...props }: NewsCardProps) => {
const { bgColor, textColor } = useColors();

return (
<HStack color={textColor} bgColor={bgColor} gap={10} align="start" {...props}>
<Link href={`/news/${id}`}>
<Image
src={image ?? "https://archive.org/download/placeholder-image/placeholder-image.jpg"}
maxW="200px"
alt="Placeholder"
borderRadius="md"
/>
</Link>
<VStack align="start" maxW="100%">
<Heading size="md">{header}</Heading>
<Text color="whiteAlpha.600" fontSize="xs">
By author
</Text>
<Text
w="full"
maxW="100%"
marginTop={2}
overflowWrap="break-word"
whiteSpace="normal"
wordBreak="break-word"
fontSize="sm"
dangerouslySetInnerHTML={{ __html: sanitize(html.length > maxChars ? html.slice(0, maxChars) + "..." : html) }}
/>
</VStack>
{/* <Flex bgColor={bgColor} 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 color={textColor}>{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> */}
</HStack>
);
};
41 changes: 0 additions & 41 deletions src/components/NewsPanel.tsx

This file was deleted.

13 changes: 3 additions & 10 deletions src/layout/TopBar/index.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { Text, Image, HStack, Spacer } from "@chakra-ui/react";
import { Text, HStack, Spacer } from "@chakra-ui/react";
import { TopBarItem } from "./TopBarItem";
import { trpc } from "@util/trpc";
import Link from "@component/Link";
import { TopBarSeparator } from "./TopBarSeparator";
import { FaDiscord, FaGithub } from "react-icons/fa";
import { TbBrandYoutubeFilled } from "react-icons/tb";
import DropdownButton from "@component/DropdownButton";
import { useRouter } from "next/router";
import { DarkModeButton } from "@component/DarkModeButton";
import { NavBar } from "@component/NavBar";
import { IoIosSearch } from "react-icons/io";
import { Logo } from "@component/Logo";

export interface NavigationItems {
text: string;
Expand Down Expand Up @@ -47,14 +47,7 @@ export const TopBar = () => {
return (
<NavBar justifyContent="flex-start" paddingX="14em">
<HStack>
<Link href="/" style={{ height: "100%", textDecoration: "none" }}>
<TopBarItem paddingLeft={0} userSelect="none" pointerEvents="none">
<Image height="35px" boxSize="35px" src="/images/header.png" alt="shibaac" />
<Text fontSize="lg" color="white" ml="10px">
Shibaac
</Text>
</TopBarItem>
</Link>
<Logo />
<DarkModeButton aria-label="Toggle Dark Mode" />
<Link href="/character" title="Search Character" color="white" _hover={{ color: "violet.300" }}>
<IoIosSearch size="25px" />
Expand Down
19 changes: 12 additions & 7 deletions src/pages/index.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import sanitize from "sanitize-html";
import NewsPanel from "../components/NewsPanel";
import React from "react";
import { NewsCard } from "../components/NewsCard";
import { trpc } from "@util/trpc";
import { Content } from "@component/Content";
import { Heading } from "@chakra-ui/react";

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

return (
<Content>
<Content.Body>
<Content.Body maxW="unset" gap={5}>
<Heading size="lg">News</Heading>
{news.data?.map((post) => (
<NewsPanel borderRadius="none" key={`news-${post.id}`} header={post.title} date={post.createdAt}>
<div dangerouslySetInnerHTML={{ __html: sanitize(post.content) }} />
</NewsPanel>
<NewsCard
key={`news-${post.id}`}
id={String(post.id)}
image={post.imageUrl ?? undefined}
header={post.title}
date={post.createdAt}
html={post.content}
/>
))}
</Content.Body>
</Content>
Expand Down

0 comments on commit db51348

Please sign in to comment.