Skip to content

Commit

Permalink
feat: fix sorting
Browse files Browse the repository at this point in the history
  • Loading branch information
zugdev committed Dec 12, 2024
1 parent 131e0c0 commit 97f4fdc
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 33 deletions.
2 changes: 1 addition & 1 deletion src/home/sorting/generate-sorting-buttons.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { SortingManager } from "./sorting-manager";

export const SORTING_OPTIONS = ["priority", "reason", "freshness"] as const;
export const SORTING_OPTIONS = ["priority", "oldest"] as const;
export type Sorting = (typeof SORTING_OPTIONS)[number];

export function generateSortingToolbar() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { GitHubAggregated } from "../github-types";

export function sortByFreshness(tasks: GitHubAggregated[]) {
return tasks.sort((a, b) => {
export function sortByOldest(tasks: GitHubAggregated[]) {
return tasks.sort((b,a) => {
const dateA = new Date(a.notification.updated_at);
const dateB = new Date(b.notification.updated_at);
return dateB.getTime() - dateA.getTime();
Expand Down
19 changes: 0 additions & 19 deletions src/home/sorting/sort-by-reason.ts

This file was deleted.

9 changes: 3 additions & 6 deletions src/home/sorting/sort-by.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
import { GitHubAggregated } from "../github-types";
import { SORTING_OPTIONS } from "./generate-sorting-buttons";
import { sortByReason } from "./sort-by-reason";
import { sortByPriority } from "./sort-by-priority";
import { sortByFreshness } from "./sort-by-freshness";
import { sortByOldest } from "./sort-by-oldest";

export function sortBy(tasks: GitHubAggregated[], sortBy: (typeof SORTING_OPTIONS)[number]){
switch (sortBy) {
case "priority":
return sortByPriority(tasks);
case "freshness":
return sortByFreshness(tasks);
case "reason":
return sortByReason(tasks);
case "oldest":
return sortByOldest(tasks);
default:
return tasks;
}
Expand Down
8 changes: 3 additions & 5 deletions src/home/sorting/sort-controller.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
import { GitHubAggregated, GitHubNotifications } from "../github-types";
import { GitHubAggregated } from "../github-types";
import { Sorting } from "./generate-sorting-buttons";
import { sortBy } from "./sort-by";
import { sortByPriority } from "./sort-by-priority";
import { sortByFreshness } from "./sort-by-freshness";
import { sortByReason } from "./sort-by-reason";
import { sortByOldest } from "./sort-by-oldest";

export function sortIssuesController(tasks: GitHubAggregated[], sorting?: Sorting, options = { ordering: "normal" }) {
let sortedNotifications = tasks;

if (sorting) {
sortedNotifications = sortBy(sortedNotifications, sorting);
} else {
const sortedByReason = sortByReason(sortedNotifications); // draw criteria
const sortedByFreshness = sortByFreshness(sortedByReason); // oldest first
const sortedByFreshness = sortByOldest(sortedNotifications); // oldest first
const sortedByPriority = sortByPriority(sortedByFreshness); // highest priority first
sortedNotifications = sortedByPriority;
}
Expand Down

0 comments on commit 97f4fdc

Please sign in to comment.