Füge Archivierungs-Funktion für Kommentare hinzu und fixe initiales Laden
- Archivierungs-Funktionalität: Kuratoren können Kommentare archivieren - archived-Flag in CuratorCommentRecipient hinzugefügt - API-Route für Archivieren: /api/curator-comments/[id]/archive - Kommentare werden beim initialen Laden automatisch abgerufen - Archivierte Kommentare werden nicht mehr in der Liste angezeigt - Archivieren-Button in der UI hinzugefügt - Migration für archived-Feld - Übersetzungen für Archivierung (DE/EN)
This commit is contained in:
@@ -133,16 +133,11 @@ export default function CuratorPageClient() {
|
||||
}
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
if (showComments && isAuthenticated) {
|
||||
fetchComments();
|
||||
}
|
||||
}, [showComments, isAuthenticated]);
|
||||
|
||||
const bootstrapCuratorData = async () => {
|
||||
try {
|
||||
setLoading(true);
|
||||
await Promise.all([fetchCuratorInfo(), fetchSongs(), fetchGenres(), fetchSpecials()]);
|
||||
await Promise.all([fetchCuratorInfo(), fetchSongs(), fetchGenres(), fetchSpecials(), fetchComments()]);
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
@@ -184,6 +179,24 @@ export default function CuratorPageClient() {
|
||||
}
|
||||
};
|
||||
|
||||
const archiveComment = async (commentId: number) => {
|
||||
try {
|
||||
const res = await fetch(`/api/curator-comments/${commentId}/archive`, {
|
||||
method: 'POST',
|
||||
headers: getCuratorAuthHeaders(),
|
||||
});
|
||||
if (res.ok) {
|
||||
// Remove comment from local state (archived comments are not shown)
|
||||
setComments(comments.filter(c => c.id !== commentId));
|
||||
} else {
|
||||
setMessage(t('archiveCommentError'));
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error archiving comment:', error);
|
||||
setMessage(t('archiveCommentError'));
|
||||
}
|
||||
};
|
||||
|
||||
const fetchCuratorInfo = async () => {
|
||||
const res = await fetch('/api/curator/me', {
|
||||
headers: getCuratorAuthHeaders(),
|
||||
@@ -708,9 +721,6 @@ export default function CuratorPageClient() {
|
||||
<button
|
||||
onClick={() => {
|
||||
setShowComments(!showComments);
|
||||
if (!showComments && comments.length === 0) {
|
||||
fetchComments();
|
||||
}
|
||||
}}
|
||||
style={{
|
||||
padding: '0.4rem 0.8rem',
|
||||
@@ -790,9 +800,31 @@ export default function CuratorPageClient() {
|
||||
<div style={{ marginBottom: '0.5rem', fontSize: '0.85rem', color: '#6b7280' }}>
|
||||
{comment.puzzle.song.title} - {comment.puzzle.song.artist}
|
||||
</div>
|
||||
<div style={{ fontSize: '0.9rem', whiteSpace: 'pre-wrap' }}>
|
||||
<div style={{ fontSize: '0.9rem', whiteSpace: 'pre-wrap', marginBottom: '0.5rem' }}>
|
||||
{comment.message}
|
||||
</div>
|
||||
<div style={{ display: 'flex', justifyContent: 'flex-end', gap: '0.5rem', marginTop: '0.5rem' }}>
|
||||
<button
|
||||
onClick={(e) => {
|
||||
e.stopPropagation();
|
||||
if (confirm(t('archiveCommentConfirm'))) {
|
||||
archiveComment(comment.id);
|
||||
}
|
||||
}}
|
||||
style={{
|
||||
padding: '0.4rem 0.8rem',
|
||||
borderRadius: '0.25rem',
|
||||
border: '1px solid #d1d5db',
|
||||
background: '#fff',
|
||||
color: '#6b7280',
|
||||
cursor: 'pointer',
|
||||
fontSize: '0.85rem',
|
||||
}}
|
||||
title={t('archiveComment')}
|
||||
>
|
||||
{t('archiveComment')}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
|
||||
Reference in New Issue
Block a user