| 19 | export type InstructionSortOption = 'title' | 'lastUpdated'; |
| 20 | |
| 21 | export function sortInstructions<T extends RenderableInstruction>( |
| 22 | items: T[], |
| 23 | sort: InstructionSortOption |
| 24 | ): T[] { |
| 25 | return [...items].sort((a, b) => { |
| 26 | if (sort === 'lastUpdated') { |
| 27 | const dateA = a.lastUpdated ? new Date(a.lastUpdated).getTime() : 0; |
| 28 | const dateB = b.lastUpdated ? new Date(b.lastUpdated).getTime() : 0; |
| 29 | return dateB - dateA; |
| 30 | } |
| 31 | |
| 32 | return a.title.localeCompare(b.title); |
| 33 | }); |
| 34 | } |
| 35 | |
| 36 | export function renderInstructionsHtml( |
| 37 | items: RenderableInstruction[] |