/** A column a list is sorted by, and which way. */ export interface ListSort { by: Key; order: 'asc' | 'desc'; } /** * The sort after a click on a column: the same column turns the other * way; another starts the way it reads best (names A to Z, counts and * dates biggest and newest first). * * @param {ListSort} current - The sort now. * @param {string} by - The column clicked. * @param {string[]} ascending - The columns that start A to Z. * @returns {ListSort} */ export const nextSort = ( current: ListSort, by: Key, ascending: readonly Key[] ): ListSort => current.by === by ? { by, order: current.order === 'asc' ? 'desc' : 'asc' } : { by, order: ascending.includes(by) ? 'asc' : 'desc' };