From a8d51b44b88449a09cd8a0415a5dbcb6ae474482 Mon Sep 17 00:00:00 2001 From: Topvennie Date: Sun, 21 Jul 2024 23:35:07 +0200 Subject: [PATCH] vinvoor: minor visual improvements --- vinvoor/src/cards/CardsAdd.tsx | 49 +++++++++++-------- vinvoor/src/overview/Overview.tsx | 15 ++---- vinvoor/src/overview/heatmap/Heatmap.tsx | 4 +- vinvoor/src/overview/heatmap/heatmap.css | 10 ++-- vinvoor/src/overview/heatmap/utils.ts | 10 +++- .../src/providers/CustomSnackbarProvider.tsx | 2 +- vinvoor/src/settings/SettingsOverview.tsx | 7 +-- vinvoor/src/theme.ts | 11 +++-- 8 files changed, 61 insertions(+), 47 deletions(-) diff --git a/vinvoor/src/cards/CardsAdd.tsx b/vinvoor/src/cards/CardsAdd.tsx index fa5eb00..b64a134 100644 --- a/vinvoor/src/cards/CardsAdd.tsx +++ b/vinvoor/src/cards/CardsAdd.tsx @@ -73,7 +73,7 @@ export const CardsAdd = () => { await postApi(REGISTER_ENDPOINT) .then(() => (started = true)) .catch((error) => { - if (isResponseNot200Error(error)) + if (isResponseNot200Error(error)) { error.response .json() .then((response: CardPostResponse) => { @@ -86,7 +86,7 @@ export const CardsAdd = () => { variant: "error", }); }); - else throw new Error(error); + } else throw new Error(error); }); } @@ -95,29 +95,36 @@ export const CardsAdd = () => { if (started) { setRegistering(true); - const id = randomInt().toString(); - enqueueSnackbar(requestSuccess, { - variant: "info", - persist: true, - key: id, - }); + let id: string | undefined; + + if (!(response.registering && response.isCurrentUser)) { + id = randomInt().toString(); + enqueueSnackbar(requestSuccess, { + variant: "info", + persist: true, + key: id, + }); + } checkCardsChange() .then((scanned) => { - closeSnackbar(id); setRegistering(false); - if (scanned) { - enqueueSnackbar(registerSucces, { - variant: "success", - }); - getApi( - "cards", - convertCardJSON - ).then((cards) => setCards(cards)); - } else - enqueueSnackbar(registerFail, { - variant: "error", - }); + if (id) { + closeSnackbar(id); + + if (scanned) { + enqueueSnackbar(registerSucces, { + variant: "success", + }); + getApi( + "cards", + convertCardJSON + ).then((cards) => setCards(cards)); + } else + enqueueSnackbar(registerFail, { + variant: "error", + }); + } }) .finally(() => setProgressProps(defaultProgressProps)); } diff --git a/vinvoor/src/overview/Overview.tsx b/vinvoor/src/overview/Overview.tsx index 76897dc..61377c6 100644 --- a/vinvoor/src/overview/Overview.tsx +++ b/vinvoor/src/overview/Overview.tsx @@ -50,12 +50,7 @@ export const Overview = () => { {scans.length > 0 ? ( - + @@ -88,8 +83,8 @@ export const Overview = () => { { ); }; - -// Current height of the heatmap is calculated using ref's and calculus -// TODO: Change it as it is very very very very very very ugly ^^ -// Add a grid item underneath and see what happens diff --git a/vinvoor/src/overview/heatmap/Heatmap.tsx b/vinvoor/src/overview/heatmap/Heatmap.tsx index e2bcdea..e09ce90 100644 --- a/vinvoor/src/overview/heatmap/Heatmap.tsx +++ b/vinvoor/src/overview/heatmap/Heatmap.tsx @@ -271,7 +271,9 @@ export const Heatmap: FC = ({ {renderMonthLabels()} - + {renderColumns()} diff --git a/vinvoor/src/overview/heatmap/heatmap.css b/vinvoor/src/overview/heatmap/heatmap.css index 56673ed..6bb2a2f 100644 --- a/vinvoor/src/overview/heatmap/heatmap.css +++ b/vinvoor/src/overview/heatmap/heatmap.css @@ -2,11 +2,6 @@ stroke-opacity: 0; } -.rect { - animation: createBox 1s; - stroke-width: 1px; -} - @keyframes createBox { from { width: 0; @@ -16,3 +11,8 @@ transform: scale(1); } } + +.rect { + /* animation: createBox 1s; */ + stroke-width: 1px; +} diff --git a/vinvoor/src/overview/heatmap/utils.ts b/vinvoor/src/overview/heatmap/utils.ts index 780689f..b427295 100644 --- a/vinvoor/src/overview/heatmap/utils.ts +++ b/vinvoor/src/overview/heatmap/utils.ts @@ -88,8 +88,16 @@ export const getColumnCount = ( variant: HeatmapVariant ) => { if (variant === HeatmapVariant.DAYS) { + const startOfWeek = new Date(startDate); + startOfWeek.setDate(startOfWeek.getDate() - startOfWeek.getDay()); + + const endOfWeek = new Date(endDate); + if (endOfWeek.getDay() === 0) + endOfWeek.setDate(endOfWeek.getDate() - endOfWeek.getDay()); + else endOfWeek.setDate(endOfWeek.getDate() - endOfWeek.getDay() + 6); + return Math.ceil( - (endDate.getTime() - startDate.getTime()) / + (endOfWeek.getTime() - startOfWeek.getTime()) / (DAYS_IN_WEEK * MILLISECONDS_IN_ONE_DAY) ); } else { diff --git a/vinvoor/src/providers/CustomSnackbarProvider.tsx b/vinvoor/src/providers/CustomSnackbarProvider.tsx index 144bb63..a6f7fe5 100644 --- a/vinvoor/src/providers/CustomSnackbarProvider.tsx +++ b/vinvoor/src/providers/CustomSnackbarProvider.tsx @@ -24,7 +24,7 @@ export const CustomSnackbarProvider: FC = ({ { - More settings coming soon! - + ...yay? + diff --git a/vinvoor/src/theme.ts b/vinvoor/src/theme.ts index 95509b1..82b12e2 100644 --- a/vinvoor/src/theme.ts +++ b/vinvoor/src/theme.ts @@ -2,9 +2,6 @@ import { createTheme, ThemeOptions } from "@mui/material"; const baseTheme: ThemeOptions = { palette: { - primary: { - main: "#ff7f00", - }, secondary: { main: "#002379", }, @@ -48,6 +45,10 @@ export const lightTheme = createTheme({ palette: { ...baseTheme.palette, mode: "light", + primary: { + main: "#ff7f00", + contrastText: "#121212", + }, }, }); @@ -56,6 +57,10 @@ export const darkTheme = createTheme({ palette: { ...baseTheme.palette, mode: "dark", + primary: { + main: "#ff7f00", + contrastText: "#ffffff", + }, background: { default: "#121212", },