Mirror of https://github.com/roostorg/osprey github.com/roostorg/osprey
2
fork

Configure Feed

Select the types of activity you want to include in your feed.

at main 21 lines 689 B view raw
1import { Label } from '../types/LabelTypes'; 2 3export function sortLabelsChronologically(labels: Label[]) { 4 const labelsByLatestTimestamp: Array<[string, Label]> = labels.map((label) => { 5 let latestTimestamp: string = ''; 6 7 Object.values(label.reasons).forEach((reason) => { 8 if (latestTimestamp === '' || Date.parse(reason.created_at) - Date.parse(latestTimestamp) > 0) { 9 latestTimestamp = reason.created_at; 10 } 11 }); 12 13 return [latestTimestamp, label]; 14 }); 15 16 const sortedLabels = labelsByLatestTimestamp 17 .sort(([timestampA], [timestampB]) => Date.parse(timestampB) - Date.parse(timestampA)) 18 .map(([_, label]) => label); 19 20 return sortedLabels; 21}