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:
parent
8b9ab93856
commit
eb16815f91
@ -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,
|
||||
}));
|
||||
|
||||
@ -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,
|
||||
}));
|
||||
|
||||
@ -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({});
|
||||
|
||||
@ -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 {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user