From b88ad4e20764f993636ce33b103596e8d27addd1 Mon Sep 17 00:00:00 2001 From: TZGyn Date: Thu, 19 Oct 2023 12:37:11 +0800 Subject: [PATCH] Frontend added layout for each page --- react-frontend/src/App.tsx | 40 ++++++++++++++------------ react-frontend/src/main.tsx | 5 +++- react-frontend/src/pages/Layout.tsx | 14 +++++++++ react-frontend/src/pages/dashboard.tsx | 10 ++----- 4 files changed, 42 insertions(+), 27 deletions(-) create mode 100644 react-frontend/src/pages/Layout.tsx diff --git a/react-frontend/src/App.tsx b/react-frontend/src/App.tsx index 10ffd73..f082ce1 100644 --- a/react-frontend/src/App.tsx +++ b/react-frontend/src/App.tsx @@ -1,5 +1,4 @@ import { ModeToggle } from '@/components/mode-toggle' -import { ThemeProvider } from '@/components/theme-provider' import { Dialog, DialogContent, @@ -29,11 +28,12 @@ import { DropdownMenuSeparator, DropdownMenuTrigger, } from '@/components/ui/dropdown-menu' +import { Avatar, AvatarFallback, AvatarImage } from '@/components/ui/avatar' import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card' import { Toaster } from '@/components/ui/toaster' import { useToast } from '@/components/ui/use-toast' -import { Copy, Loader2, MoreHorizontal, Settings } from 'lucide-react' +import { Copy, Loader2, MoreHorizontal, Settings, User } from 'lucide-react' import { useEffect, useState } from 'react' import { useNavigate } from 'react-router-dom' @@ -71,28 +71,22 @@ export default function App() { }, []) return ( - - + <>
-
+ ) } -export const Navbar = ({ - getShorteners, -}: { - getShorteners?: () => Promise -}) => { +export const Navbar = () => { const navigate = useNavigate() return (
@@ -103,10 +97,13 @@ export const Navbar = ({ Shortener
- {getShorteners && ( - - )} + + + + + +
@@ -188,9 +185,11 @@ const CreateShortener = ({ const ShortenerTable = ({ shorteners, isLoading, + getShorteners, }: { shorteners: Shortener[] isLoading: boolean + getShorteners: () => Promise }) => { const { toast } = useToast() const copyLinkToClipboard = async (code: string) => { @@ -204,9 +203,14 @@ const ShortenerTable = ({ return ( - -
Shorteners
- {isLoading && } + +
+
Shorteners
+ {isLoading && ( + + )} +
+
diff --git a/react-frontend/src/main.tsx b/react-frontend/src/main.tsx index dd9f1fd..2226c88 100644 --- a/react-frontend/src/main.tsx +++ b/react-frontend/src/main.tsx @@ -4,12 +4,15 @@ import App from './App.tsx' import './index.css' import { BrowserRouter, Routes, Route, Navigate } from 'react-router-dom' import Dashboard from './pages/dashboard.tsx' +import { Layout } from './pages/Layout.tsx' ReactDOM.createRoot(document.getElementById('root')!).render( - + }> }> diff --git a/react-frontend/src/pages/Layout.tsx b/react-frontend/src/pages/Layout.tsx new file mode 100644 index 0000000..327d63a --- /dev/null +++ b/react-frontend/src/pages/Layout.tsx @@ -0,0 +1,14 @@ +import { ThemeProvider } from '@/components/theme-provider' +import { Navbar } from '@/App.tsx' +import { Outlet } from 'react-router-dom' + +export function Layout() { + return ( + + + + + ) +} diff --git a/react-frontend/src/pages/dashboard.tsx b/react-frontend/src/pages/dashboard.tsx index 31ce636..23be6c8 100644 --- a/react-frontend/src/pages/dashboard.tsx +++ b/react-frontend/src/pages/dashboard.tsx @@ -1,10 +1,7 @@ -import { Navbar } from '@/App' -import { ThemeProvider } from '@/components/theme-provider' import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card' import { Table, TableBody, - TableCaption, TableCell, TableHead, TableHeader, @@ -131,10 +128,7 @@ export default function Dashboard() { } return ( - - + <>
@@ -241,7 +235,7 @@ export default function Dashboard() {
- + ) }