From 5520d3c3d6f1ca17b38319076229be6c8573f7bc Mon Sep 17 00:00:00 2001 From: Jan-Willem van Bremen Date: Mon, 20 May 2024 21:23:30 +0200 Subject: [PATCH] Cleanup --- components/common/Filters.jsx | 2 +- pages/combos/index.jsx | 12 ++++++------ pages/dashboard.jsx | 20 ++++++++++++++------ pages/flatgroundtricks/index.jsx | 14 ++++++++------ pages/grinds/index.jsx | 11 +++++------ pages/manuals/index.jsx | 12 ++++++------ 6 files changed, 40 insertions(+), 31 deletions(-) diff --git a/components/common/Filters.jsx b/components/common/Filters.jsx index cc66930..5a55e01 100644 --- a/components/common/Filters.jsx +++ b/components/common/Filters.jsx @@ -16,7 +16,7 @@ function Filters({ filters = {}, onReset, children }) { }, []); return ( -
+
Filters

diff --git a/pages/combos/index.jsx b/pages/combos/index.jsx index eeed9a9..db064f2 100644 --- a/pages/combos/index.jsx +++ b/pages/combos/index.jsx @@ -39,8 +39,11 @@ export default function CombosPage() { } }; + const filteredCombos = + filters.landed === 'any' ? combos : combos?.filter((combo) => filters.landed === (combo.landed ? 'yes' : 'no')); + return ( -
+

Combos

This is an overview of all the combos you've added to your account.

@@ -101,17 +104,14 @@ export default function CombosPage() { filters.landed === (combo.landed ? 'yes' : 'no')) - } + objArray={filteredCombos} columns={[{ trick: { className: 'text-sm font-bold', alias: 'Combo name' } }, landedAtCol]} actions={getCommonActions('combos')} onAction={handleAction} entityName="combo" newLink="/new-combo" showCount + enablePagination />
diff --git a/pages/dashboard.jsx b/pages/dashboard.jsx index f36d042..6cce396 100644 --- a/pages/dashboard.jsx +++ b/pages/dashboard.jsx @@ -35,10 +35,10 @@ import TransitionScroll from 'react-transition-scroll'; // } export default function Index() { - const [flatgroundTricks, setFlatgroundTricks] = useState({ data: [], count: 0 }); - const [grinds, setGrinds] = useState({ data: [], count: 0 }); - const [manuals, setManuals] = useState({ data: [], count: 0 }); - const [combos, setCombos] = useState({ data: [], count: 0 }); + const [flatgroundTricks, setFlatgroundTricks] = useState({ data: null, count: 0 }); + const [grinds, setGrinds] = useState({ data: null, count: 0 }); + const [manuals, setManuals] = useState({ data: null, count: 0 }); + const [combos, setCombos] = useState({ data: null, count: 0 }); useAsyncEffect(async () => { const fetchAndSetData = async (endpoint, setData) => { @@ -97,10 +97,10 @@ export default function Index() { } }; - const formatAdditionalInfo = (count, data) => (count !== 0 && count !== data.length ? count + ' total' : ''); + const formatAdditionalInfo = (count, data) => (count !== 0 && count !== data?.length ? count + ' total' : ''); return ( -
+

Dashboard

This is an overview of all the landed tricks you've added to your account.

@@ -119,6 +119,8 @@ export default function Index() { defaultSortColumnIndex={1} defaultSortDirection="desc" additionalInfo={formatAdditionalInfo(flatgroundTricks.count, flatgroundTricks.data)} + additionalInfoLink="/flatgroundtricks" + enablePagination /> @@ -136,6 +138,8 @@ export default function Index() { defaultSortColumnIndex={1} defaultSortDirection="desc" additionalInfo={formatAdditionalInfo(grinds.count, grinds.data)} + additionalInfoLink="/grinds" + enablePagination /> @@ -153,6 +157,8 @@ export default function Index() { defaultSortColumnIndex={1} defaultSortDirection="desc" additionalInfo={formatAdditionalInfo(manuals.count, manuals.data)} + additionalInfoLink="/manuals" + enablePagination /> @@ -170,6 +176,8 @@ export default function Index() { defaultSortColumnIndex={1} defaultSortDirection="desc" additionalInfo={formatAdditionalInfo(combos.count, combos.data)} + additionalInfoLink="/combos" + enablePagination />
diff --git a/pages/flatgroundtricks/index.jsx b/pages/flatgroundtricks/index.jsx index 05e97ce..97f51db 100644 --- a/pages/flatgroundtricks/index.jsx +++ b/pages/flatgroundtricks/index.jsx @@ -38,8 +38,13 @@ export default function FlatgroundTricksPage() { } }; + const filteredFlatgroundTricks = + filters.landed === 'any' + ? flatgroundTricks + : flatgroundTricks?.filter((trick) => filters.landed === (trick.landed ? 'yes' : 'no')); + return ( -
+

Flatground Tricks

@@ -69,11 +74,7 @@ export default function FlatgroundTricksPage() { filters.landed === (trick.landed ? 'yes' : 'no')) - } + objArray={filteredFlatgroundTricks} columns={['stance', 'direction', 'rotation', 'name', trickCol, landedAtCol]} actions={getCommonActions('flatgroundtricks')} onAction={handleAction} @@ -81,6 +82,7 @@ export default function FlatgroundTricksPage() { newLink="/new-flatground-trick" showCount defaultSortColumnIndex={4} + enablePagination />

diff --git a/pages/grinds/index.jsx b/pages/grinds/index.jsx index 15783ee..a75e400 100644 --- a/pages/grinds/index.jsx +++ b/pages/grinds/index.jsx @@ -37,9 +37,11 @@ export default function GrindsPage() { break; } }; + const filteredGrinds = + filters.landed === 'any' ? grinds : grinds.filter((grind) => filters.landed === (grind.landed ? 'yes' : 'no')); return ( -
+

Grinds

This is an overview of all the grinds you've added to your account.

@@ -66,11 +68,7 @@ export default function GrindsPage() { filters.landed === (grind.landed ? 'yes' : 'no')) - } + objArray={filteredGrinds} columns={['stance', 'direction', 'name', trickCol, landedAtCol]} actions={getCommonActions('grinds')} entityName="grind" @@ -78,6 +76,7 @@ export default function GrindsPage() { newLink="/new-grind" showCount defaultSortColumnIndex={3} + enablePagination />
diff --git a/pages/manuals/index.jsx b/pages/manuals/index.jsx index 1d77eb8..4c012b8 100644 --- a/pages/manuals/index.jsx +++ b/pages/manuals/index.jsx @@ -38,8 +38,11 @@ export default function ManualsPage() { } }; + const filteredManuals = + filters.landed === 'any' ? manuals : manuals.filter((manual) => filters.landed === (manual.landed ? 'yes' : 'no')); + return ( -
+

Manuals

This is an overview of all the manuals you've added to your account.

@@ -67,17 +70,14 @@ export default function ManualsPage() { filters.landed === (manual.landed ? 'yes' : 'no')) - } + objArray={filteredManuals} columns={[{ type: { className: 'text-sm font-bold' } }, landedAtCol]} actions={getCommonActions('manuals')} onAction={handleAction} entityName="manual" newLink="/new-manual" showCount + enablePagination />