summaryrefslogtreecommitdiff
path: root/app/routes/band-by-uuid.tsx
blob: 99a8b5c495cf619d288b58a010ae9491fbbb3224 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
import { data, Link, useLoaderData } from "react-router";
import type { LoaderFunctionArgs } from "react-router";
import {
  getBandById,
  getBandLinks,
  getBandArtists,
  getBandRevisions,
} from "~/lib/db.server";
import { LINK_TYPE_LABEL } from "~/lib/constants";

export async function loader({ params }: LoaderFunctionArgs) {
  const band = getBandById(params.uuid!);
  if (!band) throw data("Not found", { status: 404 });
  const links = getBandLinks(band.id);
  const artists = getBandArtists(band.id);
  const revisions = getBandRevisions(band.id);
  return { band, links, artists, latest: revisions[0] ?? null };
}

const STATUS_LABEL: Record<string, string> = {
  active: "活動中",
  hiatus: "活動休止",
  disbanded: "解散",
};

export default function BandDetail() {
  const { band, links, artists, latest } = useLoaderData<typeof loader>();
  return (
    <main>
      <div className="detail-header">
        <div className="detail-info">
          <h1>{band.name}</h1>
          <div className="detail-subtitle">
            {band.area && <span>{band.area}</span>}
            <span>{STATUS_LABEL[band.status] ?? band.status}</span>
          </div>
          {band.description && (
            <p className="detail-desc">{band.description}</p>
          )}
        </div>
        <div className="detail-actions">
          <Link to={`/bands/of/${band.id}/history`} className="history">履歴</Link>
          <Link to={`/bands/of/${band.id}/edit`} className="edit">編集</Link>
        </div>
      </div>

      {artists.length > 0 && (
        <section>
          <h2>メンバー</h2>
          <ul className="member-list">
            {artists.map((a) => (
              <li key={a.artist_id}>
                <Link to={`/artists/of/${a.artist_id}`}>{a.artist_name}</Link>
                {a.role && a.role.split(", ").filter(Boolean).map((r, i) => (
                  <span key={i} className="badge">{r}</span>
                ))}
              </li>
            ))}
          </ul>
        </section>
      )}

      {links.length > 0 && (
        <section>
          <h2>リンク</h2>
          <ul className="link-list">
            {links.map((l) => (
              <li key={l.id}>
                <a href={l.url} target="_blank" rel="noopener noreferrer">
                  {LINK_TYPE_LABEL[l.label] ?? l.label}
                </a>
              </li>
            ))}
          </ul>
        </section>
      )}

      <hr />
      <div className="meta">
        <p>/bands/of/{band.id}</p>
        <p>
          <Link to={`/bands/named/${band.slug}`}>/bands/named/{band.slug}</Link>
        </p>
        {latest && (
          <p className="updated">最終更新: {latest.created_at} — {latest.message}</p>
        )}
      </div>
    </main>
  );
}