Fixing author page load times
This commit is contained in:
@@ -26,15 +26,11 @@ export default function AuthorDetailPage() {
|
|||||||
setLoading(true);
|
setLoading(true);
|
||||||
const [authorData, storiesResult] = await Promise.all([
|
const [authorData, storiesResult] = await Promise.all([
|
||||||
authorApi.getAuthor(authorId),
|
authorApi.getAuthor(authorId),
|
||||||
storyApi.getStories({ page: 0, size: 1000 }) // Get all stories to filter by author
|
storyApi.getStoriesByAuthor(authorId, { page: 0, size: 100 })
|
||||||
]);
|
]);
|
||||||
|
|
||||||
setAuthor(authorData);
|
setAuthor(authorData);
|
||||||
// Filter stories by this author
|
setStories(storiesResult.content);
|
||||||
const authorStories = storiesResult.content.filter(
|
|
||||||
story => story.authorId === authorId
|
|
||||||
);
|
|
||||||
setStories(authorStories);
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Failed to load author data:', error);
|
console.error('Failed to load author data:', error);
|
||||||
router.push('/authors');
|
router.push('/authors');
|
||||||
|
|||||||
@@ -162,6 +162,11 @@ export const storyApi = {
|
|||||||
return response.data;
|
return response.data;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
getStoriesByAuthor: async (authorId: string, params?: { page?: number; size?: number }): Promise<PagedResult<Story>> => {
|
||||||
|
const response = await api.get(`/stories/author/${authorId}`, { params });
|
||||||
|
return response.data;
|
||||||
|
},
|
||||||
|
|
||||||
getStory: async (id: string): Promise<Story> => {
|
getStory: async (id: string): Promise<Story> => {
|
||||||
const response = await api.get(`/stories/${id}`);
|
const response = await api.get(`/stories/${id}`);
|
||||||
return response.data;
|
return response.data;
|
||||||
|
|||||||
Reference in New Issue
Block a user