From 50ecb39cceaf72a6d7c7db74179a12492580f645 Mon Sep 17 00:00:00 2001 From: mattia Date: Mon, 6 Jan 2025 17:46:10 +0100 Subject: [PATCH] feat: UI cleanup and short GUIDs --- package-lock.json | 27 ++++++++++++++++++++++-- package.json | 1 + src/client/Root.tsx | 25 ++++++++++++++++++++++ src/client/Sessions.tsx | 41 ++++++++++++++++++++++++++++++++++--- src/client/configuration.ts | 3 +++ src/client/guid.ts | 7 +++++++ src/client/theme.ts | 6 ++---- 7 files changed, 101 insertions(+), 9 deletions(-) create mode 100644 src/client/configuration.ts create mode 100644 src/client/guid.ts diff --git a/package-lock.json b/package-lock.json index 6505674..ff8cdc7 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "game-logger", - "version": "0.0.2", + "version": "0.0.3", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "game-logger", - "version": "0.0.2", + "version": "0.0.3", "license": "ISC", "dependencies": { "@ts-rest/core": "^3.51.0", @@ -41,6 +41,7 @@ "@vitejs/plugin-react": "^4.3.4", "concurrently": "^9.1.2", "date-fns": "^4.1.0", + "jotai": "^2.11.0", "material-react-table": "^3.1.0", "openapi3-ts": "^4.4.0", "react": "^18.0.0", @@ -3577,6 +3578,28 @@ "integrity": "sha512-VLghIWNM6ELQzo7zwmcg0NmTVyWKYjvIeM83yjp0wRDTmUnrM678fQbcKBo6n2CJEF0szoG//ytg+TKla89ALQ==", "license": "MIT" }, + "node_modules/jotai": { + "version": "2.11.0", + "resolved": "https://registry.npmjs.org/jotai/-/jotai-2.11.0.tgz", + "integrity": "sha512-zKfoBBD1uDw3rljwHkt0fWuja1B76R7CjznuBO+mSX6jpsO1EBeWNRKpeaQho9yPI/pvCv4recGfgOXGxwPZvQ==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=12.20.0" + }, + "peerDependencies": { + "@types/react": ">=17.0.0", + "react": ">=17.0.0" + }, + "peerDependenciesMeta": { + "@types/react": { + "optional": true + }, + "react": { + "optional": true + } + } + }, "node_modules/js-tokens": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/js-tokens/-/js-tokens-4.0.0.tgz", diff --git a/package.json b/package.json index 8948638..798f615 100644 --- a/package.json +++ b/package.json @@ -37,6 +37,7 @@ "@vitejs/plugin-react": "^4.3.4", "concurrently": "^9.1.2", "date-fns": "^4.1.0", + "jotai": "^2.11.0", "material-react-table": "^3.1.0", "openapi3-ts": "^4.4.0", "react": "^18.0.0", diff --git a/src/client/Root.tsx b/src/client/Root.tsx index 419ba13..d7c3db4 100644 --- a/src/client/Root.tsx +++ b/src/client/Root.tsx @@ -2,8 +2,10 @@ import { AppBar, Breadcrumbs, Container, + FormControlLabel, Link, Stack, + Switch, Toolbar, Typography, } from "@mui/material"; @@ -15,11 +17,23 @@ import { } from "react-router"; import "./theme"; import { serverRoot } from "./client"; +import { useAtom } from "jotai"; +import { shortGuidsAtom } from "./configuration"; +import { ChangeEvent, useCallback } from "react"; export function Root() { const location = useLocation(); const params = useParams(); + const [shortGuids, setShortGuids] = useAtom(shortGuidsAtom); + + const handleShortGuidsOnChange = useCallback( + (e: ChangeEvent) => { + setShortGuids(e.target.checked); + }, + [setShortGuids] + ); + return ( @@ -28,6 +42,17 @@ export function Root() { Game Logger + + } + label={"Use short GUIDs"} + /> ({ @@ -73,27 +77,54 @@ function SessionsTable({ isRefetching: boolean; columnFilters: MRT_ColumnFiltersState; }) { + const [shortGuids] = useAtom(shortGuidsAtom); + const columns = useMemo[]>( () => [ { accessorKey: "save_id", header: "Save ID", + grow: false, + Cell: ({ + row: { + original: { save_id }, + }, + }) => {formatGuid(save_id, shortGuids)}, }, { accessorKey: "id", header: "ID", + grow: true, + Cell: ({ + row: { + original: { id }, + }, + }) => {formatGuid(id, shortGuids)}, }, { accessorKey: "game_name", header: "Game Name", + grow: false, + Cell: ({ + row: { + original: { game_name }, + }, + }) => {game_name}, }, { accessorKey: "version", header: "Version", + grow: false, + Cell: ({ + row: { + original: { version }, + }, + }) => {version}, }, { accessorKey: "time", header: "Time", + grow: true, Cell: ({ row }) => { const rangeInterval = interval( row.original.start_time, @@ -104,19 +135,23 @@ function SessionsTable({ const formattedDuration = formatDuration(duration); return ( - {formattedStartTime} -
({formattedDuration || "very quick"}) + {formattedStartTime} + + {formattedDuration || "very quick"}, {row.original.num_events}{" "} + events +
); }, }, ], - [] + [shortGuids] ); const navigate = useNavigate(); const table = useMaterialReactTable({ + layoutMode: "grid", data: sessions, columns, muiTableBodyRowProps: ({ row }) => ({ diff --git a/src/client/configuration.ts b/src/client/configuration.ts new file mode 100644 index 0000000..b97def5 --- /dev/null +++ b/src/client/configuration.ts @@ -0,0 +1,3 @@ +import {atom} from "jotai"; + +export const shortGuidsAtom = atom(true); \ No newline at end of file diff --git a/src/client/guid.ts b/src/client/guid.ts new file mode 100644 index 0000000..fb775e9 --- /dev/null +++ b/src/client/guid.ts @@ -0,0 +1,7 @@ +export function formatGuid(guid: string, shortGuid: boolean) { + if (shortGuid) { + return guid.substring(0, 4) + "-" + guid.substring(guid.length - 4); + } else { + return guid; + } +} diff --git a/src/client/theme.ts b/src/client/theme.ts index cf3b29f..2324260 100644 --- a/src/client/theme.ts +++ b/src/client/theme.ts @@ -7,17 +7,15 @@ declare module "@mui/material/Typography" { } } -// const x: LinkPropsVariantOverrides; - // A custom theme for this app const theme = createTheme({ cssVariables: true, palette: { primary: { - main: "#556cd6", + main: "#735DA5", }, secondary: { - main: "#19857b", + main: "#D3C5E5", }, error: { main: red.A400,