Skip to content

Commit a15c1b5

Browse files
authored
#63 chunk application by page (#84)
* feat: converted into monorepo for root package.json management * fix: update github workflows * fix: rename frontend package to frontend for filtering * fix: workflows to use correct pnpm filtering * fix: workflows for uses clause * feat: upgrade react-router to v7 & dynamic chunking
1 parent f37b018 commit a15c1b5

File tree

11 files changed

+70
-31
lines changed

11 files changed

+70
-31
lines changed

frontend/package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"prepare": "pnpm -w lefthook install"
1616
},
1717
"dependencies": {
18+
"@loadable/component": "^5.16.4",
1819
"@radix-ui/react-dialog": "^1.1.5",
1920
"@radix-ui/react-dropdown-menu": "^2.1.5",
2021
"@radix-ui/react-navigation-menu": "^1.2.4",
@@ -32,13 +33,14 @@
3233
"lucide-react": "^0.474.0",
3334
"react": "^18.3.1",
3435
"react-dom": "^18.3.1",
35-
"react-router-dom": "^7.1.5",
36+
"react-router": "^7.1.5",
3637
"recharts": "^2.15.1",
3738
"tailwind-merge": "^3.0.1",
3839
"tailwindcss": "^4.0.3",
3940
"tailwindcss-animate": "^1.0.7"
4041
},
4142
"devDependencies": {
43+
"@types/loadable__component": "^5.13.9",
4244
"@types/node": "^22.13.0",
4345
"@types/react": "^18.3.18",
4446
"@types/react-dom": "^18.3.5",

frontend/src/App.tsx

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
11
import { COLLECTION_ID, DATABASE_ID, getDatabase } from '@/lib/Auth'
22
import { getUser } from '@/lib/Auth.ts'
33
import type { CollectionRow } from '@/types'
4+
import loadable from '@loadable/component'
45
import { type Models, Query } from 'appwrite'
56
import { useEffect, useState } from 'react'
6-
import { Route, Routes } from 'react-router-dom'
7+
import { Route, Routes } from 'react-router'
78
import { Header } from './components/ui/Header.tsx'
89
import { Toaster } from './components/ui/toaster.tsx'
9-
import { Collection } from './pages/collection/Collection.tsx'
10-
import { Overview } from './pages/overview/Overview.tsx'
11-
import { Trade } from './pages/trade/Trade.tsx'
12-
import { Verify } from './pages/verify/Verify.tsx'
10+
11+
// Lazy import for chunking
12+
const Overview = loadable(() => import('./pages/overview/Overview.tsx'))
13+
const Verify = loadable(() => import('./pages/verify/Verify.tsx'))
14+
const Collection = loadable(() => import('./pages/collection/Collection.tsx'))
15+
const Trade = loadable(() => import('./pages/trade/Trade.tsx'))
1316

1417
function App() {
1518
const [user, setUser] = useState<Models.User<Models.Preferences> | null>(null)

frontend/src/components/ui/Header.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { logout } from '@/lib/Auth.ts'
77
import type { Models } from 'appwrite'
88
import { ChevronRight } from 'lucide-react'
99
import type { FC } from 'react'
10-
import { Link } from 'react-router-dom'
10+
import { Link } from 'react-router'
1111

1212
interface Props {
1313
user: Models.User<Models.Preferences> | null

frontend/src/main.tsx

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { StrictMode } from 'react'
1+
import { StrictMode, Suspense } from 'react'
22
import { createRoot } from 'react-dom/client'
3-
import { HashRouter } from 'react-router-dom'
3+
import { HashRouter } from 'react-router'
44
import App from './App.tsx'
55
import './index.css'
66

@@ -11,8 +11,10 @@ if (!root) {
1111

1212
createRoot(root).render(
1313
<StrictMode>
14-
<HashRouter>
15-
<App />
16-
</HashRouter>
14+
<Suspense fallback={<div>Loading...</div>}>
15+
<HashRouter>
16+
<App />
17+
</HashRouter>
18+
</Suspense>
1719
</StrictMode>,
1820
)

frontend/src/pages/collection/Collection.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,13 @@ interface Props {
99
setOwnedCards: (cards: CollectionRow[]) => void
1010
}
1111

12-
export const Collection: FC<Props> = ({ user, ownedCards, setOwnedCards }) => {
12+
const Collection: FC<Props> = ({ user, ownedCards, setOwnedCards }) => {
1313
if (user) {
1414
// TODO: Refactor that cards still show without a user, but prompts for a login if you are not logged in yet.
1515
return <Cards user={user} ownedCards={ownedCards} setOwnedCards={setOwnedCards} />
1616
}
1717

1818
return null
1919
}
20+
21+
export default Collection

frontend/src/pages/overview/Overview.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ interface Props {
1010
ownedCards: CollectionRow[]
1111
}
1212

13-
export const Overview: FC<Props> = ({ user, ownedCards }) => {
13+
const Overview: FC<Props> = ({ user, ownedCards }) => {
1414
const ownedCardsCount = ownedCards.reduce((total, card) => total + card.amount_owned, 0)
1515
if (user) {
1616
return (
@@ -128,3 +128,5 @@ const GradientCard: FC<GradientCardProps> = ({ title, paragraph, className }) =>
128128
</div>
129129
)
130130
}
131+
132+
export default Overview

frontend/src/pages/trade/Trade.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ interface Props {
99
ownedCards: CollectionRow[]
1010
}
1111

12-
export function Trade({ user, ownedCards }: Props) {
12+
function Trade({ user, ownedCards }: Props) {
1313
const lookingForTradeCards = () => {
1414
const allCards = [...a1Cards, ...a2Cards, ...a1aCards, ...paCards]
1515
const missingCards = allCards.filter((ac) => ownedCards.findIndex((oc) => oc.card_id === ac.card_id) === -1)
@@ -45,3 +45,5 @@ export function Trade({ user, ownedCards }: Props) {
4545

4646
return null
4747
}
48+
49+
export default Trade

frontend/src/pages/verify/Verify.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1+
import { login } from '@/lib/Auth.ts'
12
import { useEffect, useState } from 'react'
2-
import { login } from '../../lib/Auth.ts'
33

4-
export const Verify = () => {
4+
const Verify = () => {
55
const [errorLoggingIn, setErrorLoggingIn] = useState(false)
66

77
useEffect(() => {
@@ -26,3 +26,5 @@ export const Verify = () => {
2626
</div>
2727
)
2828
}
29+
30+
export default Verify

frontend/tsconfig.app.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
"noUnusedParameters": true,
1818
"noFallthroughCasesInSwitch": true,
1919
"noUncheckedSideEffectImports": true,
20+
"composite": true,
21+
"forceConsistentCasingInFileNames": true,
2022

2123
"baseUrl": ".",
2224
"paths": {

frontend/tsconfig.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
"files": [],
33
"references": [{ "path": "./tsconfig.app.json" }],
44
"compilerOptions": {
5+
"strict": true,
6+
"forceConsistentCasingInFileNames": true,
57
"baseUrl": ".",
68
"paths": {
79
"@assets/*": ["./assets/*"],

0 commit comments

Comments
 (0)