feat(contents): enhance user-specific data handling and admin content management
Integrate user-specific fields (`isLiked`, `favoritesCount`) in content APIs and improve `ContentCard` through reactive updates. Add admin-only content deletion support. Refactor services and repository to enrich responses with additional data (author details, tags).
This commit is contained in:
@@ -26,9 +26,14 @@ interface ContentCardProps {
|
||||
export function ContentCard({ content }: ContentCardProps) {
|
||||
const { isAuthenticated } = useAuth();
|
||||
const router = useRouter();
|
||||
const [isLiked, setIsLiked] = React.useState(false);
|
||||
const [isLiked, setIsLiked] = React.useState(content.isLiked || false);
|
||||
const [likesCount, setLikesCount] = React.useState(content.favoritesCount);
|
||||
|
||||
React.useEffect(() => {
|
||||
setIsLiked(content.isLiked || false);
|
||||
setLikesCount(content.favoritesCount);
|
||||
}, [content.isLiked, content.favoritesCount]);
|
||||
|
||||
const handleLike = async (e: React.MouseEvent) => {
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
@@ -54,6 +59,17 @@ export function ContentCard({ content }: ContentCardProps) {
|
||||
}
|
||||
};
|
||||
|
||||
const handleUse = async (e: React.MouseEvent) => {
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
try {
|
||||
await ContentService.incrementUsage(content.id);
|
||||
toast.success("Mème prêt à être utilisé !");
|
||||
} catch (_error) {
|
||||
toast.error("Une erreur est survenue");
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<Card className="overflow-hidden border-none shadow-sm hover:shadow-md transition-shadow">
|
||||
<CardHeader className="p-4 flex flex-row items-center space-y-0 gap-3">
|
||||
@@ -118,7 +134,12 @@ export function ContentCard({ content }: ContentCardProps) {
|
||||
<Share2 className="h-4 w-4" />
|
||||
</Button>
|
||||
</div>
|
||||
<Button size="sm" variant="secondary" className="text-xs h-8">
|
||||
<Button
|
||||
size="sm"
|
||||
variant="secondary"
|
||||
className="text-xs h-8"
|
||||
onClick={handleUse}
|
||||
>
|
||||
Utiliser
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
@@ -61,4 +61,8 @@ export const ContentService = {
|
||||
});
|
||||
return data;
|
||||
},
|
||||
|
||||
async removeAdmin(id: string): Promise<void> {
|
||||
await api.delete(`/contents/${id}/admin`);
|
||||
},
|
||||
};
|
||||
|
||||
@@ -16,6 +16,7 @@ export interface Content {
|
||||
views: number;
|
||||
usageCount: number;
|
||||
favoritesCount: number;
|
||||
isLiked?: boolean;
|
||||
tags: (string | Tag)[];
|
||||
category?: Category;
|
||||
authorId: string;
|
||||
@@ -39,7 +40,7 @@ export interface Category {
|
||||
|
||||
export interface PaginatedResponse<T> {
|
||||
data: T[];
|
||||
total: number;
|
||||
totalCount: number;
|
||||
limit: number;
|
||||
offset: number;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user