diff --git a/apps/client/src/components/AuthWrapper.tsx b/apps/client/src/components/AuthWrapper.tsx new file mode 100644 index 0000000..b695306 --- /dev/null +++ b/apps/client/src/components/AuthWrapper.tsx @@ -0,0 +1,17 @@ +import { ReactNode } from "react"; +import { useGlobalContext } from "@/contexts/GlobalContext"; + +interface AuthWrapperProps { + children?: ReactNode; + fallback?: ReactNode; +} + +export const AuthWrapper = ({ children, fallback }: AuthWrapperProps) => { + const { isLoggedIn } = useGlobalContext(); + + if (!isLoggedIn) { + return fallback ?? null; + } + + return <>{children}; +}; diff --git a/apps/client/src/components/Avatar.tsx b/apps/client/src/components/Avatar.tsx index e372600..01dfc91 100644 --- a/apps/client/src/components/Avatar.tsx +++ b/apps/client/src/components/Avatar.tsx @@ -59,18 +59,17 @@ export const Avatar: FC = ({ className, ...props }) => { - const fallbackBackground = hasRandomBackground - ? RandomBackgroundColors[ - Math.floor(Math.random() * RandomBackgroundColors.length) - ] - : "bg-muted"; + const fallbackBackground = + hasRandomBackground && username + ? RandomBackgroundColors[ + username.charCodeAt(0) % RandomBackgroundColors.length + ] + : "bg-base-muted"; return ( - - {username?.[0].toLocaleUpperCase() || ""} - + ); }; diff --git a/apps/client/src/components/Content.tsx b/apps/client/src/components/Content.tsx index 411698e..5172cd6 100644 --- a/apps/client/src/components/Content.tsx +++ b/apps/client/src/components/Content.tsx @@ -1,27 +1,113 @@ // import "katex/dist/katex.min.css" -import { detectFormat, Format } from "@/lib/format" -import type { FC } from "react" -import Latex from "react-latex-next" -import ReactMarkdown from "react-markdown" -import rehypeHighlight from "rehype-highlight" -import remarkGfm from "remark-gfm" +import { detectFormat, Format } from "@/lib/format"; +import { cn } from "@/lib/utils"; +import type { FC } from "react"; +import Latex from "react-latex-next"; +import ReactMarkdown from "react-markdown"; +import rehypeHighlight from "rehype-highlight"; +import remarkGfm from "remark-gfm"; export const Content: FC<{ content: string }> = ({ content }) => { switch (detectFormat(content)) { case Format.Markdown: return ( -
+
( +

+ {children} +

+ ), + h2: ({ children, className }) => ( +

+ {children} +

+ ), + h3: ({ children, className }) => ( +

+ {children} +

+ ), + h4: ({ children, className }) => ( +

+ {children} +

+ ), + h5: ({ children, className }) => ( +
+ {children} +
+ ), + h6: ({ children, className }) => ( +
+ {children} +
+ ), + strong: ({ children, className }) => ( + + {children} + + ), + em: ({ children, className }) => ( + + {children} + + ), + code: ({ children, className }) => ( + + {children} + + ), + blockquote: ({ children, className }) => ( +
+ {children} +
+ ), + ul: ({ children, className }) => ( +
    + {children} +
+ ), + ol: ({ children, className }) => ( +
    + {children} +
+ ), + p: ({ children, className }) => ( +

+ {children} +

+ ), + a: ({ children, href, className }) => ( + + {children} + + ), + span: ({ children, className }) => ( + + {children} + + ), + div: ({ children, className }) => ( +
+ {children} +
+ ), + }} > {content}
- ) + ); case Format.Latex: - return {content} + return {content}; case Format.Raw: - return content + return content; } -} +}; diff --git a/apps/client/src/components/Header.tsx b/apps/client/src/components/Header.tsx index f3491c0..f826b9a 100644 --- a/apps/client/src/components/Header.tsx +++ b/apps/client/src/components/Header.tsx @@ -12,13 +12,13 @@ import { LeftSidebar } from "@/components/LeftSidebar"; const DesktopNav = () => { return ( -
+

- + PSE - + forum

@@ -48,7 +48,7 @@ const MobileNav = () => { />
@@ -56,10 +56,10 @@ const MobileNav = () => {

- + PSE - + forum

@@ -99,7 +99,7 @@ const MobileNav = () => { export function Header() { return ( -