b31f7e6f34
Mirror to GitHub / mirror (push) Successful in 38s
Test and Lint / backend-test (push) Successful in 1m26s
continuous-integration/drone/push Build is passing
Test and Lint / frontend-test (push) Successful in 2m9s
Version and Release / version-bump (push) Successful in 48s
Version and Release / trigger-drone (push) Successful in 3s
Gallery Feedback Features: - Add feedback system allowing ratings, likes, comments, and favorites on photos - Implement admin controls for enabling/disabling feedback per event - Add content moderation with word filters and spam detection - Implement rate limiting to prevent abuse (10 requests/15min per type) - Create comprehensive admin interface for feedback management - Add analytics dashboard for feedback insights - Export feedback data when archiving events Frontend Components: - PhotoRating: 5-star rating system with optimistic updates - PhotoLikes: Like/unlike with animation - PhotoComments: Threaded comments with moderation - PhotoFavorites: Bookmark functionality - FeedbackSettings: Admin configuration panel - EventFeedbackPage: Complete management interface Backend Implementation: - Database migration 033: 4 new tables for feedback system - RESTful API with proper authorization - Guest identification via SHA256(IP+UserAgent) - Automatic backup integration - Email notification support Backup Version Tracking: - Migration 034: Add version columns to backup tables - Track app version, Node.js version, and DB schema version - Create restore_history table for tracking restore attempts - Add version compatibility checking for safe restores - Configurable version matching requirements Security & Performance: - Input validation and sanitization - Rate limiting per feedback type - Content moderation system - Optimistic UI updates - Efficient database queries with proper indexes 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
93 lines
2.8 KiB
TypeScript
93 lines
2.8 KiB
TypeScript
import React, { useState } from 'react';
|
|
import { Bookmark } from 'lucide-react';
|
|
import { useTranslation } from 'react-i18next';
|
|
import { useMutation, useQueryClient } from '@tanstack/react-query';
|
|
import { feedbackService } from '../../services/feedback.service';
|
|
import { toast } from 'react-toastify';
|
|
|
|
interface PhotoFavoritesProps {
|
|
photoId: string;
|
|
gallerySlug: string;
|
|
isFavorited: boolean;
|
|
favoriteCount: number;
|
|
isEnabled: boolean;
|
|
onFavoriteChange?: (favorited: boolean) => void;
|
|
}
|
|
|
|
export const PhotoFavorites: React.FC<PhotoFavoritesProps> = ({
|
|
photoId,
|
|
gallerySlug,
|
|
isFavorited,
|
|
favoriteCount,
|
|
isEnabled,
|
|
onFavoriteChange
|
|
}) => {
|
|
const { t } = useTranslation();
|
|
const queryClient = useQueryClient();
|
|
const [isSubmitting, setIsSubmitting] = useState(false);
|
|
const [animating, setAnimating] = useState(false);
|
|
|
|
const submitFavoriteMutation = useMutation({
|
|
mutationFn: () =>
|
|
feedbackService.submitFeedback(gallerySlug, photoId, {
|
|
feedback_type: 'favorite'
|
|
}),
|
|
onMutate: async () => {
|
|
setIsSubmitting(true);
|
|
setAnimating(true);
|
|
// Optimistic update
|
|
if (onFavoriteChange) {
|
|
onFavoriteChange(!isFavorited);
|
|
}
|
|
},
|
|
onSuccess: () => {
|
|
queryClient.invalidateQueries({ queryKey: ['photo-feedback', gallerySlug, photoId] });
|
|
},
|
|
onError: (error: any) => {
|
|
// Revert optimistic update
|
|
if (onFavoriteChange) {
|
|
onFavoriteChange(isFavorited);
|
|
}
|
|
if (error.response?.status === 429) {
|
|
toast.error(t('feedback.rateLimited', 'Please wait before favoriting again'));
|
|
} else {
|
|
toast.error(t('feedback.favoriteError', 'Failed to update favorite'));
|
|
}
|
|
},
|
|
onSettled: () => {
|
|
setIsSubmitting(false);
|
|
setTimeout(() => setAnimating(false), 300);
|
|
}
|
|
});
|
|
|
|
const handleFavoriteClick = () => {
|
|
if (!isEnabled || isSubmitting) return;
|
|
submitFavoriteMutation.mutate();
|
|
};
|
|
|
|
if (!isEnabled) return null;
|
|
|
|
return (
|
|
<button
|
|
onClick={handleFavoriteClick}
|
|
disabled={isSubmitting}
|
|
className={`group flex items-center gap-2 px-3 py-2 rounded-lg transition-all ${
|
|
isFavorited
|
|
? 'bg-amber-50 text-amber-600 hover:bg-amber-100'
|
|
: 'bg-neutral-50 text-neutral-600 hover:bg-neutral-100'
|
|
} ${isSubmitting ? 'cursor-not-allowed opacity-50' : 'cursor-pointer'}`}
|
|
aria-label={isFavorited ? t('feedback.unfavorite', 'Remove from favorites') : t('feedback.favorite', 'Add to favorites')}
|
|
>
|
|
<Bookmark
|
|
className={`w-5 h-5 transition-all ${
|
|
animating ? 'scale-125' : 'scale-100'
|
|
} ${
|
|
isFavorited ? 'fill-current' : 'group-hover:scale-110'
|
|
}`}
|
|
/>
|
|
<span className="text-sm font-medium">
|
|
{favoriteCount > 0 ? favoriteCount : ''}
|
|
</span>
|
|
</button>
|
|
);
|
|
}; |