🎛️ resolve HTML5 drag-and-drop unmounting issue on dashboard cards
Browse files at this commit1c0f094d957a915604ff8bd3cababd53b0050252Parent: 0edd44d- fix
- 🎛️ resolve HTML5 drag-and-drop unmounting issue on dashboard cards
2 changed files +221 -84
- src/index.css +15 -0
- src/pages/dashboard-page.tsx +206 -84
src/index.cssmodified+15 -0
| @@ -255,6 +255,21 @@ | |||
| 255 | @apply rounded-xl h-11 px-5 font-medium active:scale-[0.97] transition-transform duration-150; | 255 | @apply rounded-xl h-11 px-5 font-medium active:scale-[0.97] transition-transform duration-150; |
| 256 | } | 256 | } |
| 257 | 257 | ||
| 258 | + @keyframes dashboard-jiggle { | ||
| 259 | + 0%, 100% { transform: rotate(-0.4deg) translateY(0); } | ||
| 260 | + 50% { transform: rotate(0.4deg) translateY(-1px); } | ||
| 261 | + } | ||
| 262 | + | ||
| 263 | + .dashboard-jiggle { | ||
| 264 | + animation: dashboard-jiggle 180ms ease-in-out infinite; | ||
| 265 | + } | ||
| 266 | + | ||
| 267 | + @media (prefers-reduced-motion: reduce) { | ||
| 268 | + .dashboard-jiggle { | ||
| 269 | + animation: none; | ||
| 270 | + } | ||
| 271 | + } | ||
| 272 | + | ||
| 258 | .num, | 273 | .num, |
| 259 | .mono { | 274 | .mono { |
| 260 | font-family: SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace; | 275 | font-family: SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace; |
src/pages/dashboard-page.tsxmodified+206 -84
| @@ -224,28 +224,48 @@ function DashboardContent() { | |||
| 224 | 224 | ||
| 225 | if (r === "student") { | 225 | if (r === "student") { |
| 226 | list.push( | 226 | list.push( |
| 227 | + { Icon: IconExam, titleKey: "nav.exams", to: "/exams", descKey: "dashboard.portal.examsDesc", stat: ec }, | ||
| 227 | { Icon: IconBook, titleKey: "nav.courses", to: "/courses", descKey: "dashboard.portal.coursesDesc", stat: cc }, | 228 | { Icon: IconBook, titleKey: "nav.courses", to: "/courses", descKey: "dashboard.portal.coursesDesc", stat: cc }, |
| 229 | + { Icon: IconChart, titleKey: "nav.marks", to: "/marks", descKey: "dashboard.portal.marksDesc", stat: avgLabel() }, | ||
| 228 | { Icon: IconClock, titleKey: "nav.studies", to: "/studies", descKey: "dashboard.portal.studiesDesc", stat: sc }, | 230 | { Icon: IconClock, titleKey: "nav.studies", to: "/studies", descKey: "dashboard.portal.studiesDesc", stat: sc }, |
| 229 | - { Icon: IconUsers, titleKey: "nav.clubs", to: "/clubs", descKey: "dashboard.portal.clubsDesc", stat: clc }, | ||
| 230 | - { Icon: IconExam, titleKey: "nav.exams", to: "/exams", descKey: "dashboard.portal.examsDesc", stat: ec }, | ||
| 231 | { Icon: IconCalendar, titleKey: "nav.events", to: "/events", descKey: "dashboard.portal.eventsDesc", stat: evc }, | 231 | { Icon: IconCalendar, titleKey: "nav.events", to: "/events", descKey: "dashboard.portal.eventsDesc", stat: evc }, |
| 232 | - { Icon: IconChart, titleKey: "nav.marks", to: "/marks", descKey: "dashboard.portal.marksDesc", stat: avgLabel() }, | 232 | + { Icon: IconNote, titleKey: "nav.notes", to: "/notes", descKey: "dashboard.portal.notesDesc", stat: nc }, |
| 233 | { Icon: IconClock, titleKey: "nav.pomodoro", to: "/pomodoro", descKey: "dashboard.portal.pomodoroDesc" }, | 233 | { Icon: IconClock, titleKey: "nav.pomodoro", to: "/pomodoro", descKey: "dashboard.portal.pomodoroDesc" }, |
| 234 | + { Icon: IconUsers, titleKey: "nav.clubs", to: "/clubs", descKey: "dashboard.portal.clubsDesc", stat: clc }, | ||
| 234 | { Icon: IconMessage, titleKey: "nav.messages", to: "/messages" }, | 235 | { Icon: IconMessage, titleKey: "nav.messages", to: "/messages" }, |
| 235 | - { Icon: IconNote, titleKey: "nav.notes", to: "/notes", descKey: "dashboard.portal.notesDesc", stat: nc }, | ||
| 236 | ); | 236 | ); |
| 237 | return list; | 237 | return list; |
| 238 | } | 238 | } |
| 239 | 239 | ||
| 240 | if (r === "teacher") { | 240 | if (r === "teacher") { |
| 241 | list.push( | 241 | list.push( |
| 242 | + { Icon: IconChart, titleKey: "nav.studentMarks", to: "/management/student-marks", descKey: "dashboard.portal.studentMarksDesc", minRole: "teacher" }, | ||
| 243 | + { Icon: IconClipboardCheck, titleKey: "nav.studentAttendance", to: "/management/student-attendance", descKey: "dashboard.portal.attendanceDesc", minRole: "teacher" }, | ||
| 242 | { Icon: IconBook, titleKey: "nav.courses", to: "/courses", descKey: "dashboard.portal.coursesDesc", stat: cc }, | 244 | { Icon: IconBook, titleKey: "nav.courses", to: "/courses", descKey: "dashboard.portal.coursesDesc", stat: cc }, |
| 243 | - { Icon: IconClock, titleKey: "nav.studies", to: "/studies", descKey: "dashboard.portal.studiesDesc", stat: sc }, | ||
| 244 | - { Icon: IconUsers, titleKey: "nav.clubs", to: "/clubs", descKey: "dashboard.portal.clubsDesc", stat: clc }, | ||
| 245 | { Icon: IconExam, titleKey: "nav.exams", to: "/exams", descKey: "dashboard.portal.examsDesc", stat: ec }, | 245 | { Icon: IconExam, titleKey: "nav.exams", to: "/exams", descKey: "dashboard.portal.examsDesc", stat: ec }, |
| 246 | { Icon: IconCalendar, titleKey: "nav.events", to: "/events", descKey: "dashboard.portal.eventsDesc", stat: evc, minRole: "teacher" }, | 246 | { Icon: IconCalendar, titleKey: "nav.events", to: "/events", descKey: "dashboard.portal.eventsDesc", stat: evc, minRole: "teacher" }, |
| 247 | - { Icon: IconChart, titleKey: "nav.studentMarks", to: "/management/student-marks", descKey: "dashboard.portal.studentMarksDesc", minRole: "teacher" }, | 247 | + { Icon: IconClock, titleKey: "nav.studies", to: "/studies", descKey: "dashboard.portal.studiesDesc", stat: sc }, |
| 248 | + { Icon: IconClock, titleKey: "nav.studentPomodoro", to: "/management/pomodoros", descKey: "dashboard.portal.pomodoroDesc", minRole: "teacher" }, | ||
| 249 | + { Icon: IconBriefcase, titleKey: "nav.work", to: "/work", descKey: "dashboard.portal.workDesc", minRole: "teacher" }, | ||
| 250 | + { Icon: IconNote, titleKey: "nav.notes", to: "/notes", descKey: "dashboard.portal.notesDesc", stat: nc }, | ||
| 251 | + { Icon: IconUsers, titleKey: "nav.clubs", to: "/clubs", descKey: "dashboard.portal.clubsDesc", stat: clc }, | ||
| 252 | + { Icon: IconMessage, titleKey: "nav.messages", to: "/messages" }, | ||
| 253 | + ); | ||
| 254 | + return list; | ||
| 255 | + } | ||
| 256 | + | ||
| 257 | + if (r === "manager") { | ||
| 258 | + list.push( | ||
| 259 | + { Icon: IconBriefcase, titleKey: "nav.staffWork", to: "/management/staff-work", descKey: "dashboard.portal.workDesc", minRole: "manager" }, | ||
| 248 | { Icon: IconClipboardCheck, titleKey: "nav.studentAttendance", to: "/management/student-attendance", descKey: "dashboard.portal.attendanceDesc", minRole: "teacher" }, | 260 | { Icon: IconClipboardCheck, titleKey: "nav.studentAttendance", to: "/management/student-attendance", descKey: "dashboard.portal.attendanceDesc", minRole: "teacher" }, |
| 261 | + { Icon: IconChart, titleKey: "nav.studentMarks", to: "/management/student-marks", descKey: "dashboard.portal.studentMarksDesc", minRole: "teacher" }, | ||
| 262 | + { Icon: IconBook, titleKey: "nav.courses", to: "/courses", descKey: "dashboard.portal.coursesDesc", stat: cc }, | ||
| 263 | + { Icon: IconExam, titleKey: "nav.exams", to: "/exams", descKey: "dashboard.portal.examsDesc", stat: ec }, | ||
| 264 | + { Icon: IconCalendar, titleKey: "nav.events", to: "/events", descKey: "dashboard.portal.eventsDesc", stat: evc }, | ||
| 265 | + { Icon: IconCalendarDays, titleKey: "nav.terms", to: "/management/terms", descKey: "dashboard.portal.termsDesc", minRole: "manager" }, | ||
| 266 | + { Icon: IconSettings, titleKey: "nav.settings", to: "/management/settings", descKey: "dashboard.portal.settingsDesc", minRole: "manager" }, | ||
| 267 | + { Icon: IconClock, titleKey: "nav.studies", to: "/studies", descKey: "dashboard.portal.studiesDesc", stat: sc }, | ||
| 268 | + { Icon: IconUsers, titleKey: "nav.clubs", to: "/clubs", descKey: "dashboard.portal.clubsDesc", stat: clc }, | ||
| 249 | { Icon: IconClock, titleKey: "nav.studentPomodoro", to: "/management/pomodoros", descKey: "dashboard.portal.pomodoroDesc", minRole: "teacher" }, | 269 | { Icon: IconClock, titleKey: "nav.studentPomodoro", to: "/management/pomodoros", descKey: "dashboard.portal.pomodoroDesc", minRole: "teacher" }, |
| 250 | { Icon: IconBriefcase, titleKey: "nav.work", to: "/work", descKey: "dashboard.portal.workDesc", minRole: "teacher" }, | 270 | { Icon: IconBriefcase, titleKey: "nav.work", to: "/work", descKey: "dashboard.portal.workDesc", minRole: "teacher" }, |
| 251 | { Icon: IconMessage, titleKey: "nav.messages", to: "/messages" }, | 271 | { Icon: IconMessage, titleKey: "nav.messages", to: "/messages" }, |
| @@ -254,37 +274,46 @@ function DashboardContent() { | |||
| 254 | return list; | 274 | return list; |
| 255 | } | 275 | } |
| 256 | 276 | ||
| 257 | - // manager + admin | 277 | + // admin |
| 258 | list.push( | 278 | list.push( |
| 279 | + { Icon: IconUsers, titleKey: "nav.users", to: "/admin/users", descKey: "dashboard.portal.usersDesc", minRole: "admin" }, | ||
| 280 | + { Icon: IconSettings, titleKey: "nav.settings", to: "/management/settings", descKey: "dashboard.portal.settingsDesc", minRole: "manager" }, | ||
| 281 | + { Icon: IconCalendarDays, titleKey: "nav.terms", to: "/management/terms", descKey: "dashboard.portal.termsDesc", minRole: "manager" }, | ||
| 282 | + { Icon: IconBriefcase, titleKey: "nav.staffWork", to: "/management/staff-work", descKey: "dashboard.portal.workDesc", minRole: "manager" }, | ||
| 283 | + { Icon: IconChart, titleKey: "nav.studentMarks", to: "/management/student-marks", descKey: "dashboard.portal.studentMarksDesc", minRole: "teacher" }, | ||
| 284 | + { Icon: IconClipboardCheck, titleKey: "nav.studentAttendance", to: "/management/student-attendance", descKey: "dashboard.portal.attendanceDesc", minRole: "teacher" }, | ||
| 259 | { Icon: IconBook, titleKey: "nav.courses", to: "/courses", descKey: "dashboard.portal.coursesDesc", stat: cc }, | 285 | { Icon: IconBook, titleKey: "nav.courses", to: "/courses", descKey: "dashboard.portal.coursesDesc", stat: cc }, |
| 260 | - { Icon: IconClock, titleKey: "nav.studies", to: "/studies", descKey: "dashboard.portal.studiesDesc", stat: sc }, | ||
| 261 | - { Icon: IconUsers, titleKey: "nav.clubs", to: "/clubs", descKey: "dashboard.portal.clubsDesc", stat: clc }, | ||
| 262 | { Icon: IconExam, titleKey: "nav.exams", to: "/exams", descKey: "dashboard.portal.examsDesc", stat: ec }, | 286 | { Icon: IconExam, titleKey: "nav.exams", to: "/exams", descKey: "dashboard.portal.examsDesc", stat: ec }, |
| 263 | { Icon: IconCalendar, titleKey: "nav.events", to: "/events", descKey: "dashboard.portal.eventsDesc", stat: evc }, | 287 | { Icon: IconCalendar, titleKey: "nav.events", to: "/events", descKey: "dashboard.portal.eventsDesc", stat: evc }, |
| 264 | - { Icon: IconChart, titleKey: "nav.studentMarks", to: "/management/student-marks", descKey: "dashboard.portal.studentMarksDesc", minRole: "teacher" }, | 288 | + { Icon: IconClock, titleKey: "nav.studies", to: "/studies", descKey: "dashboard.portal.studiesDesc", stat: sc }, |
| 265 | - { Icon: IconClipboardCheck, titleKey: "nav.studentAttendance", to: "/management/student-attendance", descKey: "dashboard.portal.attendanceDesc", minRole: "teacher" }, | 289 | + { Icon: IconUsers, titleKey: "nav.clubs", to: "/clubs", descKey: "dashboard.portal.clubsDesc", stat: clc }, |
| 266 | { Icon: IconClock, titleKey: "nav.studentPomodoro", to: "/management/pomodoros", descKey: "dashboard.portal.pomodoroDesc", minRole: "teacher" }, | 290 | { Icon: IconClock, titleKey: "nav.studentPomodoro", to: "/management/pomodoros", descKey: "dashboard.portal.pomodoroDesc", minRole: "teacher" }, |
| 267 | { Icon: IconMessage, titleKey: "nav.messages", to: "/messages" }, | 291 | { Icon: IconMessage, titleKey: "nav.messages", to: "/messages" }, |
| 268 | { Icon: IconNote, titleKey: "nav.notes", to: "/notes", descKey: "dashboard.portal.notesDesc", stat: nc }, | 292 | { Icon: IconNote, titleKey: "nav.notes", to: "/notes", descKey: "dashboard.portal.notesDesc", stat: nc }, |
| 269 | - { Icon: IconSettings, titleKey: "nav.settings", to: "/management/settings", descKey: "dashboard.portal.settingsDesc", minRole: "manager" }, | ||
| 270 | - { Icon: IconCalendarDays, titleKey: "nav.terms", to: "/management/terms", descKey: "dashboard.portal.termsDesc", minRole: "manager" }, | ||
| 271 | ); | 293 | ); |
| 272 | - if (r === "manager") { | ||
| 273 | - list.push({ Icon: IconBriefcase, titleKey: "nav.work", to: "/work", descKey: "dashboard.portal.workDesc", minRole: "teacher" }); | ||
| 274 | - } | ||
| 275 | - list.push({ Icon: IconBriefcase, titleKey: "nav.staffWork", to: "/management/staff-work", descKey: "dashboard.portal.workDesc", minRole: "manager" }); | ||
| 276 | - if (r === "admin") { | ||
| 277 | - list.push({ Icon: IconUsers, titleKey: "nav.users", to: "/admin/users", descKey: "dashboard.portal.usersDesc", minRole: "admin" }); | ||
| 278 | - } | ||
| 279 | return list; | 294 | return list; |
| 280 | }); | 295 | }); |
| 281 | const portalOrderKey = () => `${PORTAL_ORDER_KEY}.${role()}`; | 296 | const portalOrderKey = () => `${PORTAL_ORDER_KEY}.${role()}`; |
| 282 | const cardsFromOrder = (cards: PortalCardDef[], order: string[]) => { | 297 | const cardsFromOrder = (cards: PortalCardDef[], order: string[]) => { |
| 283 | const byId = new Map(cards.map((card) => [card.to, card])); | 298 | const byId = new Map(cards.map((card) => [card.to, card])); |
| 284 | - if (order.some((id) => !byId.has(id)) || order.length !== cards.length) return cards; | 299 | + const ordered: PortalCardDef[] = []; |
| 285 | - const ordered = order.flatMap((id) => byId.get(id) ? [byId.get(id)!] : []); | 300 | + const seen = new Set<string>(); |
| 286 | - const seen = new Set(ordered.map((card) => card.to)); | 301 | + |
| 287 | - return [...ordered, ...cards.filter((card) => !seen.has(card.to))]; | 302 | + for (const id of order) { |
| 303 | + const card = byId.get(id); | ||
| 304 | + if (card && !seen.has(id)) { | ||
| 305 | + ordered.push(card); | ||
| 306 | + seen.add(id); | ||
| 307 | + } | ||
| 308 | + } | ||
| 309 | + | ||
| 310 | + for (const card of cards) { | ||
| 311 | + if (!seen.has(card.to)) { | ||
| 312 | + ordered.push(card); | ||
| 313 | + } | ||
| 314 | + } | ||
| 315 | + | ||
| 316 | + return ordered; | ||
| 288 | }; | 317 | }; |
| 289 | const baseOrderedPortalCards = createMemo(() => cardsFromOrder(portalCards(), portalOrder())); | 318 | const baseOrderedPortalCards = createMemo(() => cardsFromOrder(portalCards(), portalOrder())); |
| 290 | const orderedPortalCards = createMemo(() => { | 319 | const orderedPortalCards = createMemo(() => { |
| @@ -301,25 +330,34 @@ function DashboardContent() { | |||
| 301 | }); | 330 | }); |
| 302 | const movePortalCard = (from: string, to: string) => { | 331 | const movePortalCard = (from: string, to: string) => { |
| 303 | if (from === to) return; | 332 | if (from === to) return; |
| 304 | - const ids = (previewPortalOrder() ?? (() => { | 333 | + const current = baseOrderedPortalCards().map((card) => card.to); |
| 305 | - const next = baseOrderedPortalCards().map((card) => card.to); | 334 | + const fromIndex = current.indexOf(from); |
| 306 | - const fromIndex = next.indexOf(from); | 335 | + const toIndex = current.indexOf(to); |
| 307 | - const toIndex = next.indexOf(to); | 336 | + if (fromIndex >= 0 && toIndex >= 0) { |
| 308 | - if (fromIndex >= 0 && toIndex >= 0) next.splice(toIndex, 0, next.splice(fromIndex, 1)[0]); | 337 | + const ids = current.slice(); |
| 309 | - return next; | 338 | + ids.splice(toIndex, 0, ids.splice(fromIndex, 1)[0]); |
| 310 | - })()).slice(); | 339 | + setPortalOrder(ids); |
| 340 | + setPreviewPortalOrder(null); | ||
| 341 | + window.localStorage.setItem(portalOrderKey(), JSON.stringify(ids)); | ||
| 342 | + } | ||
| 343 | + }; | ||
| 344 | + const moveCardByDelta = (cardTo: string, delta: number) => { | ||
| 345 | + const current = baseOrderedPortalCards().map((card) => card.to); | ||
| 346 | + const index = current.indexOf(cardTo); | ||
| 347 | + if (index < 0) return; | ||
| 348 | + const targetIndex = index + delta; | ||
| 349 | + if (targetIndex < 0 || targetIndex >= current.length) return; | ||
| 350 | + const ids = current.slice(); | ||
| 351 | + const [item] = ids.splice(index, 1); | ||
| 352 | + ids.splice(targetIndex, 0, item); | ||
| 311 | setPortalOrder(ids); | 353 | setPortalOrder(ids); |
| 312 | setPreviewPortalOrder(null); | 354 | setPreviewPortalOrder(null); |
| 313 | window.localStorage.setItem(portalOrderKey(), JSON.stringify(ids)); | 355 | window.localStorage.setItem(portalOrderKey(), JSON.stringify(ids)); |
| 314 | }; | 356 | }; |
| 315 | - const previewMovePortalCard = (from: string, to: string) => { | 357 | + const resetPortalOrder = () => { |
| 316 | - if (from === to) return; | 358 | + setPortalOrder([]); |
| 317 | - const ids = (previewPortalOrder() ?? baseOrderedPortalCards().map((card) => card.to)).slice(); | 359 | + setPreviewPortalOrder(null); |
| 318 | - const fromIndex = ids.indexOf(from); | 360 | + window.localStorage.removeItem(portalOrderKey()); |
| 319 | - const toIndex = ids.indexOf(to); | ||
| 320 | - if (fromIndex < 0 || toIndex < 0) return; | ||
| 321 | - ids.splice(toIndex, 0, ids.splice(fromIndex, 1)[0]); | ||
| 322 | - setPreviewPortalOrder(ids); | ||
| 323 | }; | 361 | }; |
| 324 | 362 | ||
| 325 | const attention = createMemo<AttentionItem[]>(() => { | 363 | const attention = createMemo<AttentionItem[]>(() => { |
| @@ -404,34 +442,47 @@ function DashboardContent() { | |||
| 404 | <h2 id="dash-sections" class="text-sm font-semibold tracking-tight text-foreground"> | 442 | <h2 id="dash-sections" class="text-sm font-semibold tracking-tight text-foreground"> |
| 405 | {t("dashboard.roleLinks")} | 443 | {t("dashboard.roleLinks")} |
| 406 | </h2> | 444 | </h2> |
| 407 | - <Button type="button" variant="outline" size="sm" class="h-8 rounded-md" onClick={() => setEditingPortalOrder((value) => !value)}> | 445 | + <div class="flex items-center gap-2"> |
| 408 | - {editingPortalOrder() ? t("common.done") : t("common.edit")} | 446 | + <Show when={editingPortalOrder()}> |
| 409 | - </Button> | 447 | + <Button type="button" variant="ghost" size="sm" class="h-8 rounded-lg text-xs" onClick={resetPortalOrder}> |
| 448 | + {t("common.remove")} | ||
| 449 | + </Button> | ||
| 450 | + </Show> | ||
| 451 | + <Button type="button" variant="outline" size="sm" class="h-8 rounded-lg text-xs font-semibold" onClick={() => setEditingPortalOrder((value) => !value)}> | ||
| 452 | + {editingPortalOrder() ? t("common.done") : t("common.edit")} | ||
| 453 | + </Button> | ||
| 454 | + </div> | ||
| 410 | </div> | 455 | </div> |
| 411 | <div class="grid grid-cols-1 gap-3 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4"> | 456 | <div class="grid grid-cols-1 gap-3 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4"> |
| 412 | <For each={orderedPortalCards()}> | 457 | <For each={orderedPortalCards()}> |
| 413 | - {(card) => ( | 458 | + {(card, index) => ( |
| 414 | <PortalCard | 459 | <PortalCard |
| 415 | card={card} | 460 | card={card} |
| 416 | editing={editingPortalOrder()} | 461 | editing={editingPortalOrder()} |
| 462 | + isFirst={index() === 0} | ||
| 463 | + isLast={index() === orderedPortalCards().length - 1} | ||
| 464 | + onMoveLeft={() => moveCardByDelta(card.to, -1)} | ||
| 465 | + onMoveRight={() => moveCardByDelta(card.to, 1)} | ||
| 417 | dragging={draggingPortal() === card.to} | 466 | dragging={draggingPortal() === card.to} |
| 418 | preview={dragOverPortal() === card.to && draggingPortal() !== card.to} | 467 | preview={dragOverPortal() === card.to && draggingPortal() !== card.to} |
| 419 | onDragStart={() => setDraggingPortal(card.to)} | 468 | onDragStart={() => setDraggingPortal(card.to)} |
| 420 | onDragEnd={() => { | 469 | onDragEnd={() => { |
| 421 | setDraggingPortal(null); | 470 | setDraggingPortal(null); |
| 422 | setDragOverPortal(null); | 471 | setDragOverPortal(null); |
| 423 | - setPreviewPortalOrder(null); | ||
| 424 | }} | 472 | }} |
| 425 | onDragOver={() => { | 473 | onDragOver={() => { |
| 426 | - const source = draggingPortal(); | 474 | + if (draggingPortal() && draggingPortal() !== card.to) { |
| 427 | - setDragOverPortal(card.to); | 475 | + setDragOverPortal(card.to); |
| 428 | - if (source) previewMovePortalCard(source, card.to); | 476 | + } |
| 429 | }} | 477 | }} |
| 430 | - onDrop={(target) => { | 478 | + onDrop={() => { |
| 431 | const source = draggingPortal(); | 479 | const source = draggingPortal(); |
| 480 | + const target = card.to; | ||
| 432 | setDraggingPortal(null); | 481 | setDraggingPortal(null); |
| 433 | setDragOverPortal(null); | 482 | setDragOverPortal(null); |
| 434 | - if (source) movePortalCard(source, target); | 483 | + if (source && target && source !== target) { |
| 484 | + movePortalCard(source, target); | ||
| 485 | + } | ||
| 435 | }} | 486 | }} |
| 436 | /> | 487 | /> |
| 437 | )} | 488 | )} |
| @@ -509,43 +560,26 @@ function DashEmpty(props: { children: string }) { | |||
| 509 | ); | 560 | ); |
| 510 | } | 561 | } |
| 511 | 562 | ||
| 512 | -function PortalCard(props: { card: PortalCardDef; editing: boolean; dragging: boolean; preview: boolean; onDragStart: () => void; onDragEnd: () => void; onDragOver: () => void; onDrop: (target: string) => void }) { | 563 | +function PortalCard(props: { |
| 564 | + card: PortalCardDef; | ||
| 565 | + editing: boolean; | ||
| 566 | + isFirst?: boolean; | ||
| 567 | + isLast?: boolean; | ||
| 568 | + onMoveLeft?: () => void; | ||
| 569 | + onMoveRight?: () => void; | ||
| 570 | + dragging: boolean; | ||
| 571 | + preview: boolean; | ||
| 572 | + onDragStart: () => void; | ||
| 573 | + onDragEnd: () => void; | ||
| 574 | + onDragOver: () => void; | ||
| 575 | + onDrop: (target: string) => void; | ||
| 576 | +}) { | ||
| 513 | const t = useT(); | 577 | const t = useT(); |
| 514 | const Icon = props.card.Icon; | 578 | const Icon = props.card.Icon; |
| 515 | const hasStat = () => props.card.stat != null && props.card.stat !== ""; | 579 | const hasStat = () => props.card.stat != null && props.card.stat !== ""; |
| 516 | 580 | ||
| 517 | - return ( | 581 | + const cardInner = () => ( |
| 518 | - <Link | 582 | + <> |
| 519 | - to={props.card.to} | ||
| 520 | - draggable={props.editing} | ||
| 521 | - onClick={(event) => { | ||
| 522 | - if (props.editing) event.preventDefault(); | ||
| 523 | - }} | ||
| 524 | - onDragStart={(event) => { | ||
| 525 | - if (!props.editing) return; | ||
| 526 | - event.dataTransfer?.setData("text/plain", props.card.to); | ||
| 527 | - event.dataTransfer?.setDragImage(event.currentTarget, 12, 12); | ||
| 528 | - props.onDragStart(); | ||
| 529 | - }} | ||
| 530 | - onDragEnd={props.onDragEnd} | ||
| 531 | - onDragOver={(event) => { | ||
| 532 | - if (!props.editing) return; | ||
| 533 | - event.preventDefault(); | ||
| 534 | - props.onDragOver(); | ||
| 535 | - }} | ||
| 536 | - onDrop={(event) => { | ||
| 537 | - if (!props.editing) return; | ||
| 538 | - event.preventDefault(); | ||
| 539 | - props.onDrop(props.card.to); | ||
| 540 | - }} | ||
| 541 | - class={cn( | ||
| 542 | - "group relative flex min-h-[6rem] items-start gap-3.5 overflow-hidden rounded-2xl border border-black/[0.06] dark:border-white/[0.08] bg-card p-4 shadow-apple transition-all duration-200 hover:shadow-apple-hover hover:border-primary/40 active:scale-[0.98] sm:min-h-[6.5rem]", | ||
| 543 | - props.editing && "cursor-move border-dashed", | ||
| 544 | - props.editing && !props.dragging && "dashboard-jiggle", | ||
| 545 | - props.preview && "scale-[1.02] border-primary/70 bg-primary/10 opacity-80 shadow-apple-hover", | ||
| 546 | - props.dragging && "scale-[0.98] border-primary/50 opacity-60", | ||
| 547 | - )} | ||
| 548 | - > | ||
| 549 | <span class="mt-0.5 flex h-10 w-10 shrink-0 items-center justify-center rounded-xl border border-black/[0.05] dark:border-white/[0.08] bg-muted/30 text-muted-foreground transition-colors group-hover:border-primary/40 group-hover:bg-primary/10 group-hover:text-primary"> | 583 | <span class="mt-0.5 flex h-10 w-10 shrink-0 items-center justify-center rounded-xl border border-black/[0.05] dark:border-white/[0.08] bg-muted/30 text-muted-foreground transition-colors group-hover:border-primary/40 group-hover:bg-primary/10 group-hover:text-primary"> |
| 550 | <Icon class="h-5 w-5" /> | 584 | <Icon class="h-5 w-5" /> |
| 551 | </span> | 585 | </span> |
| @@ -570,7 +604,95 @@ function PortalCard(props: { card: PortalCardDef; editing: boolean; dragging: bo | |||
| 570 | <p class="line-clamp-2 text-xs leading-relaxed text-muted-foreground">{t(props.card.descKey!)}</p> | 604 | <p class="line-clamp-2 text-xs leading-relaxed text-muted-foreground">{t(props.card.descKey!)}</p> |
| 571 | </Show> | 605 | </Show> |
| 572 | </div> | 606 | </div> |
| 573 | - </Link> | 607 | + <Show when={props.editing}> |
| 608 | + <div class="flex items-center gap-1 shrink-0 ml-1"> | ||
| 609 | + <Button | ||
| 610 | + type="button" | ||
| 611 | + variant="outline" | ||
| 612 | + size="sm" | ||
| 613 | + class="h-7 w-7 p-0 rounded-lg border-primary/30 text-xs font-bold shadow-none hover:bg-primary/15 disabled:opacity-30" | ||
| 614 | + disabled={props.isFirst} | ||
| 615 | + onClick={(e) => { | ||
| 616 | + e.preventDefault(); | ||
| 617 | + e.stopPropagation(); | ||
| 618 | + props.onMoveLeft?.(); | ||
| 619 | + }} | ||
| 620 | + title="Move Earlier" | ||
| 621 | + > | ||
| 622 | + ← | ||
| 623 | + </Button> | ||
| 624 | + <Button | ||
| 625 | + type="button" | ||
| 626 | + variant="outline" | ||
| 627 | + size="sm" | ||
| 628 | + class="h-7 w-7 p-0 rounded-lg border-primary/30 text-xs font-bold shadow-none hover:bg-primary/15 disabled:opacity-30" | ||
| 629 | + disabled={props.isLast} | ||
| 630 | + onClick={(e) => { | ||
| 631 | + e.preventDefault(); | ||
| 632 | + e.stopPropagation(); | ||
| 633 | + props.onMoveRight?.(); | ||
| 634 | + }} | ||
| 635 | + title="Move Later" | ||
| 636 | + > | ||
| 637 | + → | ||
| 638 | + </Button> | ||
| 639 | + </div> | ||
| 640 | + </Show> | ||
| 641 | + </> | ||
| 642 | + ); | ||
| 643 | + | ||
| 644 | + const cardClass = () => | ||
| 645 | + cn( | ||
| 646 | + "group relative flex min-h-[6rem] items-start gap-3.5 overflow-hidden rounded-2xl border border-black/[0.06] dark:border-white/[0.08] bg-card p-4 shadow-apple transition-all duration-200 hover:shadow-apple-hover hover:border-primary/40 sm:min-h-[6.5rem]", | ||
| 647 | + !props.editing && "active:scale-[0.98]", | ||
| 648 | + props.editing && "cursor-grab select-none border-dashed border-primary/50 bg-primary/[0.03]", | ||
| 649 | + props.editing && !props.dragging && "dashboard-jiggle", | ||
| 650 | + props.preview && "scale-[1.02] border-primary/70 bg-primary/10 opacity-80 shadow-apple-hover", | ||
| 651 | + props.dragging && "scale-[0.98] border-primary/50 opacity-50", | ||
| 652 | + ); | ||
| 653 | + | ||
| 654 | + return ( | ||
| 655 | + <Show | ||
| 656 | + when={props.editing} | ||
| 657 | + fallback={ | ||
| 658 | + <Link to={props.card.to} class={cardClass()}> | ||
| 659 | + {cardInner()} | ||
| 660 | + </Link> | ||
| 661 | + } | ||
| 662 | + > | ||
| 663 | + <div | ||
| 664 | + draggable={true} | ||
| 665 | + onDragStart={(event) => { | ||
| 666 | + if (event.dataTransfer) { | ||
| 667 | + event.dataTransfer.effectAllowed = "move"; | ||
| 668 | + event.dataTransfer.setData("text/plain", props.card.to); | ||
| 669 | + } | ||
| 670 | + props.onDragStart(); | ||
| 671 | + }} | ||
| 672 | + onDragEnd={(event) => { | ||
| 673 | + event.preventDefault(); | ||
| 674 | + props.onDragEnd(); | ||
| 675 | + }} | ||
| 676 | + onDragOver={(event) => { | ||
| 677 | + event.preventDefault(); | ||
| 678 | + if (event.dataTransfer) { | ||
| 679 | + event.dataTransfer.dropEffect = "move"; | ||
| 680 | + } | ||
| 681 | + props.onDragOver(); | ||
| 682 | + }} | ||
| 683 | + onDragEnter={(event) => { | ||
| 684 | + event.preventDefault(); | ||
| 685 | + }} | ||
| 686 | + onDrop={(event) => { | ||
| 687 | + event.preventDefault(); | ||
| 688 | + event.stopPropagation(); | ||
| 689 | + props.onDrop(props.card.to); | ||
| 690 | + }} | ||
| 691 | + class={cardClass()} | ||
| 692 | + > | ||
| 693 | + {cardInner()} | ||
| 694 | + </div> | ||
| 695 | + </Show> | ||
| 574 | ); | 696 | ); |
| 575 | } | 697 | } |
| 576 | 698 | ||