Enhance Content Management: Add sector name to ContentSerializer, improve Content view with pagination and search filters, and refactor Content page for better data handling and display.
This commit is contained in:
@@ -1451,10 +1451,22 @@ export async function deleteAuthorProfile(id: number): Promise<void> {
|
||||
}
|
||||
|
||||
// Content API
|
||||
export interface ContentFilters {
|
||||
search?: string;
|
||||
status?: string;
|
||||
task_id?: number;
|
||||
page?: number;
|
||||
page_size?: number;
|
||||
ordering?: string;
|
||||
site_id?: number;
|
||||
sector_id?: number;
|
||||
}
|
||||
|
||||
export interface Content {
|
||||
id: number;
|
||||
task: number;
|
||||
task_title?: string | null;
|
||||
sector_name?: string | null;
|
||||
title?: string | null;
|
||||
meta_title?: string | null;
|
||||
meta_description?: string | null;
|
||||
@@ -1477,13 +1489,35 @@ export interface ContentResponse {
|
||||
results: Content[];
|
||||
}
|
||||
|
||||
export async function fetchContent(filters?: {
|
||||
task_id?: number;
|
||||
page?: number;
|
||||
}): Promise<ContentResponse> {
|
||||
export async function fetchContent(filters: ContentFilters = {}): Promise<ContentResponse> {
|
||||
const params = new URLSearchParams();
|
||||
if (filters?.task_id) params.append('task_id', filters.task_id.toString());
|
||||
if (filters?.page) params.append('page', filters.page.toString());
|
||||
|
||||
// Automatically add active site filter if not explicitly provided
|
||||
if (!filters.site_id) {
|
||||
const activeSiteId = getActiveSiteId();
|
||||
if (activeSiteId) {
|
||||
filters.site_id = activeSiteId;
|
||||
}
|
||||
}
|
||||
|
||||
// Automatically add active sector filter if not explicitly provided
|
||||
if (filters.sector_id === undefined) {
|
||||
const activeSectorId = getActiveSectorId();
|
||||
if (activeSectorId !== null && activeSectorId !== undefined) {
|
||||
filters.sector_id = activeSectorId;
|
||||
}
|
||||
}
|
||||
|
||||
if (filters.search) params.append('search', filters.search);
|
||||
if (filters.status) params.append('status', filters.status);
|
||||
if (filters.task_id) params.append('task_id', filters.task_id.toString());
|
||||
if (filters.site_id) params.append('site_id', filters.site_id.toString());
|
||||
if (filters.sector_id) params.append('sector_id', filters.sector_id.toString());
|
||||
if (filters.page) params.append('page', filters.page.toString());
|
||||
if (filters.page_size !== undefined && filters.page_size !== null) {
|
||||
params.append('page_size', filters.page_size.toString());
|
||||
}
|
||||
if (filters.ordering) params.append('ordering', filters.ordering);
|
||||
|
||||
const queryString = params.toString();
|
||||
return fetchAPI(`/v1/writer/content/${queryString ? `?${queryString}` : ''}`);
|
||||
|
||||
Reference in New Issue
Block a user