diff --git a/generator/frontend/src/screens/WorkshopScreen.tsx b/generator/frontend/src/screens/WorkshopScreen.tsx index c4ecd17..7abb774 100644 --- a/generator/frontend/src/screens/WorkshopScreen.tsx +++ b/generator/frontend/src/screens/WorkshopScreen.tsx @@ -247,6 +247,10 @@ export function WorkshopScreen({ // Index being dragged + index currently hovered (for drop-line indicator). const [dragIndex, setDragIndex] = useState(null) const [dropIndex, setDropIndex] = useState(null) + // Same pattern for the achievements list so the two drag interactions + // don't share state and fight each other. + const [achDragIndex, setAchDragIndex] = useState(null) + const [achDropIndex, setAchDropIndex] = useState(null) // Build the render-order list from settings.widgetOrder, tolerating // stale persisted data: drop unknown ids, append any known widgets @@ -323,6 +327,15 @@ export function WorkshopScreen({ updateSetting('achievements', settings.achievements.filter((_, i) => i !== idx)) } + const moveAchievement = (from: number, to: number) => { + const list = settings.achievements + if (from === to || from < 0 || to < 0 || from >= list.length || to >= list.length) return + const next = list.slice() + const [item] = next.splice(from, 1) + next.splice(to, 0, item) + updateSetting('achievements', next) + } + // Render SVG client-side whenever settings change (instant, no API call) const svgContent = useMemo(() => { if (!widgetData) return '' @@ -614,9 +627,57 @@ export function WorkshopScreen({ />
- {settings.achievements.map((ach, aidx) => ( -
+ {settings.achievements.map((ach, aidx) => { + const achIsDragging = achDragIndex === aidx + const achShowLineAbove = aidx > 0 && achDropIndex === aidx && achDragIndex !== null && achDragIndex !== aidx + const achShowLineBelow = aidx === settings.achievements.length - 1 && achDropIndex === settings.achievements.length && achDragIndex !== null + return ( +
+ {achShowLineAbove &&
} +
{ + setAchDragIndex(aidx) + e.dataTransfer.effectAllowed = 'move' + e.dataTransfer.setData('text/plain', String(aidx)) + }} + onDragOver={e => { + if (achDragIndex === null) return + e.preventDefault() + e.dataTransfer.dropEffect = 'move' + const rect = e.currentTarget.getBoundingClientRect() + const after = e.clientY - rect.top > rect.height / 2 + const target = after ? aidx + 1 : aidx + if (target === achDragIndex || target === achDragIndex + 1) { + setAchDropIndex(null) + } else { + setAchDropIndex(target) + } + }} + onDrop={e => { + e.preventDefault() + if (achDragIndex === null || achDropIndex === null) { + setAchDragIndex(null); setAchDropIndex(null); return + } + const to = achDropIndex > achDragIndex ? achDropIndex - 1 : achDropIndex + moveAchievement(achDragIndex, to) + setAchDragIndex(null); setAchDropIndex(null) + }} + onDragEnd={() => { setAchDragIndex(null); setAchDropIndex(null) }} + >
+ + + {ICONS.map(ic => { const selected = ach.icon === ic.id return ( @@ -665,8 +726,11 @@ export function WorkshopScreen({ placeholder="Date (e.g. 2025-01)" className="w-full px-2 py-1.5 rounded-md border border-gray-200 bg-white text-xs text-gray-800 placeholder:text-gray-300 focus:outline-none focus:ring-1 focus:ring-gray-300" /> +
+ {achShowLineBelow &&
}
- ))} + ) + })}