-
Notifications
You must be signed in to change notification settings - Fork 356
feat: Redesign header, sidebar, and implement routing setup with theme integration #1339
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
238c3b6
255ee19
ca46cf9
0854801
23e9e22
ec09a84
c692062
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
| @@ -1,59 +1,40 @@ | ||||||||
| import { BrowserRouter, Routes, Route } from 'react-router-dom'; | ||||||||
| import MuiThemeProvider from './shared/components/molecules/theme'; | ||||||||
| import A2ZNotifications from './shared/components/molecules/notification'; | ||||||||
| import Navbar from './shared/components/organisms/navbar'; | ||||||||
| import { memo, useEffect, useState, useMemo } from 'react'; | ||||||||
| import { Provider } from 'jotai'; | ||||||||
| import { setupTokenRefresh } from './shared/utils/api-interceptor'; | ||||||||
| import { useEffect } from 'react'; | ||||||||
| import Home from './modules/home'; | ||||||||
| import UserAuthForm from './modules/user-auth-form'; | ||||||||
| import Editor from './modules/editor'; | ||||||||
| import PageNotFound from './modules/404'; | ||||||||
| import Search from './modules/search'; | ||||||||
| import Profile from './modules/profile'; | ||||||||
| import Project from './modules/project'; | ||||||||
| import Sidebar from './shared/components/organisms/sidebar'; | ||||||||
| import ChangePassword from './modules/change-password'; | ||||||||
| import ManageProjects from './modules/manage-projects'; | ||||||||
| import EditProfile from './modules/edit-profile'; | ||||||||
| import Notifications from './modules/notification'; | ||||||||
| import { AppUnProtectedRoutes } from './modules/app/routes'; | ||||||||
| import { AppProtectedRoutes } from './modules/app/routes/auth-routes'; | ||||||||
| import useScrollbar from './shared/components/atoms/scrollbar'; | ||||||||
| import { useAuth } from './shared/hooks/use-auth'; | ||||||||
|
|
||||||||
| const App = memo(() => { | ||||||||
| const { GlobalScrollbar } = useScrollbar(); | ||||||||
| const [cacheKey, setCacheKey] = useState<string>(''); | ||||||||
| const { token } = useAuth(); | ||||||||
| const isAuth = useMemo(() => !!token, [token]); | ||||||||
|
|
||||||||
| function App() { | ||||||||
| useEffect(() => { | ||||||||
| setupTokenRefresh(); | ||||||||
| }, []); | ||||||||
|
|
||||||||
| return ( | ||||||||
| <MuiThemeProvider> | ||||||||
| <BrowserRouter> | ||||||||
| <Routes> | ||||||||
| <Route path="/" element={<Navbar />}> | ||||||||
| <Route index element={<Home />} /> | ||||||||
| <Route path="login" element={<UserAuthForm type="login" />} /> | ||||||||
| <Route path="signup" element={<UserAuthForm type="signup" />} /> | ||||||||
| <Route path="search/:query" element={<Search />} /> | ||||||||
| <Route path="user/:username" element={<Profile />} /> | ||||||||
| <Route path="project/:project_id" element={<Project />} /> | ||||||||
|
|
||||||||
| <Route path="dashboard" element={<Sidebar />}> | ||||||||
| <Route path="projects" element={<ManageProjects />} /> | ||||||||
| <Route path="notifications" element={<Notifications />} /> | ||||||||
| </Route> | ||||||||
| <Route path="settings" element={<Sidebar />}> | ||||||||
| <Route path="edit-profile" element={<EditProfile />} /> | ||||||||
| <Route path="change-password" element={<ChangePassword />} /> | ||||||||
| </Route> | ||||||||
| </Route> | ||||||||
|
|
||||||||
| <Route path="/editor" element={<Editor />} /> | ||||||||
| <Route path="/editor/:project_id" element={<Editor />} /> | ||||||||
| useEffect(() => { | ||||||||
| setCacheKey(Date.now().toString()); | ||||||||
| }, [isAuth]); | ||||||||
|
|
||||||||
| <Route path="*" element={<PageNotFound />} /> | ||||||||
| </Routes> | ||||||||
| if (!isAuth) { | ||||||||
| return ( | ||||||||
| <> | ||||||||
| <GlobalScrollbar /> | ||||||||
| <AppUnProtectedRoutes /> | ||||||||
| </> | ||||||||
| ); | ||||||||
| } | ||||||||
|
|
||||||||
| <A2ZNotifications /> | ||||||||
| </BrowserRouter> | ||||||||
| </MuiThemeProvider> | ||||||||
| return ( | ||||||||
| <Provider key={cacheKey}> | ||||||||
| <GlobalScrollbar /> | ||||||||
| <AppProtectedRoutes /> | ||||||||
| </Provider> | ||||||||
| ); | ||||||||
| } | ||||||||
| }); | ||||||||
|
|
||||||||
|
||||||||
| App.displayName = 'App'; |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -1,9 +1,26 @@ | ||||||
| import { StrictMode } from 'react'; | ||||||
| import { createRoot } from 'react-dom/client'; | ||||||
| import App from './App'; | ||||||
| import createCache from '@emotion/cache'; | ||||||
| import { CacheProvider } from '@emotion/react'; | ||||||
| import MuiThemeProvider from './shared/components/molecules/theme'; | ||||||
| import { BrowserRouter } from 'react-router-dom'; | ||||||
| import A2ZNotifications from './shared/components/molecules/notification'; | ||||||
|
|
||||||
| const cache = createCache({ | ||||||
| key: 'myapp', | ||||||
|
||||||
| key: 'myapp', | |
| key: 'code-a2z', |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| /** @jsxImportSource @emotion/react */ | ||
| import { css } from '@emotion/react'; | ||
| import { lazy } from 'react'; | ||
| import Header from '../../../shared/components/organisms/header'; | ||
| import { HEADER_HEIGHT } from '../../../shared/components/organisms/header/constants'; | ||
| import Sidebar from '../../../shared/components/organisms/sidebar'; | ||
| import { SIDEBAR_WIDTH } from '../../../shared/components/organisms/sidebar/constants'; | ||
| import { Routes } from 'react-router-dom'; | ||
| import getRoutesV1 from '../routes/auth-routes/v1'; | ||
|
|
||
| export const LoginLazyComponent = lazy(() => import('../../user-auth-form/v1')); | ||
| export const HomePageLazyComponent = lazy(() => import('../../home/v1')); | ||
| export const SettingsPageLazyComponent = lazy( | ||
| () => import('../../settings/v1') | ||
| ); | ||
|
|
||
| export const AppLayout = () => { | ||
| return ( | ||
| <> | ||
| <Header /> | ||
| <div | ||
| css={css` | ||
| height: calc(100vh - ${HEADER_HEIGHT}px); | ||
| `} | ||
| > | ||
| <div | ||
| css={css` | ||
| height: 100%; | ||
| display: flex; | ||
| flex: 1; | ||
| position: relative; | ||
| `} | ||
| > | ||
| <Sidebar /> | ||
| <div | ||
| css={css` | ||
| height: 100%; | ||
| width: 100%; | ||
| min-width: 100%; | ||
| max-width: 100%; | ||
| flex: 1; | ||
| padding-left: ${SIDEBAR_WIDTH}px; | ||
| overflow: hidden; | ||
| `} | ||
| > | ||
| <div | ||
| css={css` | ||
| height: 100%; | ||
| transition: height 500ms ease-in-out; | ||
| width: 100%; | ||
| min-width: 100%; | ||
| max-width: 100%; | ||
| overflow: hidden; | ||
| `} | ||
| > | ||
| <Routes>{getRoutesV1()}</Routes> | ||
| </div> | ||
| </div> | ||
| </div> | ||
| </div> | ||
| </> | ||
| ); | ||
| }; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| import { Route, Routes } from 'react-router-dom'; | ||
| import { AppLayout } from '../../components'; | ||
|
|
||
| export function AppProtectedRoutes() { | ||
| return ( | ||
| <Routes> | ||
| <Route key={'/*'} path={'/*'} element={<AppLayout />} /> | ||
| </Routes> | ||
| ); | ||
| } |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,44 @@ | ||||||||||||||||||||||||||||||||||
| import { Suspense } from 'react'; | ||||||||||||||||||||||||||||||||||
| import { Navigate, Route } from 'react-router-dom'; | ||||||||||||||||||||||||||||||||||
| import { ROUTES_V1 } from '../../constants/routes'; | ||||||||||||||||||||||||||||||||||
| import { LOADING } from '../../constants'; | ||||||||||||||||||||||||||||||||||
| import Loader from '../../../../../shared/components/molecules/loader'; | ||||||||||||||||||||||||||||||||||
| import { | ||||||||||||||||||||||||||||||||||
| HomePageLazyComponent, | ||||||||||||||||||||||||||||||||||
| SettingsPageLazyComponent, | ||||||||||||||||||||||||||||||||||
| } from '../../../components'; | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| export default function getRoutesV1() { | ||||||||||||||||||||||||||||||||||
| const routes = [ | ||||||||||||||||||||||||||||||||||
| <Route | ||||||||||||||||||||||||||||||||||
| key={ROUTES_V1.HOME} | ||||||||||||||||||||||||||||||||||
| path={ROUTES_V1.HOME} | ||||||||||||||||||||||||||||||||||
| element={ | ||||||||||||||||||||||||||||||||||
| <Suspense fallback={<Loader size={32} secondary={LOADING} />}> | ||||||||||||||||||||||||||||||||||
| <HomePageLazyComponent /> | ||||||||||||||||||||||||||||||||||
| </Suspense> | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
| />, | ||||||||||||||||||||||||||||||||||
| <Route | ||||||||||||||||||||||||||||||||||
| key={ROUTES_V1.SETTINGS} | ||||||||||||||||||||||||||||||||||
| path={ROUTES_V1.SETTINGS} | ||||||||||||||||||||||||||||||||||
| element={ | ||||||||||||||||||||||||||||||||||
| <Suspense fallback={<Loader size={32} secondary={LOADING} />}> | ||||||||||||||||||||||||||||||||||
| <SettingsPageLazyComponent /> | ||||||||||||||||||||||||||||||||||
| </Suspense> | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
| />, | ||||||||||||||||||||||||||||||||||
| ]; | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| if (routes.length) { | ||||||||||||||||||||||||||||||||||
| routes.push( | ||||||||||||||||||||||||||||||||||
| <Route | ||||||||||||||||||||||||||||||||||
| key="*" | ||||||||||||||||||||||||||||||||||
| path="*" | ||||||||||||||||||||||||||||||||||
| element={<Navigate to={ROUTES_V1.HOME} replace />} | ||||||||||||||||||||||||||||||||||
| /> | ||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
|
Comment on lines
+33
to
+41
|
||||||||||||||||||||||||||||||||||
| if (routes.length) { | |
| routes.push( | |
| <Route | |
| key="*" | |
| path="*" | |
| element={<Navigate to={ROUTES_V1.HOME} replace />} | |
| /> | |
| ); | |
| } | |
| routes.push( | |
| <Route | |
| key="*" | |
| path="*" | |
| element={<Navigate to={ROUTES_V1.HOME} replace />} | |
| /> | |
| ); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| export const LOADING = 'Loading...'; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| export enum ROUTES_V1 { | ||
| HOME = '/v1/home', | ||
| SETTINGS = '/v1/settings', | ||
| } | ||
|
|
||
| export enum ROUTES_PAGE_V1 { | ||
| HOME = 'home', | ||
| SETTINGS = 'settings', | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| import { Suspense } from 'react'; | ||
| import { Route, Routes } from 'react-router-dom'; | ||
| import Loader from '../../../shared/components/molecules/loader'; | ||
| import { LOADING } from './constants'; | ||
| import { LoginLazyComponent } from '../components'; | ||
|
|
||
| export function AppUnProtectedRoutes() { | ||
| return ( | ||
| <Routes> | ||
| <Route | ||
| path="*" | ||
| element={ | ||
| <Suspense fallback={<Loader size={32} secondary={LOADING} />}> | ||
| <LoginLazyComponent /> | ||
| </Suspense> | ||
| } | ||
| /> | ||
| </Routes> | ||
| ); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using
Date.now().toString()as a cache key causes the Jotai Provider to remount and reset all global state every timeisAuthchanges. This will cause unnecessary re-renders and loss of state. Consider using a more stable approach, such as a simple counter or only updating the key when truly necessary, rather than on every auth state change.