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>
|
||||
|
||||
Reference in New Issue
Block a user