✨ dashboard portal cards drag-to-reorder with local storage persistence
Browse files at this commitca3da20d58127a1bd5fb0e5c81a7d68d91641b7bParent: 6cf99b1- feat
- ✨ dashboard portal cards drag-to-reorder with local storage persistence
3 changed files +99 -7
- src/i18n/messages.ts +3 -0
- src/index.css +15 -0
- src/pages/dashboard-page.tsx +81 -7
src/i18n/messages.tsmodified+3 -0
| @@ -39,6 +39,7 @@ export type MessageKey = | ||
| 39 | 39 | | "common.save" |
| 40 | 40 | | "common.create" |
| 41 | 41 | | "common.edit" |
| 42 | + | "common.done" | |
| 42 | 43 | | "common.delete" |
| 43 | 44 | | "common.update" |
| 44 | 45 | | "common.remove" |
| @@ -627,6 +628,7 @@ const en: Dict = { | ||
| 627 | 628 | "common.save": "Save", |
| 628 | 629 | "common.create": "Create", |
| 629 | 630 | "common.edit": "Edit", |
| 631 | + "common.done": "Done", | |
| 630 | 632 | "common.delete": "Delete", |
| 631 | 633 | "common.update": "Update", |
| 632 | 634 | "common.remove": "Remove", |
| @@ -1227,6 +1229,7 @@ const tr: Dict = { | ||
| 1227 | 1229 | "common.save": "Kaydet", |
| 1228 | 1230 | "common.create": "Oluştur", |
| 1229 | 1231 | "common.edit": "Düzenle", |
| 1232 | + "common.done": "Bitti", | |
| 1230 | 1233 | "common.delete": "Sil", |
| 1231 | 1234 | "common.update": "Güncelle", |
| 1232 | 1235 | "common.remove": "Kaldır", |
src/index.cssmodified+15 -0
| @@ -160,6 +160,21 @@ | ||
| 160 | 160 | background-color: hsl(var(--primary) / 0.045); |
| 161 | 161 | } |
| 162 | 162 | |
| 163 | + @keyframes dashboard-jiggle { | |
| 164 | + 0%, 100% { transform: rotate(-0.35deg) translateY(0); } | |
| 165 | + 50% { transform: rotate(0.35deg) translateY(-1px); } | |
| 166 | + } | |
| 167 | + | |
| 168 | + .dashboard-jiggle { | |
| 169 | + animation: dashboard-jiggle 160ms ease-in-out infinite; | |
| 170 | + } | |
| 171 | + | |
| 172 | + @media (prefers-reduced-motion: reduce) { | |
| 173 | + .dashboard-jiggle { | |
| 174 | + animation: none; | |
| 175 | + } | |
| 176 | + } | |
| 177 | + | |
| 163 | 178 | .detail-breadcrumb { |
| 164 | 179 | @apply flex flex-wrap items-center gap-1 text-xs text-muted-foreground; |
| 165 | 180 | } |
src/pages/dashboard-page.tsxmodified+81 -7
| @@ -1,4 +1,4 @@ | ||
| 1 | -import { For, Show, createMemo, createResource, type Component } from "solid-js"; | |
| 1 | +import { For, Show, createEffect, createMemo, createResource, createSignal, type Component } from "solid-js"; | |
| 2 | 2 | import { Link } from "@tanstack/solid-router"; |
| 3 | 3 | import { formatApiError } from "@/api/client"; |
| 4 | 4 | import { getCourses } from "@/api/getCourses"; |
| @@ -10,6 +10,7 @@ import { getNotes } from "@/api/getNotes"; | ||
| 10 | 10 | import type { Course, Exam, Event, Role } from "@/api/types"; |
| 11 | 11 | import { RouteGuard } from "@/components/layout/route-guard"; |
| 12 | 12 | import { Alert } from "@/components/ui/alert"; |
| 13 | +import { Button } from "@/components/ui/button"; | |
| 13 | 14 | import { |
| 14 | 15 | IconBook, |
| 15 | 16 | IconBriefcase, |
| @@ -37,6 +38,7 @@ import { usePreferences, useT } from "@/stores/preferences-context"; | ||
| 37 | 38 | const WEEK_MS = 7 * 24 * 60 * 60 * 1000; |
| 38 | 39 | const ATTENTION_LIMIT = 8; |
| 39 | 40 | const UPCOMING_LIMIT = 6; |
| 41 | +const PORTAL_ORDER_KEY = "hezarfen.dashboard.portalOrder"; | |
| 40 | 42 | |
| 41 | 43 | type AttentionKind = "active" | "soon" | "today"; |
| 42 | 44 | |
| @@ -107,6 +109,9 @@ function DashboardContent() { | ||
| 107 | 109 | const user = () => auth.user()!; |
| 108 | 110 | const role = () => user().role; |
| 109 | 111 | const now = createNow(); |
| 112 | + const [portalOrder, setPortalOrder] = createSignal<string[]>([]); | |
| 113 | + const [draggingPortal, setDraggingPortal] = createSignal<string | null>(null); | |
| 114 | + const [editingPortalOrder, setEditingPortalOrder] = createSignal(false); | |
| 110 | 115 | |
| 111 | 116 | const [courses] = createResource( |
| 112 | 117 | () => (role() !== "student" ? true : null), |
| @@ -239,6 +244,31 @@ function DashboardContent() { | ||
| 239 | 244 | } |
| 240 | 245 | return list; |
| 241 | 246 | }); |
| 247 | + const portalOrderKey = () => `${PORTAL_ORDER_KEY}.${role()}`; | |
| 248 | + const orderedPortalCards = createMemo(() => { | |
| 249 | + const cards = portalCards(); | |
| 250 | + const byId = new Map(cards.map((card) => [card.to, card])); | |
| 251 | + const ordered = portalOrder().flatMap((id) => byId.get(id) ? [byId.get(id)!] : []); | |
| 252 | + const seen = new Set(ordered.map((card) => card.to)); | |
| 253 | + return [...ordered, ...cards.filter((card) => !seen.has(card.to))]; | |
| 254 | + }); | |
| 255 | + createEffect(() => { | |
| 256 | + try { | |
| 257 | + setPortalOrder(JSON.parse(window.localStorage.getItem(portalOrderKey()) || "[]") as string[]); | |
| 258 | + } catch { | |
| 259 | + setPortalOrder([]); | |
| 260 | + } | |
| 261 | + }); | |
| 262 | + const movePortalCard = (from: string, to: string) => { | |
| 263 | + if (from === to) return; | |
| 264 | + const ids = orderedPortalCards().map((card) => card.to); | |
| 265 | + const fromIndex = ids.indexOf(from); | |
| 266 | + const toIndex = ids.indexOf(to); | |
| 267 | + if (fromIndex < 0 || toIndex < 0) return; | |
| 268 | + ids.splice(toIndex, 0, ids.splice(fromIndex, 1)[0]); | |
| 269 | + setPortalOrder(ids); | |
| 270 | + window.localStorage.setItem(portalOrderKey(), JSON.stringify(ids)); | |
| 271 | + }; | |
| 242 | 272 | |
| 243 | 273 | const attention = createMemo<AttentionItem[]>(() => { |
| 244 | 274 | const n = now(); |
| @@ -343,11 +373,31 @@ function DashboardContent() { | ||
| 343 | 373 | <Show when={!loading()} fallback={<div class="px-4 py-8"><PageSpinner /></div>}> |
| 344 | 374 | <div class="space-y-5 bg-background/40 px-4 py-4 sm:px-5 sm:py-5"> |
| 345 | 375 | <section class="space-y-2.5" aria-labelledby="dash-sections"> |
| 346 | - <h2 id="dash-sections" class="text-sm font-semibold tracking-tight text-foreground"> | |
| 347 | - {t("dashboard.roleLinks")} | |
| 348 | - </h2> | |
| 376 | + <div class="flex items-center justify-between gap-3"> | |
| 377 | + <h2 id="dash-sections" class="text-sm font-semibold tracking-tight text-foreground"> | |
| 378 | + {t("dashboard.roleLinks")} | |
| 379 | + </h2> | |
| 380 | + <Button type="button" variant="outline" size="sm" class="h-8 rounded-sm" onClick={() => setEditingPortalOrder((value) => !value)}> | |
| 381 | + {editingPortalOrder() ? t("common.done") : t("common.edit")} | |
| 382 | + </Button> | |
| 383 | + </div> | |
| 349 | 384 | <div class="grid grid-cols-1 gap-3 sm:grid-cols-2 lg:grid-cols-3"> |
| 350 | - <For each={portalCards()}>{(card) => <PortalCard card={card} />}</For> | |
| 385 | + <For each={orderedPortalCards()}> | |
| 386 | + {(card) => ( | |
| 387 | + <PortalCard | |
| 388 | + card={card} | |
| 389 | + editing={editingPortalOrder()} | |
| 390 | + dragging={draggingPortal() === card.to} | |
| 391 | + onDragStart={() => setDraggingPortal(card.to)} | |
| 392 | + onDragEnd={() => setDraggingPortal(null)} | |
| 393 | + onDrop={(target) => { | |
| 394 | + const source = draggingPortal(); | |
| 395 | + setDraggingPortal(null); | |
| 396 | + if (source) movePortalCard(source, target); | |
| 397 | + }} | |
| 398 | + /> | |
| 399 | + )} | |
| 400 | + </For> | |
| 351 | 401 | </div> |
| 352 | 402 | </section> |
| 353 | 403 | |
| @@ -454,7 +504,7 @@ function DashEmpty(props: { children: string }) { | ||
| 454 | 504 | ); |
| 455 | 505 | } |
| 456 | 506 | |
| 457 | -function PortalCard(props: { card: PortalCardDef }) { | |
| 507 | +function PortalCard(props: { card: PortalCardDef; editing: boolean; dragging: boolean; onDragStart: () => void; onDragEnd: () => void; onDrop: (target: string) => void }) { | |
| 458 | 508 | const t = useT(); |
| 459 | 509 | const Icon = props.card.Icon; |
| 460 | 510 | const hasStat = () => props.card.stat != null && props.card.stat !== ""; |
| @@ -462,7 +512,31 @@ function PortalCard(props: { card: PortalCardDef }) { | ||
| 462 | 512 | return ( |
| 463 | 513 | <Link |
| 464 | 514 | to={props.card.to} |
| 465 | - class="group relative flex min-h-[6rem] items-start gap-3 overflow-hidden rounded-xl border border-border bg-card px-3 py-3 shadow-[0_10px_30px_rgba(15,23,42,0.08)] transition-all before:absolute before:inset-x-0 before:top-0 before:h-0.5 before:bg-primary before:opacity-0 before:transition-opacity hover:-translate-y-0.5 hover:border-primary/50 hover:bg-muted/30 hover:shadow-[0_18px_45px_rgba(15,23,42,0.14)] hover:before:opacity-100 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/60 sm:min-h-[6.5rem] sm:gap-3.5 sm:px-4 sm:py-3.5" | |
| 515 | + draggable={props.editing} | |
| 516 | + onClick={(event) => { | |
| 517 | + if (props.editing) event.preventDefault(); | |
| 518 | + }} | |
| 519 | + onDragStart={(event) => { | |
| 520 | + if (!props.editing) return; | |
| 521 | + event.dataTransfer?.setData("text/plain", props.card.to); | |
| 522 | + event.dataTransfer?.setDragImage(event.currentTarget, 12, 12); | |
| 523 | + props.onDragStart(); | |
| 524 | + }} | |
| 525 | + onDragEnd={props.onDragEnd} | |
| 526 | + onDragOver={(event) => { | |
| 527 | + if (props.editing) event.preventDefault(); | |
| 528 | + }} | |
| 529 | + onDrop={(event) => { | |
| 530 | + if (!props.editing) return; | |
| 531 | + event.preventDefault(); | |
| 532 | + props.onDrop(props.card.to); | |
| 533 | + }} | |
| 534 | + class={cn( | |
| 535 | + "group relative flex min-h-[6rem] items-start gap-3 overflow-hidden rounded-xl border border-border bg-card px-3 py-3 shadow-[0_10px_30px_rgba(15,23,42,0.08)] transition-all before:absolute before:inset-x-0 before:top-0 before:h-0.5 before:bg-primary before:opacity-0 before:transition-opacity hover:-translate-y-0.5 hover:border-primary/50 hover:bg-muted/30 hover:shadow-[0_18px_45px_rgba(15,23,42,0.14)] hover:before:opacity-100 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/60 sm:min-h-[6.5rem] sm:gap-3.5 sm:px-4 sm:py-3.5", | |
| 536 | + props.editing && "cursor-move border-dashed", | |
| 537 | + props.editing && !props.dragging && "dashboard-jiggle", | |
| 538 | + props.dragging && "scale-[0.98] border-primary/50 opacity-60", | |
| 539 | + )} | |
| 466 | 540 | > |
| 467 | 541 | <span class="mt-0.5 flex h-9 w-9 shrink-0 items-center justify-center rounded-md border border-border bg-background text-muted-foreground transition-colors group-hover:border-primary/40 group-hover:text-primary"> |
| 468 | 542 | <Icon class="h-4 w-4" /> |