Skip to content

Commit

Permalink
change up comparator to debug this overwrite problem
Browse files Browse the repository at this point in the history
  • Loading branch information
tantaman committed Dec 8, 2023
1 parent 819e1b4 commit f760c7c
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 50 deletions.
24 changes: 12 additions & 12 deletions client/src/issue/issue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,20 @@ import {
} from 'shared';
import {z} from 'zod';

export const priorityOrderValues: Record<Priority, string> = {
URGENT: '1',
HIGH: '2',
MEDIUM: '3',
LOW: '4',
NONE: '5',
export const priorityOrderValues: Record<Priority, number> = {
URGENT: 1,
HIGH: 2,
MEDIUM: 3,
LOW: 4,
NONE: 5,
};

export const statusOrderValues: Record<Status, string> = {
BACKLOG: '1',
TODO: '2',
IN_PROGRESS: '3',
DONE: '4',
CANCELED: '5',
export const statusOrderValues: Record<Status, number> = {
BACKLOG: 1,
TODO: 2,
IN_PROGRESS: 3,
DONE: 4,
CANCELED: 5,
};

export enum Filter {
Expand Down
34 changes: 30 additions & 4 deletions client/src/materialite/db.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,43 @@
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(
orders.map(order => {
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;
}),
Expand Down
34 changes: 0 additions & 34 deletions client/src/reducer.ts

This file was deleted.

0 comments on commit f760c7c

Please sign in to comment.