summaryrefslogtreecommitdiff
path: root/gui/src/views/budgetUpdatesTable/BudgetUpdatesTableView.tsx
blob: 465ea923ce4486b0e40a332b6a2fedb6ff2ca96e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import { createSignal, Match, Resource, Switch } from 'solid-js';
import { BudgetUpdate } from '../../types/budgetUpdate';
import { BudgetUpdatesTable } from '../../components/BudgetUpdatesTable/BudgetUpdatesTable';
import { Category } from '../../types/category';
import './BudgetUpdatesTableView.css';

export function BudgetUpdatesTableView({ budgetUpdates, categories }: Props) {
  const [newCategoryId, setCategoryId] = createSignal<number>();

  const filteredAndSortedBudgetUpdates: BudgetUpdate[] = budgetUpdates()
    ?.filter((bu) => bu.categoryId === newCategoryId())
    ?.sort((bu1, bu2) => bu2.date.diff(bu1.date))
    ?? [];

  return (
    <div>
      <form action="none">
        <label for="category">Category</label>
        <select id="category" onChange={(e) => setCategoryId(Number(e.target.value))}>
          {(categories() ?? []).map((c) =>
            <option value={c.id}>{c.name}</option>)}
        </select>
      </form>
      <BudgetUpdatesTable budgetUpdates={filteredAndSortedBudgetUpdates as BudgetUpdate[]} />
    </div>
  );
}

type Props = {
  budgetUpdates: Resource<BudgetUpdate[] | null>;
  categories: Resource<Category[] | null>;
}