From 5824c353f978a5b9ab9696451ee3014c6a614ffc Mon Sep 17 00:00:00 2001 From: Joe Carstairs Date: Tue, 22 Oct 2024 07:46:43 +0100 Subject: Refactors importer to use core stuff --- .../BudgetUpdatesTable/BudgetUpdatesTable.css | 1 + .../BudgetUpdatesTable/BudgetUpdatesTable.tsx | 36 ++++++++++++++++++++++ gui/src/components/app/App.css | 1 - gui/src/components/app/App.tsx | 33 -------------------- gui/src/components/histogram/Histogram.tsx | 32 ++++++++++++++----- 5 files changed, 61 insertions(+), 42 deletions(-) create mode 100644 gui/src/components/BudgetUpdatesTable/BudgetUpdatesTable.css create mode 100644 gui/src/components/BudgetUpdatesTable/BudgetUpdatesTable.tsx delete mode 100644 gui/src/components/app/App.css delete mode 100644 gui/src/components/app/App.tsx (limited to 'gui/src/components') diff --git a/gui/src/components/BudgetUpdatesTable/BudgetUpdatesTable.css b/gui/src/components/BudgetUpdatesTable/BudgetUpdatesTable.css new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/gui/src/components/BudgetUpdatesTable/BudgetUpdatesTable.css @@ -0,0 +1 @@ + diff --git a/gui/src/components/BudgetUpdatesTable/BudgetUpdatesTable.tsx b/gui/src/components/BudgetUpdatesTable/BudgetUpdatesTable.tsx new file mode 100644 index 0000000..479d69f --- /dev/null +++ b/gui/src/components/BudgetUpdatesTable/BudgetUpdatesTable.tsx @@ -0,0 +1,36 @@ +import { BudgetUpdate } from '../../types/budgetUpdate'; +import './BudgetUpdatesTable.css'; + +function BudgetUpdatesTable({ budgetUpdates }: Props) { + return ( + + + + + + + + + + + { budgetUpdates.map(Row) } + +
DateQuantityPeriod
+ ); +} + +function Row(budgetUpdate: BudgetUpdate) { + return ( + + {budgetUpdate.date.format("DD Mm YYYY")} + {budgetUpdate.newQuantity.toString()} + {budgetUpdate.newPeriod} + + ) +} + +type Props = { + budgetUpdates: BudgetUpdate[]; +} + +export { BudgetUpdatesTable }; diff --git a/gui/src/components/app/App.css b/gui/src/components/app/App.css deleted file mode 100644 index 8b13789..0000000 --- a/gui/src/components/app/App.css +++ /dev/null @@ -1 +0,0 @@ - diff --git a/gui/src/components/app/App.tsx b/gui/src/components/app/App.tsx deleted file mode 100644 index e9ef742..0000000 --- a/gui/src/components/app/App.tsx +++ /dev/null @@ -1,33 +0,0 @@ -import { createResource, Match, Resource, Switch } from 'solid-js'; -import Histogram from '../histogram/Histogram' -import './App.css' -import { getAllCategories } from '../../ajax/backend'; -import { Category } from '../../types/category'; - -function App() { - const [categories] = createResource(getAllCategories); - - return ( - - - , { state: 'ready' }>)()} /> - - -

Loading...

-
- -

Unresolved!

-
- -

Error!

-

{JSON.stringify(categories.error, null, 2)}

-

{JSON.stringify(categories(), null, 2)}

-
- -

Refreshing!

-
-
- ); -} - -export default App diff --git a/gui/src/components/histogram/Histogram.tsx b/gui/src/components/histogram/Histogram.tsx index 3a8309b..1dd8c65 100644 --- a/gui/src/components/histogram/Histogram.tsx +++ b/gui/src/components/histogram/Histogram.tsx @@ -1,5 +1,7 @@ import { BalanceToBudgetRatio } from "../../types/balanceToBudgetRatio"; import { Category } from "../../types/category"; +import { Group } from "../../types/group"; +import { groupCategories } from "../../util/groupCategories"; import './Histogram.scss'; function Histogram({ categories }: Props) { @@ -14,6 +16,8 @@ function Histogram({ categories }: Props) { category.balanceToBudgetRatio = balanceToBudgetRatioNormaliser(category.balanceToBudgetRatio); } + const groups = [...groupCategories(categories)]; + return ( @@ -23,18 +27,26 @@ function Histogram({ categories }: Props) { - - - { - categories - .sort((c1, c2) => BalanceToBudgetRatio.compare(c1.balanceToBudgetRatio, c2.balanceToBudgetRatio)) - .map((category) => Row({ category })) - } - + { + groups.map(g => ) + }
Balance
); } +function RowGroup({ group }: GroupProps) { + return ( + + {group.name} + { + group.categories + .sort((c1, c2) => BalanceToBudgetRatio.compare(c1.balanceToBudgetRatio, c2.balanceToBudgetRatio)) + .map((category) => Row({ category })) + } + + ); +} + function Row({ category }: RowProps) { return ( @@ -57,6 +69,10 @@ type Props = { categories: Category[] | null, }; +type GroupProps = { + group: Group; +} + type RowProps = { category: Category, }; -- cgit v1.2.3