"use client"; import { useState } from "react"; import { api, canEdit } from "@/admin/api"; import { gb, StorageMeter, Uploader, type MediaItem, type Storage } from "@/admin/media"; import { Btn, inputClass, Loading, Notice, Panel, Title, useAction, useAdmin, when } from "@/admin/ui"; import { Image as ImageIcon, Trash2 } from "lucide-react"; /** The media library (§10): uploads, what each photo shows (alt text), and storage used. */ export default function Media() { const { data, error, reload } = useAdmin<{ storage: Storage; request: { at: string; steps: number } | null; items: MediaItem[] }>("/media"); const me = useAdmin<{ user: { role: string } }>("/me"); const [alts, setAlts] = useState>({}); const [steps, setSteps] = useState(1); const { busy, message, run } = useAction(); if (!data) return ; const manager = ["owner", "admin"].includes(me.data?.user.role ?? ""); const editor = canEdit(me.data?.user.role ?? ""); const s = data.storage; return ( <> Media library
{message &&
{message.text}
} {data.items.length === 0 &&

No photos yet.

}
    {data.items.map((m) => (
  • {m.alt} {alts[m.id] !== undefined && alts[m.id] !== m.alt && ( run(async () => { await api(`/media/${m.id}`, { method: "PUT", body: { alt: alts[m.id] } }); await reload(); }, "Saved.")}>Save )} {!m.alt &&

    Add what it shows, for people who can't see it.

    }

    {m.width && m.height ? `${m.width} × ${m.height}` : ""} · {gb(m.bytes)}

    {m.usedIn?.length ? (

    Used on: {m.usedIn.join(", ")}

    ) : editor && ( { if (window.confirm(`Delete this photo${m.alt ? ` (“${m.alt}”)` : ""}? It isn't used anywhere. This can't be undone.`)) { void run(async () => { await api(`/media/${m.id}`, { method: "DELETE" }); await reload(); }, "Deleted."); } }}>Delete )}
  • ))}
{s.percent >= 80 &&
{s.full ? "Storage is full: uploads have stopped until more storage is added." : "Storage is nearly full."} Everything already uploaded keeps showing.
}

Get more storage

In steps of 5 GB, R20 a month each, added to your church's account.

{data.request ? (
You asked for {data.request.steps * 5} GB more on {when(data.request.at)}. Cross Code adds it to your account; uploads work again within a minute of that.
) : manager ? (
run(async () => { await api("/storage-request", { body: { steps } }); await reload(); }, "Asked: Cross Code will add it.")}>Ask for it
) :

Your website's Owner or an Admin can ask for it.

}
{s.full ? Uploads have stopped: your storage is full. : reload()} />}
); }