Commit fbb2ca03 authored by Aryan Noshirvnai's avatar Aryan Noshirvnai

Add a Community review tab to AdminPanel for community-noted songs

Lists songs a super admin still needs to approve or reject after an
uploader edited away from the system's identification (see the Upload
commit) - mirrors the existing soundmark-suggestion review queue tab's
layout, with its own tab badge count.
parent fad9c417
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
"page.title": "Admin", "page.title": "Admin",
"section.soundmarks": "soundmarks", "section.soundmarks": "soundmarks",
"section.reviewQueue": "review queue", "section.reviewQueue": "review queue",
"section.community": "community",
"section.users": "users", "section.users": "users",
"tier.major": "Major landmark", "tier.major": "Major landmark",
"tier.business": "Business", "tier.business": "Business",
...@@ -64,6 +65,8 @@ ...@@ -64,6 +65,8 @@
"empty.noTracks": "No tracks yet - add one to get this business playing.", "empty.noTracks": "No tracks yet - add one to get this business playing.",
"empty.noSoundmarks": "No soundmarks yet - create the first one.", "empty.noSoundmarks": "No soundmarks yet - create the first one.",
"empty.reviewCaughtUp": "Nothing pending — you're all caught up.", "empty.reviewCaughtUp": "Nothing pending — you're all caught up.",
"empty.communityCaughtUp": "No community-noted songs waiting on review.",
"review.systemConfidence": "{{percent}}% system confidence",
"empty.noUsers": "No users found.", "empty.noUsers": "No users found.",
"error.loadFailed": "Failed to load admin data", "error.loadFailed": "Failed to load admin data",
"error.searchFailed": "Failed to search users", "error.searchFailed": "Failed to search users",
...@@ -81,6 +84,7 @@ ...@@ -81,6 +84,7 @@
"error.clearSuspensionFailed": "Failed to clear suspension", "error.clearSuspensionFailed": "Failed to clear suspension",
"error.resetPasswordFailed": "Failed to reset password", "error.resetPasswordFailed": "Failed to reset password",
"error.reviewSuggestionFailed": "Failed to review suggestion", "error.reviewSuggestionFailed": "Failed to review suggestion",
"error.reviewLibrarySongFailed": "Failed to review song",
"confirm.deleteSoundmark": "Delete \"{{name}}\"? This can't be undone.", "confirm.deleteSoundmark": "Delete \"{{name}}\"? This can't be undone.",
"confirm.deactivateAccount": "Deactivate this account? They will be signed out immediately and unable to log back in until reactivated." "confirm.deactivateAccount": "Deactivate this account? They will be signed out immediately and unable to log back in until reactivated."
} }
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
"page.title": "مدیریت", "page.title": "مدیریت",
"section.soundmarks": "نشان‌های صوتی", "section.soundmarks": "نشان‌های صوتی",
"section.reviewQueue": "صف بررسی", "section.reviewQueue": "صف بررسی",
"section.community": "انجمن",
"section.users": "کاربران", "section.users": "کاربران",
"tier.major": "نشان اصلی", "tier.major": "نشان اصلی",
"tier.business": "کسب‌وکار", "tier.business": "کسب‌وکار",
...@@ -64,6 +65,8 @@ ...@@ -64,6 +65,8 @@
"empty.noTracks": "هنوز آهنگی نیست - یکی اضافه کن تا این کسب‌وکار شروع به پخش کند.", "empty.noTracks": "هنوز آهنگی نیست - یکی اضافه کن تا این کسب‌وکار شروع به پخش کند.",
"empty.noSoundmarks": "هنوز نشان صوتی نیست - اولی را بساز.", "empty.noSoundmarks": "هنوز نشان صوتی نیست - اولی را بساز.",
"empty.reviewCaughtUp": "چیزی در انتظار نیست — همه‌چیز به‌روز است.", "empty.reviewCaughtUp": "چیزی در انتظار نیست — همه‌چیز به‌روز است.",
"empty.communityCaughtUp": "هیچ آهنگ یادداشت‌شده‌ای در انتظار بررسی نیست.",
"review.systemConfidence": "{{percent}}٪ اطمینان سیستم",
"empty.noUsers": "کاربری پیدا نشد.", "empty.noUsers": "کاربری پیدا نشد.",
"error.loadFailed": "بارگذاری داده‌های مدیریت ممکن نشد", "error.loadFailed": "بارگذاری داده‌های مدیریت ممکن نشد",
"error.searchFailed": "جست‌وجوی کاربران ممکن نشد", "error.searchFailed": "جست‌وجوی کاربران ممکن نشد",
...@@ -81,6 +84,7 @@ ...@@ -81,6 +84,7 @@
"error.clearSuspensionFailed": "پایان تعلیق ممکن نشد", "error.clearSuspensionFailed": "پایان تعلیق ممکن نشد",
"error.resetPasswordFailed": "بازنشانی رمز عبور ممکن نشد", "error.resetPasswordFailed": "بازنشانی رمز عبور ممکن نشد",
"error.reviewSuggestionFailed": "بررسی پیشنهاد ممکن نشد", "error.reviewSuggestionFailed": "بررسی پیشنهاد ممکن نشد",
"error.reviewLibrarySongFailed": "بررسی آهنگ ممکن نشد",
"confirm.deleteSoundmark": "«{{name}}» حذف شود؟ این کار قابل بازگشت نیست.", "confirm.deleteSoundmark": "«{{name}}» حذف شود؟ این کار قابل بازگشت نیست.",
"confirm.deactivateAccount": "این حساب غیرفعال شود؟ کاربر فوراً از حساب خارج می‌شود و تا زمان فعال‌سازی دوباره نمی‌تواند وارد شود." "confirm.deactivateAccount": "این حساب غیرفعال شود؟ کاربر فوراً از حساب خارج می‌شود و تا زمان فعال‌سازی دوباره نمی‌تواند وارد شود."
} }
...@@ -63,6 +63,7 @@ const SUGGESTION: soundmarksApi.SoundmarkSuggestion = { ...@@ -63,6 +63,7 @@ const SUGGESTION: soundmarksApi.SoundmarkSuggestion = {
const PLAIN_USER: soundmarksApi.AdminUser = { id: 7, username: 'alex', phone_number: '+15551234', role: 'user', is_active: true, suspended_until: null } const PLAIN_USER: soundmarksApi.AdminUser = { id: 7, username: 'alex', phone_number: '+15551234', role: 'user', is_active: true, suspended_until: null }
function mockEmptyQueue() { function mockEmptyQueue() {
vi.spyOn(libraryApi, 'getLibraryReviewQueue').mockResolvedValue({ status: 'success', songs: [] })
return vi.spyOn(soundmarksApi, 'getReviewQueue').mockResolvedValue({ status: 'success', suggestions: [] }) return vi.spyOn(soundmarksApi, 'getReviewQueue').mockResolvedValue({ status: 'success', suggestions: [] })
} }
...@@ -380,6 +381,7 @@ describe('AdminPanel', () => { ...@@ -380,6 +381,7 @@ describe('AdminPanel', () => {
vi.spyOn(soundmarksApi, 'getAllSoundmarks').mockResolvedValue({ status: 'success', soundmarks: [LANDMARK] }) vi.spyOn(soundmarksApi, 'getAllSoundmarks').mockResolvedValue({ status: 'success', soundmarks: [LANDMARK] })
vi.spyOn(soundmarksApi, 'listUsers').mockResolvedValue({ status: 'success', users: [] }) vi.spyOn(soundmarksApi, 'listUsers').mockResolvedValue({ status: 'success', users: [] })
vi.spyOn(soundmarksApi, 'getReviewQueue').mockResolvedValue({ status: 'success', suggestions: [SUGGESTION] }) vi.spyOn(soundmarksApi, 'getReviewQueue').mockResolvedValue({ status: 'success', suggestions: [SUGGESTION] })
vi.spyOn(libraryApi, 'getLibraryReviewQueue').mockResolvedValue({ status: 'success', songs: [] })
const approve = vi.spyOn(soundmarksApi, 'approveSuggestion').mockResolvedValue({ const approve = vi.spyOn(soundmarksApi, 'approveSuggestion').mockResolvedValue({
status: 'success', status: 'success',
suggestion: { ...SUGGESTION, status: 'approved' }, suggestion: { ...SUGGESTION, status: 'approved' },
...@@ -396,4 +398,59 @@ describe('AdminPanel', () => { ...@@ -396,4 +398,59 @@ describe('AdminPanel', () => {
await waitFor(() => expect(approve).toHaveBeenCalledWith(SUGGESTION.id)) await waitFor(() => expect(approve).toHaveBeenCalledWith(SUGGESTION.id))
await waitFor(() => expect(screen.queryByText('Suggested Track')).not.toBeInTheDocument()) await waitFor(() => expect(screen.queryByText('Suggested Track')).not.toBeInTheDocument())
}) })
const COMMUNITY_NOTED_SONG: libraryApi.LibraryReviewItem = {
id: 321,
user_id: 7,
title: 'Corrected Track',
artist: 'Corrected Artist',
album: 'Corrected Album',
genre: 'Pop',
coverart: null,
confidence: 42,
review_status: 'pending',
added_at: '2026-01-01T00:00:00Z',
}
it('shows the community review queue and approves a song', async () => {
vi.spyOn(soundmarksApi, 'getAllSoundmarks').mockResolvedValue({ status: 'success', soundmarks: [] })
vi.spyOn(soundmarksApi, 'listUsers').mockResolvedValue({ status: 'success', users: [] })
vi.spyOn(soundmarksApi, 'getReviewQueue').mockResolvedValue({ status: 'success', suggestions: [] })
vi.spyOn(libraryApi, 'getLibraryReviewQueue').mockResolvedValue({ status: 'success', songs: [COMMUNITY_NOTED_SONG] })
const approve = vi.spyOn(libraryApi, 'approveLibraryReview').mockResolvedValue({
status: 'success',
song: { ...COMMUNITY_NOTED_SONG, review_status: 'approved' },
})
renderPanel()
await userEvent.click(screen.getByRole('button', { name: /community/ }))
await screen.findByText('Corrected Track')
expect(screen.getByText(/42% system confidence/)).toBeInTheDocument()
await userEvent.click(screen.getByRole('button', { name: 'Approve' }))
await waitFor(() => expect(approve).toHaveBeenCalledWith(COMMUNITY_NOTED_SONG.id))
await waitFor(() => expect(screen.queryByText('Corrected Track')).not.toBeInTheDocument())
})
it('rejects a community-noted song from the review queue', async () => {
vi.spyOn(soundmarksApi, 'getAllSoundmarks').mockResolvedValue({ status: 'success', soundmarks: [] })
vi.spyOn(soundmarksApi, 'listUsers').mockResolvedValue({ status: 'success', users: [] })
vi.spyOn(soundmarksApi, 'getReviewQueue').mockResolvedValue({ status: 'success', suggestions: [] })
vi.spyOn(libraryApi, 'getLibraryReviewQueue').mockResolvedValue({ status: 'success', songs: [COMMUNITY_NOTED_SONG] })
const reject = vi.spyOn(libraryApi, 'rejectLibraryReview').mockResolvedValue({
status: 'success',
song: { ...COMMUNITY_NOTED_SONG, review_status: 'rejected' },
})
renderPanel()
await userEvent.click(screen.getByRole('button', { name: /community/ }))
await screen.findByText('Corrected Track')
await userEvent.click(screen.getByRole('button', { name: 'Reject' }))
await waitFor(() => expect(reject).toHaveBeenCalledWith(COMMUNITY_NOTED_SONG.id))
await waitFor(() => expect(screen.queryByText('Corrected Track')).not.toBeInTheDocument())
})
}) })
import { useEffect, useState } from 'react' import { useEffect, useState } from 'react'
import { useTranslation } from 'react-i18next' import { useTranslation } from 'react-i18next'
import { Check, ListMusic, MapPin, Music2, Plus, Trash2, X } from 'lucide-react' import { Check, ListMusic, MapPin, Music2, Plus, Trash2, X } from 'lucide-react'
import {
approveLibraryReview,
getLibraryReviewQueue,
rejectLibraryReview,
type LibraryReviewItem,
} from '../api/library'
import { Layout } from '../components/Layout' import { Layout } from '../components/Layout'
import { Button } from '../components/ui/Button' import { Button } from '../components/ui/Button'
import { Input, Textarea } from '../components/ui/Input' import { Input, Textarea } from '../components/ui/Input'
...@@ -30,11 +36,12 @@ import { ...@@ -30,11 +36,12 @@ import {
type SoundmarkTier, type SoundmarkTier,
} from '../api/soundmarks' } from '../api/soundmarks'
type Section = 'soundmarks' | 'review queue' | 'users' type Section = 'soundmarks' | 'review queue' | 'community' | 'users'
const SECTION_LABEL_KEY: Record<Section, string> = { const SECTION_LABEL_KEY: Record<Section, string> = {
soundmarks: 'section.soundmarks', soundmarks: 'section.soundmarks',
'review queue': 'section.reviewQueue', 'review queue': 'section.reviewQueue',
community: 'section.community',
users: 'section.users', users: 'section.users',
} }
...@@ -490,6 +497,78 @@ function ReviewQueueSection({ ...@@ -490,6 +497,78 @@ function ReviewQueueSection({
) )
} }
function CommunityReviewSection({
queue,
loading,
savingKey,
onReview,
}: {
queue: LibraryReviewItem[]
loading: boolean
savingKey: string | null
onReview: (song: LibraryReviewItem, decision: 'approve' | 'reject') => void
}) {
const { t } = useTranslation('adminPanel')
return (
<>
{loading && (
<div className="divide-y divide-outline-variant/80">
<SkeletonRow />
<SkeletonRow />
</div>
)}
{!loading && queue.length === 0 && <EmptyState icon={Check} message={t('empty.communityCaughtUp')} />}
<ul className="space-y-3">
{queue.map((song) => (
<li key={song.id} className="rounded-xl border border-outline-variant bg-surface-container p-3">
<div className="flex items-center gap-3">
{song.coverart ? (
<img src={song.coverart} alt="" className="h-12 w-12 shrink-0 rounded-md object-cover" />
) : (
<div className="flex h-12 w-12 shrink-0 items-center justify-center rounded-md bg-surface-container-high text-on-surface-variant">
<Music2 size={16} strokeWidth={1.75} />
</div>
)}
<div className="min-w-0 flex-1">
<p className="truncate text-sm font-medium text-on-surface">{song.title}</p>
<p className="truncate text-xs text-on-surface-variant">
{song.artist} · {song.album}
</p>
</div>
{typeof song.confidence === 'number' && (
<span className="shrink-0 rounded-full bg-surface-container-high px-2 py-0.5 text-[10px] font-medium text-on-surface-variant">
{t('review.systemConfidence', { percent: Math.round(song.confidence) })}
</span>
)}
</div>
<div className="mt-3 flex gap-2">
<Button
size="sm"
onClick={() => onReview(song, 'approve')}
disabled={savingKey === `community-${song.id}`}
className="gap-1.5"
>
<Check size={14} strokeWidth={2.5} />
{t('action.approve')}
</Button>
<Button
variant="ghost"
size="sm"
onClick={() => onReview(song, 'reject')}
disabled={savingKey === `community-${song.id}`}
className="gap-1.5"
>
<X size={14} strokeWidth={2.5} />
{t('action.reject')}
</Button>
</div>
</li>
))}
</ul>
</>
)
}
function UserManageForm({ function UserManageForm({
user, user,
savingKey, savingKey,
...@@ -714,6 +793,7 @@ export function AdminPanel() { ...@@ -714,6 +793,7 @@ export function AdminPanel() {
const [soundmarks, setSoundmarks] = useState<Soundmark[]>([]) const [soundmarks, setSoundmarks] = useState<Soundmark[]>([])
const [users, setUsers] = useState<AdminUser[]>([]) const [users, setUsers] = useState<AdminUser[]>([])
const [queue, setQueue] = useState<SoundmarkSuggestion[]>([]) const [queue, setQueue] = useState<SoundmarkSuggestion[]>([])
const [libraryQueue, setLibraryQueue] = useState<LibraryReviewItem[]>([])
const [loading, setLoading] = useState(true) const [loading, setLoading] = useState(true)
const [error, setError] = useState<string | null>(null) const [error, setError] = useState<string | null>(null)
const [formTarget, setFormTarget] = useState<'new' | Soundmark | null>(null) const [formTarget, setFormTarget] = useState<'new' | Soundmark | null>(null)
...@@ -726,11 +806,12 @@ export function AdminPanel() { ...@@ -726,11 +806,12 @@ export function AdminPanel() {
function loadAll() { function loadAll() {
setLoading(true) setLoading(true)
Promise.all([getAllSoundmarks(), listUsers(), getReviewQueue()]) Promise.all([getAllSoundmarks(), listUsers(), getReviewQueue(), getLibraryReviewQueue()])
.then(([smRes, userRes, queueRes]) => { .then(([smRes, userRes, queueRes, libraryQueueRes]) => {
setSoundmarks(smRes.soundmarks) setSoundmarks(smRes.soundmarks)
setUsers(userRes.users) setUsers(userRes.users)
setQueue(queueRes.suggestions) setQueue(queueRes.suggestions)
setLibraryQueue(libraryQueueRes.songs)
}) })
.catch((err) => setError(err instanceof ApiError ? err.message : t('error.loadFailed'))) .catch((err) => setError(err instanceof ApiError ? err.message : t('error.loadFailed')))
.finally(() => setLoading(false)) .finally(() => setLoading(false))
...@@ -952,12 +1033,24 @@ export function AdminPanel() { ...@@ -952,12 +1033,24 @@ export function AdminPanel() {
} }
} }
async function handleLibraryReview(song: LibraryReviewItem, decision: 'approve' | 'reject') {
setSavingKey(`community-${song.id}`)
try {
await (decision === 'approve' ? approveLibraryReview(song.id) : rejectLibraryReview(song.id))
setLibraryQueue((prev) => prev.filter((s) => s.id !== song.id))
} catch (err) {
setError(err instanceof ApiError ? err.message : t('error.reviewLibrarySongFailed'))
} finally {
setSavingKey(null)
}
}
const playlistTarget = playlistFor !== null ? soundmarks.find((sm) => sm.id === playlistFor) : undefined const playlistTarget = playlistFor !== null ? soundmarks.find((sm) => sm.id === playlistFor) : undefined
return ( return (
<Layout title={t('page.title')}> <Layout title={t('page.title')}>
<div className="mb-6 flex w-fit gap-1 rounded-full bg-surface-container p-1"> <div className="mb-6 flex w-fit gap-1 rounded-full bg-surface-container p-1">
{(['soundmarks', 'review queue', 'users'] as const).map((s) => ( {(['soundmarks', 'review queue', 'community', 'users'] as const).map((s) => (
<button <button
key={s} key={s}
onClick={() => setSection(s)} onClick={() => setSection(s)}
...@@ -971,6 +1064,11 @@ export function AdminPanel() { ...@@ -971,6 +1064,11 @@ export function AdminPanel() {
{queue.length} {queue.length}
</span> </span>
)} )}
{s === 'community' && libraryQueue.length > 0 && (
<span className="ml-1.5 rounded-full bg-primary px-1.5 py-0.5 text-[10px] font-bold text-on-primary">
{libraryQueue.length}
</span>
)}
</button> </button>
))} ))}
</div> </div>
...@@ -998,6 +1096,15 @@ export function AdminPanel() { ...@@ -998,6 +1096,15 @@ export function AdminPanel() {
<ReviewQueueSection queue={queue} loading={loading} savingKey={savingKey} onReview={handleReview} /> <ReviewQueueSection queue={queue} loading={loading} savingKey={savingKey} onReview={handleReview} />
)} )}
{section === 'community' && (
<CommunityReviewSection
queue={libraryQueue}
loading={loading}
savingKey={savingKey}
onReview={handleLibraryReview}
/>
)}
{section === 'users' && ( {section === 'users' && (
<UsersSection <UsersSection
users={users} users={users}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment