feat: entry editor at /content/:key/new and /content/:key/:id
This commit is contained in:
1 parent
91d916fb74
commit
fba20f83c5
94 files changed
+7116
-423
No files matched your search
@@ -0,0 +1,34 @@
|
||||
import { ref, watch } from 'vue'
|
||||
import { useUserLookup } from '@/composables/useUserLookup'
|
||||
import type { ContentEntry } from '@/lib/contentTypes'
|
||||
|
||||
function authorIds(entry: ContentEntry | null) {
|
||||
return entry ? [entry.created_by, entry.updated_by].filter((id) => id > 0) : []
|
||||
}
|
||||
|
||||
export function useEntryNames(entry: () => ContentEntry | null) {
|
||||
const { lookupUsers } = useUserLookup()
|
||||
const names = ref<Record<number, string>>({})
|
||||
const requested = new Set<number>()
|
||||
|
||||
async function resolve() {
|
||||
const wanted = [...new Set(authorIds(entry()))].filter((id) => !requested.has(id))
|
||||
if (wanted.length === 0) {
|
||||
return
|
||||
}
|
||||
wanted.forEach((id) => requested.add(id))
|
||||
try {
|
||||
const users = await lookupUsers(wanted)
|
||||
names.value = {
|
||||
...names.value,
|
||||
...Object.fromEntries(users.map((user) => [user.id, user.display_name])),
|
||||
}
|
||||
} catch {
|
||||
wanted.forEach((id) => requested.delete(id))
|
||||
}
|
||||
}
|
||||
|
||||
watch(() => authorIds(entry()).join(','), resolve, { immediate: true })
|
||||
|
||||
return names
|
||||
}
|
||||
Reference in new issue
Block a user