style: format code with prettier
Local Build and Deploy / deploy (push) Successful in 49s

This commit is contained in:
openhands committed 2026-07-12 21:07:34 +02:00
1 parent e85e4d74ea
commit 2e4ed76121
378 files changed
+22404 -20686

No files matched your search

+262 -286
View File
@@ -1,4 +1,4 @@
'use client'
"use client";
import {
AlertCircle,
@@ -12,46 +12,46 @@ import {
Search,
Trash2,
X,
} from 'lucide-react'
import { useCallback, useEffect, useState } from 'react'
import { toast } from 'sonner'
import { Badge } from '@/components/ui/badge'
import { Button } from '@/components/ui/button'
import { Input } from '@/components/ui/input'
import { cn } from '@/lib/utils'
} from "lucide-react";
import { useCallback, useEffect, useState } from "react";
import { toast } from "sonner";
import { Badge } from "@/components/ui/badge";
import { Button } from "@/components/ui/button";
import { Input } from "@/components/ui/input";
import { cn } from "@/lib/utils";
// ── Types ─────────────────────────────────────────────────────────────────────
interface CloneSource {
id: string
name: string
furnidataUrl: string
nitroBaseUrl: string
iconBaseUrl: string
id: string;
name: string;
furnidataUrl: string;
nitroBaseUrl: string;
iconBaseUrl: string;
}
interface FurniItem {
classname: string
name: string
description?: string
revision?: number
category?: string
itemType: 's' | 'i'
xdim: number
ydim: number
present: boolean
classname: string;
name: string;
description?: string;
revision?: number;
category?: string;
itemType: "s" | "i";
xdim: number;
ydim: number;
present: boolean;
}
interface CloneStats {
total: number
present: number
clonable: number
total: number;
present: number;
clonable: number;
}
interface PageMeta {
page: number
perPage: number
total: number
page: number;
perPage: number;
total: number;
}
// ── Shared SSE reader (mirrors import-clothing-client.tsx) ────────────────────
@@ -63,63 +63,63 @@ async function runSseImport(
onComplete: (succeeded: number, failed: number) => void,
): Promise<void> {
const res = await fetch(url, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify(body),
})
});
if (!res.body) {
toast.error('No response stream')
return
toast.error("No response stream");
return;
}
const reader = res.body.getReader()
const decoder = new TextDecoder()
let buf = ''
let succeeded = 0
let failed = 0
const reader = res.body.getReader();
const decoder = new TextDecoder();
let buf = "";
let succeeded = 0;
let failed = 0;
while (true) {
const { value, done: streamDone } = await reader.read()
if (streamDone) break
buf += decoder.decode(value, { stream: true })
const parts = buf.split('\n\n')
buf = parts.pop() ?? ''
const { value, done: streamDone } = await reader.read();
if (streamDone) break;
buf += decoder.decode(value, { stream: true });
const parts = buf.split("\n\n");
buf = parts.pop() ?? "";
for (const part of parts) {
if (!part.startsWith('data: ')) continue
const evt = JSON.parse(part.slice(6))
if (evt.type === 'item_progress' && (evt.status === 'done' || evt.status === 'failed')) {
onDone(evt.classname)
if (!part.startsWith("data: ")) continue;
const evt = JSON.parse(part.slice(6));
if (evt.type === "item_progress" && (evt.status === "done" || evt.status === "failed")) {
onDone(evt.classname);
}
if (evt.type === 'batch_complete') {
succeeded = evt.succeeded
failed = evt.failed
if (evt.type === "batch_complete") {
succeeded = evt.succeeded;
failed = evt.failed;
}
}
}
onComplete(succeeded, failed)
onComplete(succeeded, failed);
}
// ── Source form ───────────────────────────────────────────────────────────────
interface SourceFormProps {
initial?: Partial<CloneSource>
onSave: (src: Partial<CloneSource>) => Promise<void>
onCancel: () => void
saving: boolean
initial?: Partial<CloneSource>;
onSave: (src: Partial<CloneSource>) => Promise<void>;
onCancel: () => void;
saving: boolean;
}
function SourceForm({ initial, onSave, onCancel, saving }: SourceFormProps) {
const [name, setName] = useState(initial?.name ?? '')
const [furnidataUrl, setFurnidataUrl] = useState(initial?.furnidataUrl ?? '')
const [nitroBaseUrl, setNitroBaseUrl] = useState(initial?.nitroBaseUrl ?? '')
const [iconBaseUrl, setIconBaseUrl] = useState(initial?.iconBaseUrl ?? '')
const [name, setName] = useState(initial?.name ?? "");
const [furnidataUrl, setFurnidataUrl] = useState(initial?.furnidataUrl ?? "");
const [nitroBaseUrl, setNitroBaseUrl] = useState(initial?.nitroBaseUrl ?? "");
const [iconBaseUrl, setIconBaseUrl] = useState(initial?.iconBaseUrl ?? "");
async function handleSubmit(e: React.FormEvent) {
e.preventDefault()
await onSave({ id: initial?.id, name, furnidataUrl, nitroBaseUrl, iconBaseUrl })
e.preventDefault();
await onSave({ id: initial?.id, name, furnidataUrl, nitroBaseUrl, iconBaseUrl });
}
return (
<form onSubmit={handleSubmit} className="space-y-3 rounded-lg border p-4 bg-card">
<div className="text-sm font-medium">{initial?.id ? 'Edit Source' : 'Add Source'}</div>
<div className="text-sm font-medium">{initial?.id ? "Edit Source" : "Add Source"}</div>
<div className="grid gap-2">
<Input
placeholder="Name (e.g. HotelX)"
@@ -156,61 +156,61 @@ function SourceForm({ initial, onSave, onCancel, saving }: SourceFormProps) {
</Button>
</div>
</form>
)
);
}
// ── Sources manager ───────────────────────────────────────────────────────────
interface SourcesManagerProps {
sources: CloneSource[]
activeSourceId: string | null
onSelect: (src: CloneSource) => void
onRefresh: () => Promise<void>
sources: CloneSource[];
activeSourceId: string | null;
onSelect: (src: CloneSource) => void;
onRefresh: () => Promise<void>;
}
function SourcesManager({ sources, activeSourceId, onSelect, onRefresh }: SourcesManagerProps) {
const [showForm, setShowForm] = useState(false)
const [editSrc, setEditSrc] = useState<CloneSource | null>(null)
const [saving, setSaving] = useState(false)
const [deletingId, setDeletingId] = useState<string | null>(null)
const [showForm, setShowForm] = useState(false);
const [editSrc, setEditSrc] = useState<CloneSource | null>(null);
const [saving, setSaving] = useState(false);
const [deletingId, setDeletingId] = useState<string | null>(null);
async function handleSave(src: Partial<CloneSource>) {
setSaving(true)
setSaving(true);
try {
const res = await fetch('/api/admin/import/clone', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
const res = await fetch("/api/admin/import/clone", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify(src),
})
const data = await res.json()
});
const data = await res.json();
if (!res.ok) {
toast.error(data.error || 'Save failed')
return
toast.error(data.error || "Save failed");
return;
}
toast.success(src.id ? 'Source updated' : 'Source added')
setShowForm(false)
setEditSrc(null)
await onRefresh()
toast.success(src.id ? "Source updated" : "Source added");
setShowForm(false);
setEditSrc(null);
await onRefresh();
} finally {
setSaving(false)
setSaving(false);
}
}
async function handleDelete(src: CloneSource) {
setDeletingId(src.id)
setDeletingId(src.id);
try {
const res = await fetch(`/api/admin/import/clone?id=${encodeURIComponent(src.id)}`, {
method: 'DELETE',
})
const data = await res.json()
method: "DELETE",
});
const data = await res.json();
if (!res.ok) {
toast.error(data.error || 'Delete failed')
return
toast.error(data.error || "Delete failed");
return;
}
toast.success(`${src.name} removed`)
await onRefresh()
toast.success(`${src.name} removed`);
await onRefresh();
} finally {
setDeletingId(null)
setDeletingId(null);
}
}
@@ -223,8 +223,8 @@ function SourcesManager({ sources, activeSourceId, onSelect, onRefresh }: Source
variant="outline"
className="h-7 text-xs"
onClick={() => {
setEditSrc(null)
setShowForm(true)
setEditSrc(null);
setShowForm(true);
}}
>
<Plus className="w-3 h-3 mr-1" />
@@ -246,17 +246,12 @@ function SourcesManager({ sources, activeSourceId, onSelect, onRefresh }: Source
{sources.map((src) => (
<div key={src.id}>
{editSrc?.id === src.id ? (
<SourceForm
initial={src}
onSave={handleSave}
onCancel={() => setEditSrc(null)}
saving={saving}
/>
<SourceForm initial={src} onSave={handleSave} onCancel={() => setEditSrc(null)} saving={saving} />
) : (
<div
className={cn(
'w-full rounded-lg border px-3 py-2.5 flex items-center gap-2 transition-colors hover:border-border',
activeSourceId === src.id && 'border-primary ring-1 ring-primary bg-primary/5',
"w-full rounded-lg border px-3 py-2.5 flex items-center gap-2 transition-colors hover:border-border",
activeSourceId === src.id && "border-primary ring-1 ring-primary bg-primary/5",
)}
>
<button
@@ -277,8 +272,8 @@ function SourcesManager({ sources, activeSourceId, onSelect, onRefresh }: Source
className="h-6 w-6 p-0"
title="Edit source"
onClick={() => {
setEditSrc(src)
setShowForm(false)
setEditSrc(src);
setShowForm(false);
}}
>
<Pencil className="w-3 h-3" />
@@ -303,7 +298,7 @@ function SourcesManager({ sources, activeSourceId, onSelect, onRefresh }: Source
</div>
))}
</div>
)
);
}
// ── Furni icon with fallback ──────────────────────────────────────────────────
@@ -313,20 +308,20 @@ function FurniIcon({
iconBaseUrl,
classname,
}: {
sourceId: string
iconBaseUrl: string
classname: string
sourceId: string;
iconBaseUrl: string;
classname: string;
}) {
// 0 = source's standalone icon, 1 = icon extracted from the .nitro (our
// endpoint), 2 = give up and show a placeholder.
const [stage, setStage] = useState(0)
const [stage, setStage] = useState(0);
if (stage >= 2) {
return <Package className="w-8 h-8 text-muted-foreground/50" />
return <Package className="w-8 h-8 text-muted-foreground/50" />;
}
const src =
stage === 0
? `${iconBaseUrl}/${classname}_icon.png`
: `/api/admin/import/clone/icon?source=${encodeURIComponent(sourceId)}&classname=${encodeURIComponent(classname)}`
: `/api/admin/import/clone/icon?source=${encodeURIComponent(sourceId)}&classname=${encodeURIComponent(classname)}`;
return (
// biome-ignore lint/performance/noImgElement: remote icon from clone source, not a Next asset
<img
@@ -336,203 +331,197 @@ function FurniIcon({
className="max-h-full max-w-full object-contain image-pixelated"
onError={() => setStage((s) => s + 1)}
/>
)
);
}
// ── Furni grid view ───────────────────────────────────────────────────────────
interface FurniGridProps {
source: CloneSource
source: CloneSource;
}
const PER_PAGE = 50
const PER_PAGE = 50;
function FurniGrid({ source }: FurniGridProps) {
const [searchTerm, setSearchTerm] = useState('')
const [activeSearch, setActiveSearch] = useState('')
const [items, setItems] = useState<FurniItem[]>([])
const [stats, setStats] = useState<CloneStats | null>(null)
const [meta, setMeta] = useState<PageMeta | null>(null)
const [page, setPage] = useState(1)
const [loading, setLoading] = useState(false)
const [error, setError] = useState('')
const [selected, setSelected] = useState<Set<string>>(new Set())
const [batchProgress, setBatchProgress] = useState<{ done: number; total: number } | null>(null)
const [busyClassname, setBusyClassname] = useState<string | null>(null)
const [filter, setFilter] = useState<'all' | 'missing' | 'present'>('all')
const [searchTerm, setSearchTerm] = useState("");
const [activeSearch, setActiveSearch] = useState("");
const [items, setItems] = useState<FurniItem[]>([]);
const [stats, setStats] = useState<CloneStats | null>(null);
const [meta, setMeta] = useState<PageMeta | null>(null);
const [page, setPage] = useState(1);
const [loading, setLoading] = useState(false);
const [error, setError] = useState("");
const [selected, setSelected] = useState<Set<string>>(new Set());
const [batchProgress, setBatchProgress] = useState<{ done: number; total: number } | null>(null);
const [busyClassname, setBusyClassname] = useState<string | null>(null);
const [filter, setFilter] = useState<"all" | "missing" | "present">("all");
const fetchItems = useCallback(
async (search: string, pageNum: number, filterVal: 'all' | 'missing' | 'present' = 'all') => {
setLoading(true)
setError('')
async (search: string, pageNum: number, filterVal: "all" | "missing" | "present" = "all") => {
setLoading(true);
setError("");
try {
const params = new URLSearchParams({
source: source.id,
page: String(pageNum),
perPage: String(PER_PAGE),
})
if (search) params.set('search', search)
if (filterVal !== 'all') params.set('filter', filterVal)
const res = await fetch(`/api/admin/import/clone?${params}`)
const data = await res.json()
});
if (search) params.set("search", search);
if (filterVal !== "all") params.set("filter", filterVal);
const res = await fetch(`/api/admin/import/clone?${params}`);
const data = await res.json();
if (!res.ok) {
setError(data.error || 'Failed to load')
return
setError(data.error || "Failed to load");
return;
}
setItems(data.item || [])
setMeta(data.meta || null)
setStats(data.stats || null)
setSelected(new Set())
setItems(data.item || []);
setMeta(data.meta || null);
setStats(data.stats || null);
setSelected(new Set());
} catch {
setError('Network error')
setError("Network error");
} finally {
setLoading(false)
setLoading(false);
}
},
[source.id],
)
);
useEffect(() => {
setPage(1)
setSearchTerm('')
setActiveSearch('')
setItems([])
setStats(null)
setMeta(null)
setFilter('all')
fetchItems('', 1, 'all')
}, [fetchItems])
setPage(1);
setSearchTerm("");
setActiveSearch("");
setItems([]);
setStats(null);
setMeta(null);
setFilter("all");
fetchItems("", 1, "all");
}, [fetchItems]);
function doSearch() {
setActiveSearch(searchTerm)
setPage(1)
fetchItems(searchTerm, 1, filter)
setActiveSearch(searchTerm);
setPage(1);
fetchItems(searchTerm, 1, filter);
}
function goPage(dir: 'prev' | 'next') {
const next = dir === 'next' ? page + 1 : Math.max(1, page - 1)
setPage(next)
fetchItems(activeSearch, next, filter)
function goPage(dir: "prev" | "next") {
const next = dir === "next" ? page + 1 : Math.max(1, page - 1);
setPage(next);
fetchItems(activeSearch, next, filter);
}
function changeFilter(f: 'all' | 'missing' | 'present') {
setFilter(f)
setPage(1)
fetchItems(activeSearch, 1, f)
function changeFilter(f: "all" | "missing" | "present") {
setFilter(f);
setPage(1);
fetchItems(activeSearch, 1, f);
}
const importable = items.filter((it) => !it.present)
const total = meta?.total ?? 0
const lastPage = Math.max(Math.ceil(total / PER_PAGE), 1)
const importable = items.filter((it) => !it.present);
const total = meta?.total ?? 0;
const lastPage = Math.max(Math.ceil(total / PER_PAGE), 1);
function toggle(classname: string) {
setSelected((prev) => {
const n = new Set(prev)
if (n.has(classname)) n.delete(classname)
else n.add(classname)
return n
})
const n = new Set(prev);
if (n.has(classname)) n.delete(classname);
else n.add(classname);
return n;
});
}
function markDone(classname: string) {
setItems((prev) =>
prev.map((it) => (it.classname === classname ? { ...it, present: true } : it)),
)
setItems((prev) => prev.map((it) => (it.classname === classname ? { ...it, present: true } : it)));
}
async function cloneViaSse(toClone: FurniItem[]) {
setBatchProgress({ done: 0, total: toClone.length })
let done = 0
setBatchProgress({ done: 0, total: toClone.length });
let done = 0;
await runSseImport(
'/api/admin/import/clone/batch',
"/api/admin/import/clone/batch",
{ sourceId: source.id, classnames: toClone.map((it) => it.classname), concurrency: 2 },
(classname) => {
done++
markDone(classname)
setBatchProgress({ done, total: toClone.length })
done++;
markDone(classname);
setBatchProgress({ done, total: toClone.length });
},
(succeeded, failed) => {
setBatchProgress(null)
setSelected(new Set())
if (succeeded > 0) toast.success(`${succeeded} furni cloned`)
if (failed > 0) toast.error(`${failed} failed`)
setBatchProgress(null);
setSelected(new Set());
if (succeeded > 0) toast.success(`${succeeded} furni cloned`);
if (failed > 0) toast.error(`${failed} failed`);
// Refresh stats after batch
fetchItems(activeSearch, page, filter)
fetchItems(activeSearch, page, filter);
},
)
setBatchProgress(null)
);
setBatchProgress(null);
}
async function cloneOne(it: FurniItem) {
setBusyClassname(it.classname)
setBusyClassname(it.classname);
try {
await cloneViaSse([it])
await cloneViaSse([it]);
} finally {
setBusyClassname(null)
setBusyClassname(null);
}
}
async function cloneSelected() {
const toClone = items.filter((it) => selected.has(it.classname) && !it.present)
if (toClone.length === 0) return
await cloneViaSse(toClone)
const toClone = items.filter((it) => selected.has(it.classname) && !it.present);
if (toClone.length === 0) return;
await cloneViaSse(toClone);
}
// Clone EVERY not-yet-present furni from the source (across all pages),
// in chunks of 400 to stay under the batch endpoint's 500 cap.
async function cloneAll() {
let names: string[] = []
let names: string[] = [];
try {
const res = await fetch(
`/api/admin/import/clone?source=${encodeURIComponent(source.id)}&action=clonable`,
)
const data = await res.json()
);
const data = await res.json();
if (!res.ok) {
toast.error(data.error || 'Failed to load clonable list')
return
toast.error(data.error || "Failed to load clonable list");
return;
}
names = data.classnames || []
names = data.classnames || [];
} catch {
toast.error('Network error')
return
toast.error("Network error");
return;
}
if (names.length === 0) {
toast.info('Nothing to clone — everything is already present')
return
toast.info("Nothing to clone — everything is already present");
return;
}
if (
!window.confirm(
`Clone ALL ${names.length} furni from "${source.name}"? This can take a while.`,
)
) {
return
if (!window.confirm(`Clone ALL ${names.length} furni from "${source.name}"? This can take a while.`)) {
return;
}
const CHUNK = 400
setBatchProgress({ done: 0, total: names.length })
let done = 0
let okCount = 0
let failCount = 0
const CHUNK = 400;
setBatchProgress({ done: 0, total: names.length });
let done = 0;
let okCount = 0;
let failCount = 0;
for (let i = 0; i < names.length; i += CHUNK) {
const chunk = names.slice(i, i + CHUNK)
const chunk = names.slice(i, i + CHUNK);
await runSseImport(
'/api/admin/import/clone/batch',
"/api/admin/import/clone/batch",
{ sourceId: source.id, classnames: chunk, concurrency: 2 },
(classname) => {
done++
markDone(classname)
setBatchProgress({ done, total: names.length })
done++;
markDone(classname);
setBatchProgress({ done, total: names.length });
},
(succeeded, failed) => {
okCount += succeeded
failCount += failed
okCount += succeeded;
failCount += failed;
},
)
);
}
setBatchProgress(null)
setSelected(new Set())
if (okCount > 0) toast.success(`${okCount} furni cloned`)
if (failCount > 0) toast.error(`${failCount} failed`)
fetchItems(activeSearch, page, filter)
setBatchProgress(null);
setSelected(new Set());
if (okCount > 0) toast.success(`${okCount} furni cloned`);
if (failCount > 0) toast.error(`${failCount} failed`);
fetchItems(activeSearch, page, filter);
}
return (
@@ -567,12 +556,12 @@ function FurniGrid({ source }: FurniGridProps) {
value={searchTerm}
onChange={(e) => setSearchTerm(e.target.value)}
onKeyDown={(e) => {
if (e.key === 'Enter') doSearch()
if (e.key === 'Escape') {
setSearchTerm('')
setActiveSearch('')
setPage(1)
fetchItems('', 1, filter)
if (e.key === "Enter") doSearch();
if (e.key === "Escape") {
setSearchTerm("");
setActiveSearch("");
setPage(1);
fetchItems("", 1, filter);
}
}}
className="pl-9 pr-8"
@@ -581,10 +570,10 @@ function FurniGrid({ source }: FurniGridProps) {
<button
type="button"
onClick={() => {
setSearchTerm('')
setActiveSearch('')
setPage(1)
fetchItems('', 1, filter)
setSearchTerm("");
setActiveSearch("");
setPage(1);
fetchItems("", 1, filter);
}}
className="absolute right-3 top-1/2 -translate-y-1/2 text-muted-foreground hover:text-foreground"
>
@@ -601,22 +590,22 @@ function FurniGrid({ source }: FurniGridProps) {
<div className="flex items-center gap-1 flex-wrap">
{(
[
{ key: 'all', label: 'All', count: stats?.total },
{ key: 'missing', label: "Not present (don't have)", count: stats?.clonable },
{ key: 'present', label: 'Present', count: stats?.present },
{ key: "all", label: "All", count: stats?.total },
{ key: "missing", label: "Not present (don't have)", count: stats?.clonable },
{ key: "present", label: "Present", count: stats?.present },
] as const
).map((f) => (
<Button
key={f.key}
type="button"
size="sm"
variant={filter === f.key ? 'default' : 'outline'}
variant={filter === f.key ? "default" : "outline"}
className="h-7 text-xs"
disabled={loading || !!batchProgress}
onClick={() => changeFilter(f.key)}
>
{f.label}
{typeof f.count === 'number' ? ` (${f.count})` : ''}
{typeof f.count === "number" ? ` (${f.count})` : ""}
</Button>
))}
</div>
@@ -632,15 +621,11 @@ function FurniGrid({ source }: FurniGridProps) {
disabled={!!batchProgress}
onClick={() =>
setSelected((prev) =>
prev.size === importable.length
? new Set()
: new Set(importable.map((it) => it.classname)),
prev.size === importable.length ? new Set() : new Set(importable.map((it) => it.classname)),
)
}
>
{selected.size === importable.length
? 'Deselect page'
: `Select page (${importable.length})`}
{selected.size === importable.length ? "Deselect page" : `Select page (${importable.length})`}
</Button>
)}
{selected.size > 0 && (
@@ -689,27 +674,22 @@ function FurniGrid({ source }: FurniGridProps) {
{!loading && items.length === 0 && !error && (
<div className="text-center py-12 text-muted-foreground">
<CloudDownload className="w-12 h-12 mx-auto mb-3 opacity-50" />
<p className="text-sm">No furni found{activeSearch ? ` for "${activeSearch}"` : ''}</p>
<p className="text-sm">No furni found{activeSearch ? ` for "${activeSearch}"` : ""}</p>
</div>
)}
{/* Grid */}
{items.length > 0 && (
<div
className={cn(
'grid grid-cols-2 md:grid-cols-4 lg:grid-cols-6 gap-3',
loading && 'opacity-50',
)}
>
<div className={cn("grid grid-cols-2 md:grid-cols-4 lg:grid-cols-6 gap-3", loading && "opacity-50")}>
{items.map((it) => {
const isSelected = selected.has(it.classname)
const isSelected = selected.has(it.classname);
return (
<div
key={it.classname}
className={cn(
'group rounded-lg border overflow-hidden bg-card relative hover:border-border transition-all',
it.present && 'ring-1 ring-[var(--admin-success)]/30',
isSelected && 'ring-2 ring-primary border-primary',
"group rounded-lg border overflow-hidden bg-card relative hover:border-border transition-all",
it.present && "ring-1 ring-[var(--admin-success)]/30",
isSelected && "ring-2 ring-primary border-primary",
)}
>
{!it.present && (
@@ -717,10 +697,10 @@ function FurniGrid({ source }: FurniGridProps) {
type="button"
onClick={() => toggle(it.classname)}
className={cn(
'absolute top-1.5 left-1.5 z-10 w-5 h-5 rounded border-2 flex items-center justify-center transition-colors',
"absolute top-1.5 left-1.5 z-10 w-5 h-5 rounded border-2 flex items-center justify-center transition-colors",
isSelected
? 'bg-primary border-primary text-primary-foreground'
: 'bg-background/80 border-muted-foreground/30 hover:border-muted-foreground',
? "bg-primary border-primary text-primary-foreground"
: "bg-background/80 border-muted-foreground/30 hover:border-muted-foreground",
)}
>
{isSelected && <Check className="w-3 h-3" />}
@@ -729,23 +709,19 @@ function FurniGrid({ source }: FurniGridProps) {
{/* Type badge */}
<div className="absolute top-1.5 right-1.5 z-10">
<Badge variant="outline" className="text-[9px] px-1 py-0 bg-background/80">
{it.itemType === 's' ? 'floor' : 'wall'}
{it.itemType === "s" ? "floor" : "wall"}
</Badge>
</div>
<div className="relative flex items-center justify-center h-28 bg-accent/20">
<FurniIcon
sourceId={source.id}
iconBaseUrl={source.iconBaseUrl}
classname={it.classname}
/>
<FurniIcon sourceId={source.id} iconBaseUrl={source.iconBaseUrl} classname={it.classname} />
{/* Hover detail tooltip */}
<div className="absolute bottom-1 left-1 right-1 z-10 opacity-0 group-hover:opacity-100 transition-opacity pointer-events-none">
<div className="bg-[var(--admin-overlay)] backdrop-blur-sm rounded px-2 py-1.5 text-[10px] text-[var(--admin-sidebar-text)] space-y-0.5">
{it.description ? <p className="truncate">{it.description}</p> : null}
<div className="flex gap-2 text-[var(--admin-sidebar-text)]/70">
{it.revision ? <span>Rev: {it.revision}</span> : null}
<span>{it.itemType === 's' ? 'Floor' : 'Wall'}</span>
<span>{it.itemType === "s" ? "Floor" : "Wall"}</span>
<span>
{it.xdim}×{it.ydim}
</span>
@@ -762,7 +738,7 @@ function FurniGrid({ source }: FurniGridProps) {
{it.classname}
</div>
<div className="text-[10px] text-muted-foreground truncate">
{it.itemType === 's' ? 'Floor' : 'Wall'} · {it.category || 'other'}
{it.itemType === "s" ? "Floor" : "Wall"} · {it.category || "other"}
</div>
<div className="pt-1">
{it.present ? (
@@ -789,7 +765,7 @@ function FurniGrid({ source }: FurniGridProps) {
</div>
</div>
</div>
)
);
})}
</div>
)}
@@ -805,7 +781,7 @@ function FurniGrid({ source }: FurniGridProps) {
variant="outline"
size="sm"
disabled={page <= 1 || loading}
onClick={() => goPage('prev')}
onClick={() => goPage("prev")}
>
&larr; Prev
</Button>
@@ -813,7 +789,7 @@ function FurniGrid({ source }: FurniGridProps) {
variant="outline"
size="sm"
disabled={page >= lastPage || loading}
onClick={() => goPage('next')}
onClick={() => goPage("next")}
>
Next &rarr;
</Button>
@@ -821,33 +797,33 @@ function FurniGrid({ source }: FurniGridProps) {
</div>
)}
</div>
)
);
}
// ── Root component ────────────────────────────────────────────────────────────
export function ImportCloneClient() {
const [sources, setSources] = useState<CloneSource[]>([])
const [activeSource, setActiveSource] = useState<CloneSource | null>(null)
const [loadingSources, setLoadingSources] = useState(true)
const [sources, setSources] = useState<CloneSource[]>([]);
const [activeSource, setActiveSource] = useState<CloneSource | null>(null);
const [loadingSources, setLoadingSources] = useState(true);
const fetchSources = useCallback(async () => {
try {
const res = await fetch('/api/admin/import/clone?action=sources')
const data = await res.json()
const res = await fetch("/api/admin/import/clone?action=sources");
const data = await res.json();
if (res.ok) {
setSources(data.sources || [])
setSources(data.sources || []);
}
} catch {
/* ignore */
} finally {
setLoadingSources(false)
setLoadingSources(false);
}
}, [])
}, []);
useEffect(() => {
fetchSources()
}, [fetchSources])
fetchSources();
}, [fetchSources]);
return (
<div className="space-y-6">
@@ -883,5 +859,5 @@ export function ImportCloneClient() {
</div>
)}
</div>
)
);
}
+6 -6
View File
@@ -1,11 +1,11 @@
import { redirect } from 'next/navigation'
import { canAccess, getAdminContext, PERMS } from '@/lib/permissions'
import { ImportCloneClient } from './import-clone-client'
import { redirect } from "next/navigation";
import { canAccess, getAdminContext, PERMS } from "@/lib/permissions";
import { ImportCloneClient } from "./import-clone-client";
export default async function ImportClonePage(_props: { params: Promise<{ locale: string }> }) {
const { session, permissions } = await getAdminContext()
const { session, permissions } = await getAdminContext();
if (!canAccess(permissions, PERMS.ASSETS_IMPORT, session.user.rank)) {
redirect('/admin')
redirect("/admin");
}
return <ImportCloneClient />
return <ImportCloneClient />;
}