front fix
This commit is contained in:
@@ -26,7 +26,6 @@ import {
|
||||
MessageOutlined
|
||||
} from '@ant-design/icons';
|
||||
import { format } from 'date-fns';
|
||||
import { postsApi } from '../utils/api';
|
||||
|
||||
// API response type definition based on backend structure
|
||||
interface ApiPost {
|
||||
@@ -87,76 +86,58 @@ const PostList: React.FC<PostListProps> = ({ influencerId, projectId }) => {
|
||||
const [platformFilter, setPlatformFilter] = useState<string>('all');
|
||||
const [contentTypeFilter, setContentTypeFilter] = useState<string>('all');
|
||||
const [showFilters, setShowFilters] = useState<boolean>(false);
|
||||
const [totalPosts, setTotalPosts] = useState<number>(0);
|
||||
|
||||
// Fetch posts data
|
||||
useEffect(() => {
|
||||
const fetchPosts = async () => {
|
||||
try {
|
||||
setLoading(true);
|
||||
|
||||
// Build query parameters
|
||||
const params: Record<string, string | number> = {
|
||||
limit: 50,
|
||||
offset: 0
|
||||
};
|
||||
|
||||
if (influencerId) {
|
||||
params.influencer_id = influencerId;
|
||||
const fetchPosts = async () => {
|
||||
try {
|
||||
setLoading(true);
|
||||
|
||||
// Mock data for posts
|
||||
const mockPosts = [
|
||||
{
|
||||
id: '1',
|
||||
title: 'Introduction to React Hooks',
|
||||
content: 'React Hooks are a powerful feature that allows you to use state and other React features without writing a class.',
|
||||
author: 'John Smith',
|
||||
date: '2023-05-15',
|
||||
platform: 'Facebook',
|
||||
status: 'Published',
|
||||
engagement: 85,
|
||||
comments: 12
|
||||
},
|
||||
{
|
||||
id: '2',
|
||||
title: 'Advanced CSS Techniques',
|
||||
content: 'Learn about the latest CSS techniques including Grid, Flexbox, and CSS Variables.',
|
||||
author: 'Sarah Johnson',
|
||||
date: '2023-05-14',
|
||||
platform: 'Twitter',
|
||||
status: 'Draft',
|
||||
engagement: 72,
|
||||
comments: 8
|
||||
},
|
||||
{
|
||||
id: '3',
|
||||
title: 'JavaScript Performance Tips',
|
||||
content: 'Optimize your JavaScript code with these performance tips and best practices.',
|
||||
author: 'Michael Brown',
|
||||
date: '2023-05-13',
|
||||
platform: 'LinkedIn',
|
||||
status: 'Published',
|
||||
engagement: 68,
|
||||
comments: 15
|
||||
}
|
||||
|
||||
if (projectId) {
|
||||
params.project_id = projectId;
|
||||
}
|
||||
|
||||
const response = await postsApi.getPosts(params);
|
||||
|
||||
// Process returned data
|
||||
const apiPosts: ApiPost[] = response.data.posts || [];
|
||||
|
||||
// Transform API posts to frontend format
|
||||
const processedPosts: FrontendPost[] = apiPosts.map((apiPost) => {
|
||||
// Determine content type based on post data
|
||||
let contentType: FrontendPost['contentType'] = 'post';
|
||||
if (apiPost.platform === 'youtube') {
|
||||
contentType = 'video';
|
||||
} else if (
|
||||
apiPost.platform === 'instagram' &&
|
||||
apiPost.post_url?.includes('/reels/')
|
||||
) {
|
||||
contentType = 'reel';
|
||||
}
|
||||
|
||||
return {
|
||||
id: apiPost.post_id,
|
||||
title: apiPost.title || 'Untitled Post',
|
||||
description: apiPost.description || '',
|
||||
author: apiPost.influencer?.name || 'Unknown',
|
||||
authorType: 'influencer',
|
||||
platform: apiPost.platform as FrontendPost['platform'],
|
||||
contentType,
|
||||
timestamp: apiPost.published_at,
|
||||
engagement: {
|
||||
views: apiPost.views_count,
|
||||
likes: apiPost.likes_count,
|
||||
comments: apiPost.comments_count,
|
||||
shares: apiPost.shares_count
|
||||
},
|
||||
url: apiPost.post_url
|
||||
};
|
||||
});
|
||||
|
||||
setPosts(processedPosts);
|
||||
setError(null);
|
||||
} catch (err) {
|
||||
console.error('Failed to fetch posts:', err);
|
||||
setError('Failed to load posts. Please try again later.');
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
fetchPosts();
|
||||
}, [influencerId, projectId]);
|
||||
];
|
||||
|
||||
setTotalPosts(mockPosts.length);
|
||||
setPosts(mockPosts);
|
||||
setLoading(false);
|
||||
} catch (error) {
|
||||
console.error('Error fetching posts:', error);
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
// Filter posts based on selected filters
|
||||
const filteredPosts = posts.filter((post) => {
|
||||
|
||||
Reference in New Issue
Block a user