Update comment pagination and ignore data files
This commit is contained in:
@@ -175,7 +175,7 @@ export interface Article {
|
||||
|
||||
export const fetchArticles = async (page: number, signal?: AbortSignal): Promise<Article[]> => {
|
||||
try {
|
||||
const response = await fetch(`/api/10_info?page=${page}`, { signal });
|
||||
const response = await fetch(`/api/posts_info?page=${page}`, { signal });
|
||||
if (!response.ok) {
|
||||
throw new Error(`HTTP error! status: ${response.status}`);
|
||||
}
|
||||
@@ -219,15 +219,23 @@ export interface Comment {
|
||||
parent_comment_id: number;
|
||||
}
|
||||
|
||||
export const getComments = async (id: string | number): Promise<Comment[]> => {
|
||||
export interface CommentPage {
|
||||
comments: Comment[];
|
||||
total_pages: number;
|
||||
}
|
||||
|
||||
export const getComments = async (id: string | number, page: number = 1): Promise<CommentPage> => {
|
||||
try {
|
||||
const response = await fetch(`/api/get/comment?id=${id}`);
|
||||
const response = await fetch(`/api/get/comment?id=${id}&page=${page}`);
|
||||
if (!response.ok) {
|
||||
throw new Error(`HTTP error! status: ${response.status}`);
|
||||
}
|
||||
const json = await response.json();
|
||||
if (json.code === 1000 && Array.isArray(json.data)) {
|
||||
return json.data as Comment[];
|
||||
if (json.code === 1000 && json.data && Array.isArray(json.data.comments)) {
|
||||
return {
|
||||
comments: json.data.comments as Comment[],
|
||||
total_pages: Number(json.data.total_pages) || 0,
|
||||
};
|
||||
}
|
||||
throw new Error('Invalid response code or missing data');
|
||||
} catch (error) {
|
||||
|
||||
Reference in New Issue
Block a user