Fix blog hooks: unwrap API response envelope for authors and categories

The API returns { authors: {...} } and { categories: [...] } but hooks
were expecting the unwrapped values directly. Also add defensive guards
in components for undefined props during initial render.

Bunker Admin
This commit is contained in:
bunker-admin 2026-03-27 13:33:47 -06:00
parent 8b9ab93856
commit eb16815f91
4 changed files with 8 additions and 8 deletions

View File

@ -42,12 +42,12 @@ export function BlogFrontmatterPanel({
if (!frontmatter) return null;
const authorOptions = Object.entries(authors).map(([key, entry]) => ({
const authorOptions = Object.entries(authors || {}).map(([key, entry]) => ({
label: entry.name,
value: key,
}));
const categoryOptions = categories.map((cat) => ({
const categoryOptions = (categories || []).map((cat) => ({
label: cat,
value: cat,
}));

View File

@ -42,12 +42,12 @@ export function NewBlogPostModal({
const dateStr = dateValue ? dateValue.format('YYYY-MM-DD') : dayjs().format('YYYY-MM-DD');
const previewFilename = slug ? `blog/posts/${dateStr}-${slug}.md` : '';
const authorOptions = Object.entries(authors).map(([key, entry]) => ({
const authorOptions = Object.entries(authors || {}).map(([key, entry]) => ({
label: entry.name,
value: key,
}));
const categoryOptions = categories.map((cat) => ({
const categoryOptions = (categories || []).map((cat) => ({
label: cat,
value: cat,
}));

View File

@ -29,8 +29,8 @@ export function useBlogAuthors(): UseBlogAuthorsReturn {
const refetch = useCallback(async () => {
setLoading(true);
try {
const res = await api.get<AuthorsMap>('/docs/blog/authors');
setAuthors(res.data);
const res = await api.get<{ authors: AuthorsMap }>('/docs/blog/authors');
setAuthors(res.data.authors ?? {});
} catch {
// If no authors file exists yet, keep empty
setAuthors({});

View File

@ -14,8 +14,8 @@ export function useBlogCategories(): UseBlogCategoriesReturn {
const refetch = useCallback(async () => {
setLoading(true);
try {
const res = await api.get<string[]>('/docs/blog/categories');
setCategories(res.data);
const res = await api.get<{ categories: string[] }>('/docs/blog/categories');
setCategories(res.data.categories ?? []);
} catch {
setCategories([]);
} finally {