Yehoshua Sandler c49f8e4d07
refact: generalized back end structs (#1)
* refact: generalized back end structs

* refact: fixed front end type, removed dead code

* removed test image folder

* refact: removed dead structs
2023-05-26 19:23:35 -05:00

39 lines
1.0 KiB
TypeScript

import { entities } from '../../../wailsjs/wailsjs/go/models'
import { SidebarGroup } from './types'
const getNavigationProps = (documents: entities.Document[], groups: entities.Group[]) : SidebarGroup[] => {
const groupsWithDocuments = groups.map(g => {
const childrenDocuments = documents
.filter(d => d.groupId === g.id)
.map(d => ({
id: d.id,
name: d.name,
areas: d.areas?.map(a => ({ id: a.id, name: a.name, order: a.order }))//.sort((a, b) => a.order - b.order)
}))
return {
id: g.id,
name: g.name,
documents: childrenDocuments
}
})
const documentsWithoutGroup = documents
.filter(d => !d.groupId || d.groupId === 'Uncategorized')
.map(d => ({
id: d.id,
name: d.name,
areas: d.areas?.map(a => ({ id: a.id, name: a.name, order: a.order }))//.sort((a, b) => a.order - b.order)
}))
return [
...groupsWithDocuments,
{
id: '',
name: 'Uncategorized',
documents: documentsWithoutGroup
}
]
}
export { getNavigationProps }