From 4998a22fc0f877e83d1e24514bd60822df79ad16 Mon Sep 17 00:00:00 2001 From: Araozu Date: Thu, 31 Aug 2023 15:30:44 -0500 Subject: [PATCH] [FE][Certs] Hide registers older than CURRENT_YEAR - 1 --- frontend/src/certs/Registers/index.tsx | 76 +++++++++++++++++++--- frontend/src/icons/CaretRight.tsx | 13 ++++ frontend/src/icons/CopyIcon.tsx | 2 +- frontend/src/icons/DocxIcon.tsx | 2 +- frontend/src/icons/HomeIcon.tsx | 2 +- frontend/src/icons/KeyIcon.tsx | 2 +- frontend/src/icons/MagnifyingGlassIcon.tsx | 2 +- frontend/src/icons/PaletteIcon.tsx | 2 +- frontend/src/icons/ScanIcon.tsx | 2 +- frontend/src/icons/StackIcon.tsx | 2 +- frontend/src/icons/TrashIcon.tsx | 2 +- frontend/src/icons/XIcon.tsx | 2 +- 12 files changed, 91 insertions(+), 18 deletions(-) create mode 100644 frontend/src/icons/CaretRight.tsx diff --git a/frontend/src/certs/Registers/index.tsx b/frontend/src/certs/Registers/index.tsx index d81c23f..703060d 100644 --- a/frontend/src/certs/Registers/index.tsx +++ b/frontend/src/certs/Registers/index.tsx @@ -1,12 +1,14 @@ -import { For, Show, createEffect, createSignal } from "solid-js"; +import { For, Show, createEffect, createMemo, createSignal } from "solid-js"; import { DownloadIcon } from "../../icons/DownloadIcon"; import { Person } from "../../types/Person"; import { Register } from "../../types/Register"; import { courseMap } from "../../utils/allCourses"; import { certGenerator } from "../../certGenerator"; +import { CaretRight } from "../../icons/CaretRight"; export function Registers(props: {person: Person | null, count: number}) { const [registers, setRegisters] = createSignal>([]); + const [showHidden, setShowHidden] = createSignal(false); createEffect(async() => { // eslint-disable-next-line @typescript-eslint/no-unused-vars @@ -26,18 +28,70 @@ export function Registers(props: {person: Person | null, count: number}) { } }); + // All registers sorted by year, and an indicator of whether there's register older + // than last year + const registerSortedList = createMemo<[Array>, boolean]>(() => { + const allRegisters = registers(); + + const registerByYear: {[y: string]: Array} = {}; + + let olderThanLastYear = false; + allRegisters.forEach((register) => { + const year = new Date(register.register_display_date).getFullYear(); + const currentYear = new Date().getFullYear(); + + // Don't show registers from before last year + if (year < (currentYear - 1)) { + olderThanLastYear = true; + if (!showHidden()) { + return; + } + } + + if (registerByYear[year] === undefined) { + registerByYear[year] = []; + } + + registerByYear[year].push(register); + }); + + // Create a new array with each year's registers + // Sort the object keys (years) in descending order + const sortedYears = Object.keys(registerByYear).sort((y1, y2) => (y1 < y2 ? 1 : -1)); + + // Create the final array + const result = sortedYears.map((year) => registerByYear[year].sort((r1, r2) => (r1.register_display_date < r2.register_display_date ? 1 : -1))); + + return [result, olderThanLastYear]; + }); + + const inputCheck = () => setShowHidden((x) => !x); + return (
-

+

{props.person?.person_names}  {props.person?.person_paternal_surname}  {props.person?.person_maternal_surname} + + +    | + + + Ocultar cert. anteriores a {new Date().getFullYear() - 1} + +

-
- - {(register) => } - -
+ + + {(year) => ( +
+ + {(register) => } + +
+ )} +
); } @@ -91,7 +145,7 @@ function RegisterEl(props: {register: Register, person: Person}) { }; return ( -
+
+
); } diff --git a/frontend/src/icons/CaretRight.tsx b/frontend/src/icons/CaretRight.tsx new file mode 100644 index 0000000..3f523f2 --- /dev/null +++ b/frontend/src/icons/CaretRight.tsx @@ -0,0 +1,13 @@ +export function CaretRight(props: {fill: string, size?: number}) { + return ( + + + + ); +} diff --git a/frontend/src/icons/CopyIcon.tsx b/frontend/src/icons/CopyIcon.tsx index 0965d35..9a8b68c 100644 --- a/frontend/src/icons/CopyIcon.tsx +++ b/frontend/src/icons/CopyIcon.tsx @@ -1,5 +1,5 @@ export function CopyIcon(props: {fill: string}) { return ( - + ); } diff --git a/frontend/src/icons/DocxIcon.tsx b/frontend/src/icons/DocxIcon.tsx index d8d1818..98bddb2 100644 --- a/frontend/src/icons/DocxIcon.tsx +++ b/frontend/src/icons/DocxIcon.tsx @@ -1,5 +1,5 @@ export function DocxIcon() { return ( - + ); } diff --git a/frontend/src/icons/HomeIcon.tsx b/frontend/src/icons/HomeIcon.tsx index 42ea841..d8215d0 100644 --- a/frontend/src/icons/HomeIcon.tsx +++ b/frontend/src/icons/HomeIcon.tsx @@ -1,5 +1,5 @@ export function HomeIcon() { return ( - + ); } diff --git a/frontend/src/icons/KeyIcon.tsx b/frontend/src/icons/KeyIcon.tsx index ba82e6c..d174d14 100644 --- a/frontend/src/icons/KeyIcon.tsx +++ b/frontend/src/icons/KeyIcon.tsx @@ -1,5 +1,5 @@ export function KeyIcon() { return ( - + ); } diff --git a/frontend/src/icons/MagnifyingGlassIcon.tsx b/frontend/src/icons/MagnifyingGlassIcon.tsx index df3e72b..cac3e4a 100644 --- a/frontend/src/icons/MagnifyingGlassIcon.tsx +++ b/frontend/src/icons/MagnifyingGlassIcon.tsx @@ -1,5 +1,5 @@ export function MagnifyingGlassIcon(props: {fill: string}) { return ( - + ); } diff --git a/frontend/src/icons/PaletteIcon.tsx b/frontend/src/icons/PaletteIcon.tsx index c491788..cf39f5d 100644 --- a/frontend/src/icons/PaletteIcon.tsx +++ b/frontend/src/icons/PaletteIcon.tsx @@ -1,5 +1,5 @@ export function PaletteIcon() { return ( - + ); } diff --git a/frontend/src/icons/ScanIcon.tsx b/frontend/src/icons/ScanIcon.tsx index aae8fd1..c736113 100644 --- a/frontend/src/icons/ScanIcon.tsx +++ b/frontend/src/icons/ScanIcon.tsx @@ -1,5 +1,5 @@ export function ScanIcon() { return ( - + ); } diff --git a/frontend/src/icons/StackIcon.tsx b/frontend/src/icons/StackIcon.tsx index e32b4be..d8284a4 100644 --- a/frontend/src/icons/StackIcon.tsx +++ b/frontend/src/icons/StackIcon.tsx @@ -1,5 +1,5 @@ export function StackIcon() { return ( - + ); } diff --git a/frontend/src/icons/TrashIcon.tsx b/frontend/src/icons/TrashIcon.tsx index 681ab9b..9a231f7 100644 --- a/frontend/src/icons/TrashIcon.tsx +++ b/frontend/src/icons/TrashIcon.tsx @@ -1,5 +1,5 @@ export function TrashIcon(props: {fill: string}) { return ( - + ); } diff --git a/frontend/src/icons/XIcon.tsx b/frontend/src/icons/XIcon.tsx index 52c716f..0211d7e 100644 --- a/frontend/src/icons/XIcon.tsx +++ b/frontend/src/icons/XIcon.tsx @@ -1,6 +1,6 @@ export function XIcon(props: {fill: string}) { return ( - + ); }