fa7897c195
Renombrado completo de los prefijos heredados: 19 carpetas, 11 ficheros y 318 referencias en 35 ficheros de código, más las clases y las rutas url() de dentro del CSS del tema. Se usa git mv para conservar el historial. También fuera del código, que un sed no ve: - BD: votesite.image_url (4 filas) apuntaba a /nw-themes/... - Ficheros con la marca vieja en el NOMBRE: novawow-maintenance.webp -> nightspire-maintenance.webp (lo usa la página de mantenimiento) y store_novawow_response.js. ⚠ Alias en Caddy /nw-themes/* -> /ns-themes/*: los correos ENVIADOS antes del rebranding llevan esas rutas escritas y están en las bandejas de los usuarios. Sin el alias, sus imágenes se romperían. Verificado que las rutas viejas siguen sirviendo 200. Nota: ns-js/ y ns-js-handlers/ son CÓDIGO MUERTO (manejadores jQuery del portal Django, que ya se borró). Se midió en el navegador: la web no pide ni un solo JS del tema. Se renombran igualmente por consistencia, pero son candidatos a borrarse. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
85 lines
3.1 KiB
TypeScript
85 lines
3.1 KiB
TypeScript
'use client'
|
|
|
|
import { useState } from 'react'
|
|
import { useTranslations } from 'next-intl'
|
|
import type { VoteSite } from '@/lib/admin-votes'
|
|
|
|
export function AdminVotesManager({ initial }: { initial: VoteSite[] }) {
|
|
const t = useTranslations('Admin')
|
|
const [sites, setSites] = useState(initial)
|
|
const [form, setForm] = useState({ name: '', url: '', imageUrl: '', points: '1' })
|
|
const [busy, setBusy] = useState(false)
|
|
|
|
function upd(k: string, v: string) {
|
|
setForm((f) => ({ ...f, [k]: v }))
|
|
}
|
|
|
|
async function create(e: React.FormEvent) {
|
|
e.preventDefault()
|
|
if (busy || !form.name.trim() || !form.url.trim()) return
|
|
setBusy(true)
|
|
try {
|
|
const res = await fetch('/api/admin/votes', {
|
|
method: 'POST',
|
|
headers: { 'Content-Type': 'application/json' },
|
|
credentials: 'same-origin',
|
|
body: JSON.stringify({ ...form, points: Number(form.points) }),
|
|
})
|
|
const data: { success?: boolean; id?: number } = await res.json()
|
|
if (data.success && data.id) {
|
|
setSites([
|
|
...sites,
|
|
{ id: data.id, name: form.name, url: form.url, image_url: form.imageUrl, points: Number(form.points) },
|
|
])
|
|
setForm({ name: '', url: '', imageUrl: '', points: '1' })
|
|
}
|
|
} finally {
|
|
setBusy(false)
|
|
}
|
|
}
|
|
|
|
async function remove(id: number) {
|
|
if (!confirm(t('confirmDelete'))) return
|
|
const res = await fetch(`/api/admin/votes/${id}`, { method: 'DELETE', credentials: 'same-origin' })
|
|
if ((await res.json()).success) setSites(sites.filter((s) => s.id !== id))
|
|
}
|
|
|
|
return (
|
|
<div>
|
|
<form onSubmit={create} className="admin-form info-box-light separate2">
|
|
<input value={form.name} onChange={(e) => upd('name', e.target.value)} placeholder={t('voteName')} />
|
|
<input value={form.url} onChange={(e) => upd('url', e.target.value)} placeholder={t('voteUrl')} />
|
|
<input value={form.imageUrl} onChange={(e) => upd('imageUrl', e.target.value)} placeholder={t('voteImage')} />
|
|
<input type="number" min="0" value={form.points} onChange={(e) => upd('points', e.target.value)} placeholder={t('votePoints')} />
|
|
<button type="submit" disabled={busy}>
|
|
{busy ? t('creating') : t('create')}
|
|
</button>
|
|
</form>
|
|
<br />
|
|
{sites.length === 0 ? (
|
|
<p className="second-brown centered">{t('noVotes')}</p>
|
|
) : (
|
|
<table className="max-center-table">
|
|
<tbody>
|
|
{sites.map((s) => (
|
|
<tr key={s.id} className="team-center-table-tr">
|
|
<td className="lefted separate">
|
|
<span className="yellow-info">{s.name}</span>
|
|
<p className="third-brown small-font">
|
|
{s.points} PV · {s.url}
|
|
</p>
|
|
</td>
|
|
<td className="real-info-box">
|
|
<button onClick={() => remove(s.id)} className="ns-tool-btn red-info2">
|
|
{t('delete')}
|
|
</button>
|
|
</td>
|
|
</tr>
|
|
))}
|
|
</tbody>
|
|
</table>
|
|
)}
|
|
</div>
|
|
)
|
|
}
|