From f760c7c59fb8145071a3e459ec0fddca395ced3c Mon Sep 17 00:00:00 2001 From: Matt <1009003+tantaman@users.noreply.github.com> Date: Fri, 8 Dec 2023 14:23:38 -0500 Subject: [PATCH] change up comparator to debug this overwrite problem --- client/src/issue/issue.ts | 24 ++++++++++++------------ client/src/materialite/db.ts | 34 ++++++++++++++++++++++++++++++---- client/src/reducer.ts | 34 ---------------------------------- 3 files changed, 42 insertions(+), 50 deletions(-) delete mode 100644 client/src/reducer.ts diff --git a/client/src/issue/issue.ts b/client/src/issue/issue.ts index 4753bac..53bddeb 100644 --- a/client/src/issue/issue.ts +++ b/client/src/issue/issue.ts @@ -10,20 +10,20 @@ import { } from 'shared'; import {z} from 'zod'; -export const priorityOrderValues: Record = { - URGENT: '1', - HIGH: '2', - MEDIUM: '3', - LOW: '4', - NONE: '5', +export const priorityOrderValues: Record = { + URGENT: 1, + HIGH: 2, + MEDIUM: 3, + LOW: 4, + NONE: 5, }; -export const statusOrderValues: Record = { - BACKLOG: '1', - TODO: '2', - IN_PROGRESS: '3', - DONE: '4', - CANCELED: '5', +export const statusOrderValues: Record = { + BACKLOG: 1, + TODO: 2, + IN_PROGRESS: 3, + DONE: 4, + CANCELED: 5, }; export enum Filter { diff --git a/client/src/materialite/db.ts b/client/src/materialite/db.ts index d6fb6fe..9bcfbb0 100644 --- a/client/src/materialite/db.ts +++ b/client/src/materialite/db.ts @@ -1,7 +1,7 @@ import {Materialite} from '@vlcn.io/materialite'; import {MutableSetSource} from '@vlcn.io/materialite/dist/sources/MutableSetSource'; import {Issue, Order, orders} from 'shared'; -import {getOrderValue} from '../reducer'; +import {priorityOrderValues, statusOrderValues} from '../issue/issue'; const m = new Materialite(); const issueComparators = Object.fromEntries( @@ -9,9 +9,35 @@ const issueComparators = Object.fromEntries( return [ order, (l: Issue, r: Issue) => { - const lValue = getOrderValue(order, l); - const rValue = getOrderValue(order, r); - return lValue < rValue ? -1 : lValue > rValue ? 1 : 0; + let comp = 0; + switch (order) { + case 'CREATED': + comp = r.created - l.created; + break; + case 'MODIFIED': + comp = r.modified - l.modified; + break; + case 'STATUS': + comp = statusOrderValues[l.status] - statusOrderValues[r.status]; + if (comp === 0) { + comp = r.modified - l.modified; + } + break; + case 'PRIORITY': + comp = + priorityOrderValues[l.priority] - priorityOrderValues[r.priority]; + if (comp === 0) { + comp = r.modified - l.modified; + } + break; + case 'KANBAN': + comp = l.kanbanOrder.localeCompare(r.kanbanOrder); + break; + } + if (comp === 0) { + comp = l.id.localeCompare(r.id); + } + return comp; }, ] as const; }), diff --git a/client/src/reducer.ts b/client/src/reducer.ts deleted file mode 100644 index ec9d580..0000000 --- a/client/src/reducer.ts +++ /dev/null @@ -1,34 +0,0 @@ -import {Issue, Order} from 'shared'; -import { - priorityOrderValues, - reverseTimestampSortKey, - statusOrderValues, -} from './issue/issue'; - -export function getOrderValue(issueOrder: Order, issue: Issue): string { - let orderValue: string; - switch (issueOrder) { - case 'CREATED': - orderValue = reverseTimestampSortKey(issue.created, issue.id); - break; - case 'MODIFIED': - orderValue = reverseTimestampSortKey(issue.modified, issue.id); - break; - case 'STATUS': - orderValue = - statusOrderValues[issue.status] + - '-' + - reverseTimestampSortKey(issue.modified, issue.id); - break; - case 'PRIORITY': - orderValue = - priorityOrderValues[issue.priority] + - '-' + - reverseTimestampSortKey(issue.modified, issue.id); - break; - case 'KANBAN': - orderValue = issue.kanbanOrder + '-' + issue.id; - break; - } - return orderValue; -}