Skip to content

Commit

Permalink
feat: add suspense to grid and rab routes
Browse files Browse the repository at this point in the history
  • Loading branch information
beeman committed Feb 19, 2024
1 parent 6339ff4 commit f6a0751
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 21 deletions.
3 changes: 2 additions & 1 deletion apps/web/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@
},
"configurations": {
"development": {
"buildTarget": "web:build:development"
"buildTarget": "web:build:development",
"port": 4321
},
"production": {
"buildTarget": "web:build:production",
Expand Down
5 changes: 3 additions & 2 deletions packages/core/src/lib/ui-grid-routes/ui-grid-routes.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { Grid, GridColProps, GridProps, NavLink, NavLinkProps } from '@mantine/core'
import { ReactNode, useMemo } from 'react'
import { ReactNode, Suspense, useMemo } from 'react'
import { Link, Navigate, useLocation, useRoutes } from 'react-router-dom'
import { UiNotFound } from '../ui-not-found'
import { UiLoader } from '../ui-loader'

export interface UiGridRoute extends NavLinkProps {
path: string
Expand Down Expand Up @@ -43,7 +44,7 @@ export function UiGridRoutes({ basePath, routes, leftColProps, rightColProps, ..
{links}
</Grid.Col>
<Grid.Col span={{ base: 12, sm: 10 }} {...leftColProps}>
{router}
<Suspense fallback={<UiLoader />}>{router}</Suspense>
</Grid.Col>
</Grid>
)
Expand Down
19 changes: 11 additions & 8 deletions packages/core/src/lib/ui-tab-routes/ui-tab-routes.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Box, Tabs, TabsProps, Text } from '@mantine/core'
import { ReactElement, ReactNode } from 'react'
import { ReactElement, ReactNode, Suspense } from 'react'
import { Navigate, Route, Routes, useLocation, useNavigate } from 'react-router-dom'
import { UiLoader } from '../ui-loader'

export interface UiTabRoute {
element: ReactNode
Expand Down Expand Up @@ -42,13 +43,15 @@ export function UiTabRoutes({
))}
</Tabs.List>
</Tabs>
<Routes>
{redirect ? <Route index element={<Navigate replace to={`./${redirect}`} />} /> : null}
{tabs.map((tab) => (
<Route key={tab.path} path={`${tab.path}/*`} element={tab.element} />
))}
<Route path="*" element={<Navigate replace to={`./${redirect}`} />} />
</Routes>
<Suspense fallback={<UiLoader />}>
<Routes>
{redirect ? <Route index element={<Navigate replace to={`./${redirect}`} />} /> : null}
{tabs.map((tab) => (
<Route key={tab.path} path={`${tab.path}/*`} element={tab.element} />
))}
<Route path="*" element={<Navigate replace to={`./${redirect}`} />} />
</Routes>
</Suspense>
</Box>
)
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { Grid, GridColProps, GridProps, NavLink, NavLinkProps } from '@mantine/core'
import { ReactNode, useMemo } from 'react'
import { ReactNode, Suspense, useMemo } from 'react'
import { Link, Navigate, useLocation, useRoutes } from 'react-router-dom'
import { <%= prefix.className %>NotFound } from '../<%= prefix.fileName %>-not-found'
import { <%= prefix.className %>Loader } from '../<%= prefix.fileName %>-loader'

export interface <%= prefix.className %>GridRoute extends NavLinkProps {
path: string
Expand Down Expand Up @@ -43,7 +44,7 @@ export function <%= prefix.className %>GridRoutes({ basePath, routes, leftColPro
{links}
</Grid.Col>
<Grid.Col span={{ base: 12, sm: 10 }} {...leftColProps}>
{router}
<Suspense fallback={<UiLoader />}>{router}</Suspense>
</Grid.Col>
</Grid>
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Box, Tabs, TabsProps, Text } from '@mantine/core'
import { ReactElement, ReactNode } from 'react'
import { ReactElement, ReactNode, Suspense } from 'react'
import { Navigate, Route, Routes, useLocation, useNavigate } from 'react-router-dom'
import { <%= prefix.className %>Loader } from '../<%= prefix.fileName %>-loader'

export interface <%= prefix.className %>TabRoute {
element: ReactNode
Expand Down Expand Up @@ -42,13 +43,15 @@ export function <%= prefix.className %>TabRoutes({
))}
</Tabs.List>
</Tabs>
<Routes>
{redirect ? <Route index element={<Navigate replace to={`./${redirect}`} />} /> : null}
{tabs.map((tab) => (
<Route key={tab.path} path={`${tab.path}/*`} element={tab.element} />
))}
<Route path="*" element={<Navigate replace to={`./${redirect}`} />} />
</Routes>
<Suspense fallback={<<%= prefix.className %>Loader />}>
<Routes>
{redirect ? <Route index element={<Navigate replace to={`./${redirect}`} />} /> : null}
{tabs.map((tab) => (
<Route key={tab.path} path={`${tab.path}/*`} element={tab.element} />
))}
<Route path="*" element={<Navigate replace to={`./${redirect}`} />} />
</Routes>
</Suspense>
</Box>
)
}

0 comments on commit f6a0751

Please sign in to comment.