Compare commits
1 Commits
18c55262d2
...
e7051f5463
| Author | SHA1 | Date | |
|---|---|---|---|
| e7051f5463 |
1151
package-lock.json
generated
1151
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -12,15 +12,15 @@
|
|||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@tanstack/react-query": "^5.71.0",
|
"@tanstack/react-query": "^5.71.0",
|
||||||
"@tanstack/react-table": "^8.21.2",
|
"@tanstack/react-table": "^8.21.2",
|
||||||
"react": "^19.0.0",
|
"react": "^18.0.0",
|
||||||
"react-debounce-input": "^3.3.0",
|
"react-debounce-input": "^3.3.0",
|
||||||
"react-dom": "^19.0.0",
|
"react-dom": "^18.0.0",
|
||||||
"react-router": "^7.4.0"
|
"react-router": "^7.4.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@eslint/js": "^9.21.0",
|
"@eslint/js": "^9.21.0",
|
||||||
"@types/react": "^19.0.10",
|
"@types/react": "^18.0.10",
|
||||||
"@types/react-dom": "^19.0.4",
|
"@types/react-dom": "^18.0.4",
|
||||||
"@vitejs/plugin-react": "^4.3.4",
|
"@vitejs/plugin-react": "^4.3.4",
|
||||||
"eslint": "^9.21.0",
|
"eslint": "^9.21.0",
|
||||||
"eslint-plugin-react-hooks": "^5.1.0",
|
"eslint-plugin-react-hooks": "^5.1.0",
|
||||||
|
|||||||
@ -4,17 +4,13 @@ import { createRoot } from "react-dom/client";
|
|||||||
import { RouterProvider } from "react-router";
|
import { RouterProvider } from "react-router";
|
||||||
import "./index.css";
|
import "./index.css";
|
||||||
import { router } from "./routes.ts";
|
import { router } from "./routes.ts";
|
||||||
import { loader as categoriesLoader } from "./routes/categories";
|
|
||||||
import { CategoryContext } from "./store/CategoryContext.ts";
|
|
||||||
|
|
||||||
const queryClient = new QueryClient();
|
const queryClient = new QueryClient();
|
||||||
|
|
||||||
createRoot(document.getElementById("root")!).render(
|
createRoot(document.getElementById("root")!).render(
|
||||||
<StrictMode>
|
<StrictMode>
|
||||||
<QueryClientProvider client={queryClient}>
|
<QueryClientProvider client={queryClient}>
|
||||||
<CategoryContext value={await categoriesLoader()}>
|
|
||||||
<RouterProvider router={router} />
|
<RouterProvider router={router} />
|
||||||
</CategoryContext>
|
|
||||||
</QueryClientProvider>
|
</QueryClientProvider>
|
||||||
</StrictMode>
|
</StrictMode>
|
||||||
);
|
);
|
||||||
|
|||||||
@ -1,18 +1,16 @@
|
|||||||
import { useLoaderData } from "react-router";
|
import { useLoaderData } from "react-router";
|
||||||
|
|
||||||
type Category = {
|
export async function loader() {
|
||||||
name: string;
|
return await fetch(`http://localhost:9000/categories`).then((response) => {
|
||||||
group: { name: string } | undefined;
|
|
||||||
};
|
|
||||||
|
|
||||||
export async function loader(): Promise<Category[]> {
|
|
||||||
return fetch(`http://localhost:9000/categories`).then((response) => {
|
|
||||||
return response.json();
|
return response.json();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function Categories() {
|
export default function Categories() {
|
||||||
const data = useLoaderData<typeof loader>();
|
const data: {
|
||||||
|
name: string;
|
||||||
|
group: { name: string } | undefined;
|
||||||
|
}[] = useLoaderData<typeof loader>();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<table>
|
<table>
|
||||||
|
|||||||
@ -7,20 +7,11 @@ import {
|
|||||||
PaginationState,
|
PaginationState,
|
||||||
useReactTable,
|
useReactTable,
|
||||||
} from "@tanstack/react-table";
|
} from "@tanstack/react-table";
|
||||||
import { useContext, useState } from "react";
|
import { useState } from "react";
|
||||||
import { DebounceInput } from "react-debounce-input";
|
import { DebounceInput } from "react-debounce-input";
|
||||||
import { CategoryContext } from "../store/CategoryContext";
|
|
||||||
|
|
||||||
const PageSize = 30;
|
const PageSize = 30;
|
||||||
|
|
||||||
type Transaction = {
|
|
||||||
id: number;
|
|
||||||
date: string;
|
|
||||||
description: string;
|
|
||||||
value: number;
|
|
||||||
category: string;
|
|
||||||
};
|
|
||||||
|
|
||||||
async function loader(page = 0, category: string | undefined = "") {
|
async function loader(page = 0, category: string | undefined = "") {
|
||||||
const url = new URL("http://localhost:9000/transactions");
|
const url = new URL("http://localhost:9000/transactions");
|
||||||
url.search = new URLSearchParams({
|
url.search = new URLSearchParams({
|
||||||
@ -29,44 +20,30 @@ async function loader(page = 0, category: string | undefined = "") {
|
|||||||
...(category !== "" && { category: category }),
|
...(category !== "" && { category: category }),
|
||||||
}).toString();
|
}).toString();
|
||||||
|
|
||||||
return await fetch(url).then(async (response) => {
|
return await fetch(url).then((response) => response.json());
|
||||||
return {
|
|
||||||
transactions: (await response.json()) as Transaction[],
|
|
||||||
totalCount: response.headers.get("x-total-count"),
|
|
||||||
};
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type Transaction = {
|
||||||
|
id: number;
|
||||||
|
date: string;
|
||||||
|
description: string;
|
||||||
|
value: number;
|
||||||
|
category: string;
|
||||||
|
};
|
||||||
|
|
||||||
const columnHelper = createColumnHelper<Transaction>();
|
const columnHelper = createColumnHelper<Transaction>();
|
||||||
|
|
||||||
const columns = [
|
const columns = [
|
||||||
columnHelper.accessor("date", {
|
columnHelper.accessor("date", {
|
||||||
header: "Date",
|
|
||||||
enableColumnFilter: false,
|
enableColumnFilter: false,
|
||||||
}),
|
}),
|
||||||
columnHelper.accessor("description", {
|
columnHelper.accessor("description", {
|
||||||
header: "Description",
|
|
||||||
enableColumnFilter: false,
|
enableColumnFilter: false,
|
||||||
}),
|
}),
|
||||||
columnHelper.accessor("value", {
|
columnHelper.accessor("value", {
|
||||||
header: "Value",
|
|
||||||
enableColumnFilter: false,
|
enableColumnFilter: false,
|
||||||
}),
|
}),
|
||||||
columnHelper.accessor("category", {
|
columnHelper.accessor("category", {}),
|
||||||
header: "Category",
|
|
||||||
cell: (props) => {
|
|
||||||
console.log(props.getValue());
|
|
||||||
return (
|
|
||||||
<select defaultValue={props.getValue()}>
|
|
||||||
{useContext(CategoryContext).map((category) => (
|
|
||||||
<option key={category.name} value={category.name}>
|
|
||||||
{category.name}
|
|
||||||
</option>
|
|
||||||
))}
|
|
||||||
</select>
|
|
||||||
);
|
|
||||||
},
|
|
||||||
}),
|
|
||||||
];
|
];
|
||||||
|
|
||||||
export default function Transactions() {
|
export default function Transactions() {
|
||||||
@ -93,18 +70,18 @@ export default function Transactions() {
|
|||||||
|
|
||||||
const table = useReactTable({
|
const table = useReactTable({
|
||||||
columns,
|
columns,
|
||||||
data: data?.transactions ?? [],
|
data,
|
||||||
getCoreRowModel: getCoreRowModel(),
|
getCoreRowModel: getCoreRowModel(),
|
||||||
manualPagination: true,
|
manualPagination: true,
|
||||||
manualFiltering: true,
|
manualFiltering: true,
|
||||||
rowCount: data?.totalCount ? +data.totalCount : undefined,
|
// rowCount: , // TODO: get this from the server
|
||||||
|
pageCount: -1,
|
||||||
onPaginationChange: setPagination,
|
onPaginationChange: setPagination,
|
||||||
onColumnFiltersChange: setColumnFilters,
|
onColumnFiltersChange: setColumnFilters,
|
||||||
state: {
|
state: {
|
||||||
pagination,
|
pagination,
|
||||||
columnFilters,
|
columnFilters,
|
||||||
},
|
},
|
||||||
debugTable: true,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
if (isPending) {
|
if (isPending) {
|
||||||
|
|||||||
@ -1,8 +0,0 @@
|
|||||||
import { createContext } from "react";
|
|
||||||
|
|
||||||
type Category = {
|
|
||||||
name: string;
|
|
||||||
group: { name: string } | undefined;
|
|
||||||
};
|
|
||||||
|
|
||||||
export const CategoryContext = createContext<Category[]>([]);
|
|
||||||
Loading…
x
Reference in New Issue
Block a user