mirror of
https://github.com/supabase/supabase.git
synced 2026-06-16 11:58:16 +08:00
## I have read the [CONTRIBUTING.md](https://github.com/supabase/supabase/blob/master/CONTRIBUTING.md) file. YES ## What kind of change does this PR introduce? This is a prototype for private apps UI. There are no endpoints at the minute, just wanted to see what a potential flow could look like.
24 lines
728 B
TypeScript
24 lines
728 B
TypeScript
import type { PrivateApp } from '../PrivateApps.types'
|
|
import type { AppsSort } from './Apps.types'
|
|
|
|
export function handleSortChange(
|
|
currentSort: AppsSort,
|
|
column: string,
|
|
setSort: (s: AppsSort) => void
|
|
) {
|
|
const [currentCol, currentOrder] = currentSort.split(':')
|
|
if (currentCol === column) {
|
|
setSort(`${column}:${currentOrder === 'asc' ? 'desc' : 'asc'}` as AppsSort)
|
|
} else {
|
|
setSort(`${column}:asc` as AppsSort)
|
|
}
|
|
}
|
|
|
|
export function sortApps(apps: PrivateApp[], sort: AppsSort): PrivateApp[] {
|
|
const [, order] = sort.split(':')
|
|
return [...apps].sort((a, b) => {
|
|
const diff = new Date(a.created_at).getTime() - new Date(b.created_at).getTime()
|
|
return order === 'asc' ? diff : -diff
|
|
})
|
|
}
|