feat : update UI

This commit is contained in:
2026-10-01 00:13:38 +07:00 Unverified
parent 2ae4aee962
commit 63d0ec8c67
14 changed files with 6724 additions and 28 deletions
+81 -6
View File
@@ -25,6 +25,7 @@ import {
SortableContext,
sortableKeyboardCoordinates,
useSortable,
verticalListSortingStrategy,
} from "@dnd-kit/sortable";
import { CSS } from "@dnd-kit/utilities";
import { toast } from "sonner";
@@ -742,6 +743,52 @@ function VisualRecommendationGrid({
);
}
function SortableTeam({
id,
position,
children,
}: {
id: string;
position: number;
children: ReactNode;
}) {
const {
attributes,
listeners,
setNodeRef,
transform,
transition,
isDragging,
} = useSortable({ id });
return (
<div
ref={setNodeRef}
style={{ transform: CSS.Transform.toString(transform), transition }}
className={cn(isDragging && "relative z-10 opacity-60")}
>
<Card size="sm">
<CardContent className="flex flex-col gap-2">
<div className="flex items-center justify-between gap-2">
<span className="text-sm font-medium">Team {position + 1}</span>
<Button
type="button"
variant="ghost"
size="icon-xs"
className="touch-none"
aria-label={`Drag to reorder team ${position + 1}`}
{...attributes}
{...listeners}
>
<GripVerticalIcon />
</Button>
</div>
{children}
</CardContent>
</Card>
</div>
);
}
function BossRecommendationEditor({
scheduleId,
version,
@@ -776,6 +823,13 @@ function BossRecommendationEditor({
.filter((group) => group.kind === "unit")
.flatMap((group) => group.items.flatMap((item) => toInput(item) ?? [])),
);
const teamSensors = useSensors(
useSensor(PointerSensor, { activationConstraint: { distance: 4 } }),
useSensor(KeyboardSensor, {
coordinateGetter: sortableKeyboardCoordinates,
}),
);
const teamIds = teams.map((_, index) => `team-${index}`);
const fingerprint = JSON.stringify({ teams, units });
const valid = teams.every(
(team) =>
@@ -868,9 +922,28 @@ function BossRecommendationEditor({
<div className="flex min-w-0 flex-col gap-6">
<FieldSet className="gap-3">
<FieldLegend>Recommended team</FieldLegend>
{teams.map((team, teamIndex) => (
<Card key={teamIndex} size="sm">
<CardContent className="flex flex-col gap-2">
<DndContext
sensors={teamSensors}
collisionDetection={closestCenter}
onDragEnd={({ active, over }) => {
if (!over || active.id === over.id) return;
const from = teamIds.indexOf(String(active.id));
const to = teamIds.indexOf(String(over.id));
if (from >= 0 && to >= 0)
setTeams((current) => arrayMove(current, from, to));
}}
>
<SortableContext
items={teamIds}
strategy={verticalListSortingStrategy}
>
<div className="flex flex-col gap-3">
{teams.map((team, teamIndex) => (
<SortableTeam
key={teamIds[teamIndex]}
id={teamIds[teamIndex]}
position={teamIndex}
>
<VisualRecommendationGrid
items={team}
limit={4}
@@ -908,9 +981,11 @@ function BossRecommendationEditor({
<Trash2Icon data-icon="inline-start" />
Remove team
</DeleteConfirmationDialog>
</CardContent>
</Card>
))}
</SortableTeam>
))}
</div>
</SortableContext>
</DndContext>
<Button
variant="outline"
size="sm"
+1
View File
@@ -39,6 +39,7 @@ export function SiteHeader({ editHref = "/admin", guideId }: { editHref?: string
nativeButton={false}
render={<Link href="/stygian" />}
>
<Image src="/icon/stygian.webp" alt="" width={24} height={24} className="size-6 object-contain" />
Stygian Guide
</Button>
<VisitorPresence guideId={guideId} />
+48 -22
View File
@@ -1,4 +1,5 @@
import Image from "next/image";
import { CheckIcon, XIcon } from "lucide-react";
import { Accordion, AccordionContent, AccordionItem, AccordionTrigger } from "@/components/ui/accordion";
import { Badge } from "@/components/ui/badge";
@@ -16,6 +17,24 @@ type Schedule = NonNullable<Awaited<ReturnType<typeof getStygianSchedule>>>;
type Catalog = NonNullable<Awaited<ReturnType<typeof getActiveCatalog>>>;
type Item = Schedule["recommendations"][number]["items"][number];
function RecommendedMechanic({ mechanic, type }: { mechanic: string; type: string }) {
const parts = mechanic.split(/(\{SPRITE_PRESET#\d+\})/gu);
return (
<span className="inline-flex flex-wrap items-center gap-1">
{parts.map((part, index) => {
const preset = /^\{SPRITE_PRESET#(\d+)\}$/u.exec(part)?.[1];
if (preset) return <Image key={`${part}-${index}`} src={`https://api.lunaris.moe/data/assets/icons/${preset}.png`} alt="" width={20} height={20} className="size-5 shrink-0 object-contain" />;
return part ? <LunarisText key={`${part}-${index}`} nodes={parseLunarisText(part)} fallback={part} /> : null;
})}
{type === "Disadvantage"
? <XIcon className="size-4 text-red-500" aria-hidden="true" />
: type === "Advantage"
? <CheckIcon className="size-4 text-emerald-500" aria-hidden="true" />
: null}
</span>
);
}
function recommendation(item: Item, catalog: Catalog) {
if (item.kind === "element" && item.element) {
const source = catalog.characters.find((character) => character.element === item.element && character.elementIconUrl);
@@ -45,27 +64,29 @@ function RecommendationIcon({ item, catalog, teamLayout = false }: { item: Item;
if (item.kind === "character") {
const hasEquipment = Boolean(value.weapon || value.artifact);
return (
<div className="flex min-w-0 flex-col gap-1 rounded-lg border bg-card p-1">
<div className={teamLayout && hasEquipment ? "grid grid-cols-3 gap-1" : "flex flex-col gap-1"}>
<div className={`${teamLayout && hasEquipment ? "col-span-2 row-span-2" : ""} relative aspect-square overflow-hidden rounded-lg ${rarityGradientClass(value.rarity)}`}>
{value.imageUrl ? <Image src={value.imageUrl} alt={value.name} fill sizes="128px" className="object-contain" /> : null}
<div className={cn("flex min-w-0 flex-col gap-1 rounded-lg border bg-card p-1", teamLayout && "sm:p-2")}>
<div className={teamLayout ? "flex flex-col gap-1 sm:grid sm:grid-cols-3 sm:gap-2" : "flex flex-col gap-1"}>
<div className={cn("relative aspect-square overflow-hidden rounded-lg", teamLayout && "sm:col-span-2 sm:row-span-2", rarityGradientClass(value.rarity))}>
{value.imageUrl ? <Image src={value.imageUrl} alt={value.name} fill sizes={teamLayout ? "(min-width: 640px) 128px, 25vw" : "128px"} className="object-contain" /> : null}
</div>
{hasEquipment ? <div className={teamLayout ? "grid grid-cols-1 gap-1" : "grid grid-cols-2 gap-1"}>
{hasEquipment ? <div className={teamLayout ? "grid grid-cols-2 gap-1 sm:row-span-2 sm:grid-cols-1 sm:gap-2" : "grid grid-cols-2 gap-1"}>
{value.weapon ? <div className={cn("relative aspect-square overflow-hidden rounded-md border", rarityGradientClass(value.weapon.rarity))}><Image src={value.weapon.imageUrl} alt={value.weapon.name} fill sizes="64px" className="object-contain p-1" /></div> : null}
{value.artifact ? <div className={cn("relative aspect-square overflow-hidden rounded-md border", rarityGradientClass(value.artifact.rarity))}><Image src={value.artifact.imageUrl} alt={value.artifact.name} fill sizes="64px" className="object-contain p-1" /></div> : null}
</div> : null}
</div> : teamLayout ? <div className="hidden sm:block" aria-hidden="true" /> : null}
</div>
{teamLayout ? <div className="grid grid-cols-2 gap-1"><Badge variant="secondary" className="justify-center">{value.badge === "Character" ? "C—" : value.badge}</Badge><Badge variant="secondary" className="justify-center">{value.weapon && value.refinement ? `R${value.refinement}` : "R—"}</Badge></div> : <div className="flex min-w-0 items-center justify-between gap-1"><span className="truncate text-xs font-medium" title={value.name}>{value.name}</span><Badge variant="secondary">{value.badge}</Badge></div>}
{teamLayout ? item.constellationLevel !== null || value.weapon && value.refinement ? <div className="flex justify-center gap-1">
{item.constellationLevel !== null ? <Badge variant="secondary">C{item.constellationLevel}</Badge> : null}
{value.weapon && value.refinement ? <Badge variant="secondary">R{value.refinement}</Badge> : null}
</div> : null : <span className="truncate text-center text-xs font-medium" title={value.name}>{value.name}</span>}
</div>
);
}
return (
<div className="flex min-w-0 flex-col items-center gap-1 text-center">
<div className={cn("relative size-16 overflow-hidden rounded-lg border", item.kind !== "element" && rarityGradientClass(value.rarity))}>
{value.imageUrl ? <Image src={value.imageUrl} alt={value.name} fill sizes="64px" className="object-contain" style={item.kind === "element" && item.element ? { filter: elementIconFilter(item.element) } : undefined} /> : null}
<div className={cn("relative aspect-square w-full overflow-hidden rounded-lg border", item.kind !== "element" && rarityGradientClass(value.rarity))}>
{value.imageUrl ? <Image src={value.imageUrl} alt={value.name} fill sizes="80px" className="object-contain" style={item.kind === "element" && item.element ? { filter: elementIconFilter(item.element) } : undefined} /> : null}
</div>
<span className="max-w-20 truncate text-xs font-medium" title={value.name}>{value.name}</span>
<Badge variant="outline" className="capitalize">{value.badge}</Badge>
</div>
);
}
@@ -78,14 +99,11 @@ function BossCard({ schedule, level, position, catalog }: { schedule: Schedule;
const units = groups.filter((group) => group.kind === "unit").flatMap((group) => group.items);
return (
<Card>
<CardContent className="grid gap-6 md:grid-cols-[14rem_minmax(0,1fr)]">
<aside className="self-start">
<div className="relative aspect-square overflow-hidden rounded-xl bg-muted/30">
<Image src={boss.imageUrl} alt={boss.name} fill sizes="224px" className="object-contain p-3" priority={level === 110} />
</div>
<h2 className="mt-3 font-heading text-lg font-semibold">{boss.name}</h2>
<CardContent className="flex flex-col gap-6">
<header className="text-center">
<h2 className="font-heading text-lg font-semibold">{boss.name}</h2>
<p className="mt-1 text-sm text-muted-foreground">Level {level} · HP {Math.round(boss.hp).toLocaleString("en-US")}</p>
</aside>
</header>
<div className="flex min-w-0 flex-col gap-5">
<Accordion>
<AccordionItem value="overview">
@@ -106,15 +124,15 @@ function BossCard({ schedule, level, position, catalog }: { schedule: Schedule;
<section className="flex flex-col gap-3" aria-label={`Recommended teams for ${boss.name}`}>
<h3 className="font-heading text-lg font-semibold">Recommended team</h3>
{teams.length ? teams.map((team) => (
<div key={team.id} className="grid grid-cols-[repeat(4,minmax(0,7.5rem))] gap-2 rounded-lg border bg-muted/20 p-2">
<div key={team.id} className="grid w-full max-w-xl grid-cols-4 items-start gap-1 rounded-lg border bg-muted/20 p-2 sm:gap-3">
{team.items.slice(0, 4).map((item) => <RecommendationIcon key={`${item.groupId}-${item.position}`} item={item} catalog={catalog} teamLayout />)}
{Array.from({ length: Math.max(0, 4 - team.items.length) }, (_, index) => <div key={`empty-${index}`} className="aspect-[3/4] rounded-lg border border-dashed bg-muted/30" aria-hidden="true" />)}
{Array.from({ length: Math.max(0, 4 - team.items.length) }, (_, index) => <div key={`empty-${index}`} className="aspect-[4/3] rounded-lg border border-dashed bg-muted/30" aria-hidden="true" />)}
</div>
)) : <p className="text-sm text-muted-foreground">No team recommendations yet.</p>}
</section>
<section className="flex flex-col gap-3" aria-label={`Recommended units for ${boss.name}`}>
<h3 className="font-heading text-lg font-semibold">Recommended unit</h3>
{units.length ? <div className="grid grid-cols-[repeat(auto-fill,minmax(6rem,7.5rem))] gap-2">{units.map((item) => <RecommendationIcon key={`${item.groupId}-${item.position}`} item={item} catalog={catalog} />)}</div> : <p className="text-sm text-muted-foreground">No unit recommendations yet.</p>}
{units.length ? <div className="grid grid-cols-[repeat(auto-fill,minmax(4rem,5rem))] gap-2">{units.map((item) => <RecommendationIcon key={`${item.groupId}-${item.position}`} item={item} catalog={catalog} />)}</div> : <p className="text-sm text-muted-foreground">No unit recommendations yet.</p>}
</section>
</div>
</CardContent>
@@ -132,10 +150,18 @@ export function StygianGuide({ schedule, catalog }: { schedule: Schedule; catalo
{([105, 110] as const).map((level) => (
<TabsContent key={level} value={String(level)}>
<Tabs defaultValue="0">
<TabsList variant="line" className="grid h-10 w-full grid-cols-3 overflow-hidden" aria-label={`Level ${level} bosses`}>
<TabsList variant="line" className="grid w-full grid-cols-3 overflow-hidden group-data-horizontal/tabs:h-auto group-data-horizontal/tabs:min-h-96" aria-label={`Level ${level} bosses`}>
{[0, 1, 2].map((position) => {
const boss = schedule.bosses.find((candidate) => candidate.level === level && candidate.position === position);
return <TabsTrigger key={position} value={String(position)} className="h-full min-w-0 overflow-hidden rounded-none px-2"><span className="block min-w-0 truncate">{boss?.name ?? `Boss ${position + 1}`}</span></TabsTrigger>;
const label = boss?.name ?? `Boss ${position + 1}`;
const positionLabel = ["บน", "กลาง", "ล่าง"][position];
return <TabsTrigger key={position} value={String(position)} aria-label={`${positionLabel}: ${label}`} title={label} className="h-full min-w-0 flex-col justify-start overflow-hidden rounded-none px-2 py-3">
{boss ? <Image src={boss.imageUrl} alt="" width={256} height={256} sizes="256px" className="size-64 shrink-0 object-contain" priority={level === 110} /> : <span>{position + 1}</span>}
<span className="text-base font-semibold">{positionLabel}</span>
{boss?.recommendedMechanics.some(Boolean) ? <span className="mt-2 flex flex-col items-center gap-1 text-xs font-normal whitespace-normal text-muted-foreground">
{boss.recommendedMechanics.map((mechanic, index) => mechanic ? <RecommendedMechanic key={`${mechanic}-${index}`} mechanic={mechanic} type={boss.recommendedMechanicTypes[index] ?? (index === 0 ? "Advantage" : index === 1 ? "Disadvantage" : "None")} /> : null)}
</span> : null}
</TabsTrigger>;
})}
</TabsList>
{[0, 1, 2].map((position) => <TabsContent key={position} value={String(position)} className="pt-4"><BossCard schedule={schedule} level={level} position={position} catalog={catalog} /></TabsContent>)}