🏆 pixel-art profile with badge ladders
Browse files at this commit9dcc420643eabc81f90c91b3b19f474820f4e375Parent: 9e04469- feat
- 🏆 pixel-art profile with badge ladders
10 changed files +512 -194
- bun.lock +7 -6
- package.json +1 -0
- src/components/layout/sidebar-account.tsx +6 -2
- src/components/ui/icons.tsx +5 -0
- src/components/ui/pixel-icon.tsx +55 -0
- src/components/users/badge-grid.tsx +251 -166
- src/i18n/messages.ts +81 -0
- src/index.css +10 -0
- src/lib/badges.ts +42 -0
- src/pages/profile-page.tsx +54 -20
bun.lockmodified+7 -6
| @@ -12,6 +12,7 @@ | |||
| 12 | "class-variance-authority": "^0.7.1", | 12 | "class-variance-authority": "^0.7.1", |
| 13 | "clsx": "^2.1.1", | 13 | "clsx": "^2.1.1", |
| 14 | "pdfjs-dist": "^6.1.200", | 14 | "pdfjs-dist": "^6.1.200", |
| 15 | + "pixelarticons": "^2.4.1", | ||
| 15 | "solid-js": "^1.9.14", | 16 | "solid-js": "^1.9.14", |
| 16 | "tailwind-merge": "^3.6.0", | 17 | "tailwind-merge": "^3.6.0", |
| 17 | }, | 18 | }, |
| @@ -356,7 +357,7 @@ | |||
| 356 | 357 | ||
| 357 | "@tanstack/history": ["@tanstack/history@1.162.0", "", {}, "sha512-79pf/RkhteYZTRgcR4F9kbk84P2N8rugQJswxfIqovlbRiT3yI7eBE+5QorIrZaOKktsgzRlXh1l/du/xpl4iA=="], | 358 | "@tanstack/history": ["@tanstack/history@1.162.0", "", {}, "sha512-79pf/RkhteYZTRgcR4F9kbk84P2N8rugQJswxfIqovlbRiT3yI7eBE+5QorIrZaOKktsgzRlXh1l/du/xpl4iA=="], |
| 358 | 359 | ||
| 359 | - "@tanstack/router-core": ["@tanstack/router-core@1.171.14", "", { "dependencies": { "@tanstack/history": "1.162.0", "cookie-es": "^3.0.0", "seroval": "^1.5.4", "seroval-plugins": "^1.5.4" } }, "sha512-Mo3hwx0qB0cJsVYGDjG0+Ouf7VV74h/vsoDMGztdlyzDanp4gBA2s7IVvm6hFrmQM6GpD9F0Z7SqD7OldfLE7g=="], | 360 | + "@tanstack/router-core": ["@tanstack/router-core@1.171.15", "", { "dependencies": { "@tanstack/history": "1.162.0", "cookie-es": "^3.0.0", "seroval": "^1.5.4", "seroval-plugins": "^1.5.4" } }, "sha512-IILCDcLaItMZQ2jEmCABHY1Nhjjn5XUvwpQp3e4Nmu+vfg0BgYFuu/QASz2SwE2ZNbVMrvt8X/wxa+Gg5aErxA=="], |
| 360 | 361 | ||
| 361 | "@tanstack/router-devtools-core": ["@tanstack/router-devtools-core@1.168.0", "", { "dependencies": { "clsx": "^2.1.1", "goober": "^2.1.16" }, "peerDependencies": { "@tanstack/router-core": "^1.170.0", "csstype": "^3.0.10" } }, "sha512-wQoQhlBK7nlZgqzaqdYXKWNTpdHdsaREdaPhFZVH0/Ador+F+eM3/NF2i3f2LPeS0GgKraZUQXe1Q/1+KHyEYg=="], | 362 | "@tanstack/router-devtools-core": ["@tanstack/router-devtools-core@1.168.0", "", { "dependencies": { "clsx": "^2.1.1", "goober": "^2.1.16" }, "peerDependencies": { "@tanstack/router-core": "^1.170.0", "csstype": "^3.0.10" } }, "sha512-wQoQhlBK7nlZgqzaqdYXKWNTpdHdsaREdaPhFZVH0/Ador+F+eM3/NF2i3f2LPeS0GgKraZUQXe1Q/1+KHyEYg=="], |
| 362 | 363 | ||
| @@ -528,7 +529,7 @@ | |||
| 528 | 529 | ||
| 529 | "isbot": ["isbot@5.2.0", "", {}, "sha512-gbZiGCb4B5xaoxg9mS7koAyRdvJnArk10VLSHOgz6rtBG93/pi1xOFaVvXMKZ7JXgyZ8zAbNRK5uIBdIUTFSqw=="], | 530 | "isbot": ["isbot@5.2.0", "", {}, "sha512-gbZiGCb4B5xaoxg9mS7koAyRdvJnArk10VLSHOgz6rtBG93/pi1xOFaVvXMKZ7JXgyZ8zAbNRK5uIBdIUTFSqw=="], |
| 530 | 531 | ||
| 531 | - "jiti": ["jiti@1.21.7", "", { "bin": "bin/jiti.js" }, "sha512-/imKNG4EbWNrVjoNC/1H5/9GFy+tqjGBHCaSsN+P2RnPqjsLmv6UD3Ej+Kj8nBWaRAwyk7kK5ZUc+OEatnTR3A=="], | 532 | + "jiti": ["jiti@2.7.0", "", { "bin": { "jiti": "lib/jiti-cli.mjs" } }, "sha512-AC/7JofJvZGrrneWNaEnJeOLUx+JlGt7tNa0wZiRPT4MY1wmfKjt2+6O2p2uz2+skll8OZZmJMNqeke7kKbNgQ=="], |
| 532 | 533 | ||
| 533 | "js-tokens": ["js-tokens@4.0.0", "", {}, "sha512-RdJUflcE3cUzKiMqQgsCu06FPu9UdIJO0beYbPhHN4k6apgJtifcoCtT9bcxOpYBtpD2kCM6Sbzg4CausW/PKQ=="], | 534 | "js-tokens": ["js-tokens@4.0.0", "", {}, "sha512-RdJUflcE3cUzKiMqQgsCu06FPu9UdIJO0beYbPhHN4k6apgJtifcoCtT9bcxOpYBtpD2kCM6Sbzg4CausW/PKQ=="], |
| 534 | 535 | ||
| @@ -590,6 +591,8 @@ | |||
| 590 | 591 | ||
| 591 | "picomatch": ["picomatch@4.0.5", "", {}, "sha512-RvwwcruNjI1ncT5xRakeyS9Lf8lcItv34KD+aif+VH9kduAyfYBipGh12274xtenIPZ119/R9BdTBa8gAwSh0A=="], | 592 | "picomatch": ["picomatch@4.0.5", "", {}, "sha512-RvwwcruNjI1ncT5xRakeyS9Lf8lcItv34KD+aif+VH9kduAyfYBipGh12274xtenIPZ119/R9BdTBa8gAwSh0A=="], |
| 592 | 593 | ||
| 594 | + "pixelarticons": ["pixelarticons@2.4.1", "", { "peerDependencies": { "react": ">=16" }, "bin": { "pixelarticons": "bin/upgrade.js" } }, "sha512-NIiwuEmBrFT6YG5PdMnOPRsGm0rbz4TiH0P5sgftjrQugxgdF+xtZPgGrgAOL76KUMJ04kk5Bq2lVLnmBg7IPw=="], | ||
| 595 | + | ||
| 593 | "playwright": ["playwright@1.62.1", "", { "dependencies": { "playwright-core": "1.62.1" }, "optionalDependencies": { "fsevents": "2.3.2" }, "bin": { "playwright": "cli.js" } }, "sha512-0M+L3LAD8/nm554LOla9Ayx0j0tmFZ0FBcoQ7F1VuVHpM/XpiC8RcDzBQB8W5+hA8L22THxELzeF+2WcUzvcLg=="], | 596 | "playwright": ["playwright@1.62.1", "", { "dependencies": { "playwright-core": "1.62.1" }, "optionalDependencies": { "fsevents": "2.3.2" }, "bin": { "playwright": "cli.js" } }, "sha512-0M+L3LAD8/nm554LOla9Ayx0j0tmFZ0FBcoQ7F1VuVHpM/XpiC8RcDzBQB8W5+hA8L22THxELzeF+2WcUzvcLg=="], |
| 594 | 597 | ||
| 595 | "playwright-core": ["playwright-core@1.62.1", "", { "bin": { "playwright-core": "cli.js" } }, "sha512-wPYSwEBJY9GHraISXqyqtx0na0LpO3XEX7jNDhntbex7tzUS7kLnZsOlFruFJB4Hi/rhDMjXGqHewDZ68nYZVw=="], | 598 | "playwright-core": ["playwright-core@1.62.1", "", { "bin": { "playwright-core": "cli.js" } }, "sha512-wPYSwEBJY9GHraISXqyqtx0na0LpO3XEX7jNDhntbex7tzUS7kLnZsOlFruFJB4Hi/rhDMjXGqHewDZ68nYZVw=="], |
| @@ -602,6 +605,8 @@ | |||
| 602 | 605 | ||
| 603 | "pure-rand": ["pure-rand@8.4.2", "", {}, "sha512-vvuOGgcuPJAirlHvuQw1TrOiw7ptaIXXmIbNuiNOY6lNGJJH49PQ1Kj4nd783nPdQhQdicgOjVI2yI/9BD6/Ng=="], | 606 | "pure-rand": ["pure-rand@8.4.2", "", {}, "sha512-vvuOGgcuPJAirlHvuQw1TrOiw7ptaIXXmIbNuiNOY6lNGJJH49PQ1Kj4nd783nPdQhQdicgOjVI2yI/9BD6/Ng=="], |
| 604 | 607 | ||
| 608 | + "react": ["react@19.3.0", "", {}, "sha512-E8LUcbtBWt20bbl2YoHfx4ZDBdxVTfOKtCZn9cDSJ4l6/nuoApcpIBcj47t2wZoVX8g2ZHuMHbiShgCR1T5Sog=="], | ||
| 609 | + | ||
| 605 | "react-is": ["react-is@17.0.2", "", {}, "sha512-w2GsyukL62IJnlaff/nRegPQR94C/XXamvMWmSHRJ4y7Ts/4ocGRmTHvOs8PSE6pB3dWOrD/nueuU5sduBsQ4w=="], | 610 | "react-is": ["react-is@17.0.2", "", {}, "sha512-w2GsyukL62IJnlaff/nRegPQR94C/XXamvMWmSHRJ4y7Ts/4ocGRmTHvOs8PSE6pB3dWOrD/nueuU5sduBsQ4w=="], |
| 606 | 611 | ||
| 607 | "require-from-string": ["require-from-string@2.0.2", "", {}, "sha512-Xf0nWe6RseziFMu+Ap9biiUbmplq6S9/p+7w7YXP/JBHhrUDDUhwa+vANyubuqfZWTveU//DYVGsDG7RKL/vEw=="], | 612 | "require-from-string": ["require-from-string@2.0.2", "", {}, "sha512-Xf0nWe6RseziFMu+Ap9biiUbmplq6S9/p+7w7YXP/JBHhrUDDUhwa+vANyubuqfZWTveU//DYVGsDG7RKL/vEw=="], |
| @@ -696,8 +701,6 @@ | |||
| 696 | 701 | ||
| 697 | "@babel/helper-compilation-targets/lru-cache": ["lru-cache@5.1.1", "", { "dependencies": { "yallist": "^3.0.2" } }, "sha512-KpNARQA3Iwv+jTA0utUVVbrh+Jlrr1Fv0e56GGzAFOXN7dk/FviaDW8LHmK52DlcH4WP2n6gI8vN1aesBFgo9w=="], | 702 | "@babel/helper-compilation-targets/lru-cache": ["lru-cache@5.1.1", "", { "dependencies": { "yallist": "^3.0.2" } }, "sha512-KpNARQA3Iwv+jTA0utUVVbrh+Jlrr1Fv0e56GGzAFOXN7dk/FviaDW8LHmK52DlcH4WP2n6gI8vN1aesBFgo9w=="], |
| 698 | 703 | ||
| 699 | - "@tailwindcss/node/jiti": ["jiti@2.7.0", "", { "bin": { "jiti": "lib/jiti-cli.mjs" } }, "sha512-AC/7JofJvZGrrneWNaEnJeOLUx+JlGt7tNa0wZiRPT4MY1wmfKjt2+6O2p2uz2+skll8OZZmJMNqeke7kKbNgQ=="], | ||
| 700 | - | ||
| 701 | "@tailwindcss/node/lightningcss": ["lightningcss@1.32.0", "", { "dependencies": { "detect-libc": "^2.0.3" }, "optionalDependencies": { "lightningcss-android-arm64": "1.32.0", "lightningcss-darwin-arm64": "1.32.0", "lightningcss-darwin-x64": "1.32.0", "lightningcss-freebsd-x64": "1.32.0", "lightningcss-linux-arm-gnueabihf": "1.32.0", "lightningcss-linux-arm64-gnu": "1.32.0", "lightningcss-linux-arm64-musl": "1.32.0", "lightningcss-linux-x64-gnu": "1.32.0", "lightningcss-linux-x64-musl": "1.32.0", "lightningcss-win32-arm64-msvc": "1.32.0", "lightningcss-win32-x64-msvc": "1.32.0" } }, "sha512-NXYBzinNrblfraPGyrbPoD19C1h9lfI/1mzgWYvXUTe414Gz/X1FD2XBZSZM7rRTrMA8JL3OtAaGifrIKhQ5yQ=="], | 704 | "@tailwindcss/node/lightningcss": ["lightningcss@1.32.0", "", { "dependencies": { "detect-libc": "^2.0.3" }, "optionalDependencies": { "lightningcss-android-arm64": "1.32.0", "lightningcss-darwin-arm64": "1.32.0", "lightningcss-darwin-x64": "1.32.0", "lightningcss-freebsd-x64": "1.32.0", "lightningcss-linux-arm-gnueabihf": "1.32.0", "lightningcss-linux-arm64-gnu": "1.32.0", "lightningcss-linux-arm64-musl": "1.32.0", "lightningcss-linux-x64-gnu": "1.32.0", "lightningcss-linux-x64-musl": "1.32.0", "lightningcss-win32-arm64-msvc": "1.32.0", "lightningcss-win32-x64-msvc": "1.32.0" } }, "sha512-NXYBzinNrblfraPGyrbPoD19C1h9lfI/1mzgWYvXUTe414Gz/X1FD2XBZSZM7rRTrMA8JL3OtAaGifrIKhQ5yQ=="], |
| 702 | 705 | ||
| 703 | "@tailwindcss/oxide-wasm32-wasi/@emnapi/core": ["@emnapi/core@1.11.1", "", { "dependencies": { "@emnapi/wasi-threads": "1.2.2", "tslib": "^2.4.0" }, "bundled": true }, "sha512-RSvbQmHzdKzNsLYa/wHrbc3KN4sYLKAdPZxqiM2HATqv/SBk2/ENSHpvXGaLOMcsAyz0poEGqkmmKYG3OWiJEQ=="], | 706 | "@tailwindcss/oxide-wasm32-wasi/@emnapi/core": ["@emnapi/core@1.11.1", "", { "dependencies": { "@emnapi/wasi-threads": "1.2.2", "tslib": "^2.4.0" }, "bundled": true }, "sha512-RSvbQmHzdKzNsLYa/wHrbc3KN4sYLKAdPZxqiM2HATqv/SBk2/ENSHpvXGaLOMcsAyz0poEGqkmmKYG3OWiJEQ=="], |
| @@ -712,8 +715,6 @@ | |||
| 712 | 715 | ||
| 713 | "@tailwindcss/oxide-wasm32-wasi/tslib": ["tslib@2.8.1", "", { "bundled": true }, "sha512-oJFu94HQb+KVduSUQL7wnpmqnfmLsOA/nAh6b6EH0wCEoK0/mPeXU6c3wKDV83MkOuHPRHtSXKKU99IBazS/2w=="], | 716 | "@tailwindcss/oxide-wasm32-wasi/tslib": ["tslib@2.8.1", "", { "bundled": true }, "sha512-oJFu94HQb+KVduSUQL7wnpmqnfmLsOA/nAh6b6EH0wCEoK0/mPeXU6c3wKDV83MkOuHPRHtSXKKU99IBazS/2w=="], |
| 714 | 717 | ||
| 715 | - "@tanstack/solid-router/@tanstack/router-core": ["@tanstack/router-core@1.171.15", "", { "dependencies": { "@tanstack/history": "1.162.0", "cookie-es": "^3.0.0", "seroval": "^1.5.4", "seroval-plugins": "^1.5.4" } }, "sha512-IILCDcLaItMZQ2jEmCABHY1Nhjjn5XUvwpQp3e4Nmu+vfg0BgYFuu/QASz2SwE2ZNbVMrvt8X/wxa+Gg5aErxA=="], | ||
| 716 | - | ||
| 717 | "babel-plugin-jsx-dom-expressions/@babel/helper-module-imports": ["@babel/helper-module-imports@7.18.6", "", { "dependencies": { "@babel/types": "^7.18.6" } }, "sha512-0NFvs3VkuSYbFi1x2Vd6tKrywq+z/cLeYC/RJNFrIX/30Bf5aiGYbtvGXolEktzJH8o5E5KJ3tT+nkxuuZFVlA=="], | 718 | "babel-plugin-jsx-dom-expressions/@babel/helper-module-imports": ["@babel/helper-module-imports@7.18.6", "", { "dependencies": { "@babel/types": "^7.18.6" } }, "sha512-0NFvs3VkuSYbFi1x2Vd6tKrywq+z/cLeYC/RJNFrIX/30Bf5aiGYbtvGXolEktzJH8o5E5KJ3tT+nkxuuZFVlA=="], |
| 718 | 719 | ||
| 719 | "babel-plugin-jsx-dom-expressions/parse5": ["parse5@7.3.0", "", { "dependencies": { "entities": "^6.0.0" } }, "sha512-IInvU7fabl34qmi9gY8XOVxhYyMyuH2xUNpb2q8/Y+7552KlejkRvqvD19nMoUW/uQGGbqNpA6Tufu5FL5BZgw=="], | 720 | "babel-plugin-jsx-dom-expressions/parse5": ["parse5@7.3.0", "", { "dependencies": { "entities": "^6.0.0" } }, "sha512-IInvU7fabl34qmi9gY8XOVxhYyMyuH2xUNpb2q8/Y+7552KlejkRvqvD19nMoUW/uQGGbqNpA6Tufu5FL5BZgw=="], |
package.jsonmodified+1 -0
| @@ -21,6 +21,7 @@ | |||
| 21 | "class-variance-authority": "^0.7.1", | 21 | "class-variance-authority": "^0.7.1", |
| 22 | "clsx": "^2.1.1", | 22 | "clsx": "^2.1.1", |
| 23 | "pdfjs-dist": "^6.1.200", | 23 | "pdfjs-dist": "^6.1.200", |
| 24 | + "pixelarticons": "^2.4.1", | ||
| 24 | "solid-js": "^1.9.14", | 25 | "solid-js": "^1.9.14", |
| 25 | "tailwind-merge": "^3.6.0" | 26 | "tailwind-merge": "^3.6.0" |
| 26 | }, | 27 | }, |
src/components/layout/sidebar-account.tsxmodified+6 -2
| @@ -12,7 +12,7 @@ import { | |||
| 12 | DropdownMenuSeparator, | 12 | DropdownMenuSeparator, |
| 13 | DropdownMenuTrigger, | 13 | DropdownMenuTrigger, |
| 14 | } from "@/components/ui/dropdown-menu"; | 14 | } from "@/components/ui/dropdown-menu"; |
| 15 | -import { IconChevronRight, IconGlobe, IconGuide, IconLogout, IconSettings } from "@/components/ui/icons"; | 15 | +import { IconChevronRight, IconGlobe, IconGuide, IconLogout, IconSettings, IconUserCircle } from "@/components/ui/icons"; |
| 16 | import { ThemeModeControl } from "@/components/layout/theme-mode-control"; | 16 | import { ThemeModeControl } from "@/components/layout/theme-mode-control"; |
| 17 | import { UserAvatar } from "@/components/users/user-avatar"; | 17 | import { UserAvatar } from "@/components/users/user-avatar"; |
| 18 | import { useAuth } from "@/stores/auth-context"; | 18 | import { useAuth } from "@/stores/auth-context"; |
| @@ -86,11 +86,15 @@ export function SidebarAccount(props: { collapsed?: boolean; onLogout: () => voi | |||
| 86 | <UserAvatar userId={u().id} name={name()} hasAvatar={hasAvatar()} size="md" class="ring-0" /> | 86 | <UserAvatar userId={u().id} name={name()} hasAvatar={hasAvatar()} size="md" class="ring-0" /> |
| 87 | <span class="min-w-0 flex-1"> | 87 | <span class="min-w-0 flex-1"> |
| 88 | <span class="block truncate text-sm font-semibold">{name()}</span> | 88 | <span class="block truncate text-sm font-semibold">{name()}</span> |
| 89 | - <span class="block truncate text-xs text-muted-foreground dark:text-white/60">{t("profile.myProfile")}</span> | 89 | + <span class="block truncate text-xs text-muted-foreground dark:text-white/60">@{u().username}</span> |
| 90 | </span> | 90 | </span> |
| 91 | <IconChevronRight class="h-3.5 w-3.5 shrink-0 text-muted-foreground dark:text-white/50" /> | 91 | <IconChevronRight class="h-3.5 w-3.5 shrink-0 text-muted-foreground dark:text-white/50" /> |
| 92 | </DropdownMenuItem> | 92 | </DropdownMenuItem> |
| 93 | <div class="px-1.5 pb-1.5"> | 93 | <div class="px-1.5 pb-1.5"> |
| 94 | + <DropdownMenuItem class="rounded-lg gap-3 font-medium" onSelect={() => void navigate({ to: "/profile/me" })}> | ||
| 95 | + <IconUserCircle class="h-4 w-4 shrink-0 text-muted-foreground dark:text-white/60" /> | ||
| 96 | + <span>{t("profile.myProfile")}</span> | ||
| 97 | + </DropdownMenuItem> | ||
| 94 | <DropdownMenuItem class="rounded-lg gap-3" onSelect={() => setProfileOpen(true)}> | 98 | <DropdownMenuItem class="rounded-lg gap-3" onSelect={() => setProfileOpen(true)}> |
| 95 | <IconSettings class="h-4 w-4 shrink-0 text-muted-foreground dark:text-white/60" /> | 99 | <IconSettings class="h-4 w-4 shrink-0 text-muted-foreground dark:text-white/60" /> |
| 96 | <span>{t("nav.settings")}</span> | 100 | <span>{t("nav.settings")}</span> |
src/components/ui/icons.tsxmodified+5 -0
| @@ -24,6 +24,7 @@ import eyeUrl from "@phosphor-icons/core/regular/eye.svg?url"; | |||
| 24 | import fileTextUrl from "@phosphor-icons/core/regular/file-text.svg?url"; | 24 | import fileTextUrl from "@phosphor-icons/core/regular/file-text.svg?url"; |
| 25 | import funnelUrl from "@phosphor-icons/core/regular/funnel.svg?url"; | 25 | import funnelUrl from "@phosphor-icons/core/regular/funnel.svg?url"; |
| 26 | import gearUrl from "@phosphor-icons/core/regular/gear.svg?url"; | 26 | import gearUrl from "@phosphor-icons/core/regular/gear.svg?url"; |
| 27 | +import userCircleUrl from "@phosphor-icons/core/regular/user-circle.svg?url"; | ||
| 27 | import graduationCapUrl from "@phosphor-icons/core/regular/graduation-cap.svg?url"; | 28 | import graduationCapUrl from "@phosphor-icons/core/regular/graduation-cap.svg?url"; |
| 28 | import houseUrl from "@phosphor-icons/core/regular/house.svg?url"; | 29 | import houseUrl from "@phosphor-icons/core/regular/house.svg?url"; |
| 29 | import listUrl from "@phosphor-icons/core/regular/list.svg?url"; | 30 | import listUrl from "@phosphor-icons/core/regular/list.svg?url"; |
| @@ -511,6 +512,10 @@ export function IconReportAnalytics(props: IconProps) { | |||
| 511 | return <PhosphorIcon {...props} src={chartLineUpUrl} />; | 512 | return <PhosphorIcon {...props} src={chartLineUpUrl} />; |
| 512 | } | 513 | } |
| 513 | 514 | ||
| 515 | +export function IconUserCircle(props: IconProps) { | ||
| 516 | + return <PhosphorIcon {...props} src={userCircleUrl} />; | ||
| 517 | +} | ||
| 518 | + | ||
| 514 | export function IconSettings(props: IconProps) { | 519 | export function IconSettings(props: IconProps) { |
| 515 | return <PhosphorIcon {...props} src={gearUrl} />; | 520 | return <PhosphorIcon {...props} src={gearUrl} />; |
| 516 | } | 521 | } |
src/components/ui/pixel-icon.tsxadded+55 -0
| @@ -0,0 +1,55 @@ | |||
| 1 | +import chevronDown from "pixelarticons/svg/chevron-down.svg?raw"; | ||
| 2 | +import chevronUp from "pixelarticons/svg/chevron-up.svg?raw"; | ||
| 3 | +import checkDouble from "pixelarticons/svg/check-double.svg?raw"; | ||
| 4 | +import checkboxOn from "pixelarticons/svg/checkbox-on.svg?raw"; | ||
| 5 | +import bookOpen from "pixelarticons/svg/book-open.svg?raw"; | ||
| 6 | +import calendarWeeks from "pixelarticons/svg/calendar-weeks.svg?raw"; | ||
| 7 | +import crown from "pixelarticons/svg/crown.svg?raw"; | ||
| 8 | +import fire from "pixelarticons/svg/fire.svg?raw"; | ||
| 9 | +import hourglass from "pixelarticons/svg/hourglass.svg?raw"; | ||
| 10 | +import lock from "pixelarticons/svg/lock.svg?raw"; | ||
| 11 | +import messageText from "pixelarticons/svg/message-text.svg?raw"; | ||
| 12 | +import notes from "pixelarticons/svg/notes.svg?raw"; | ||
| 13 | +import penSquare from "pixelarticons/svg/pen-square.svg?raw"; | ||
| 14 | +import pencil from "pixelarticons/svg/pencil.svg?raw"; | ||
| 15 | +import sparkles from "pixelarticons/svg/sparkles.svg?raw"; | ||
| 16 | +import star from "pixelarticons/svg/star.svg?raw"; | ||
| 17 | +import trophy from "pixelarticons/svg/trophy.svg?raw"; | ||
| 18 | +import users from "pixelarticons/svg/users.svg?raw"; | ||
| 19 | +import zap from "pixelarticons/svg/zap.svg?raw"; | ||
| 20 | +import { cn } from "@/lib/cn"; | ||
| 21 | + | ||
| 22 | +// Pixel-art glyphs from pixelarticons (MIT, https://pixelarticons.com). Only | ||
| 23 | +// the handful the profile uses are imported, so the rest never reach a bundle. | ||
| 24 | +const ICONS = { | ||
| 25 | + "book-open": bookOpen, | ||
| 26 | + "calendar-weeks": calendarWeeks, | ||
| 27 | + "check-double": checkDouble, | ||
| 28 | + "chevron-down": chevronDown, | ||
| 29 | + "chevron-up": chevronUp, | ||
| 30 | + "checkbox-on": checkboxOn, | ||
| 31 | + crown, | ||
| 32 | + fire, | ||
| 33 | + hourglass, | ||
| 34 | + lock, | ||
| 35 | + "message-text": messageText, | ||
| 36 | + notes, | ||
| 37 | + "pen-square": penSquare, | ||
| 38 | + pencil, | ||
| 39 | + sparkles, | ||
| 40 | + star, | ||
| 41 | + trophy, | ||
| 42 | + users, | ||
| 43 | + zap, | ||
| 44 | +} as const; | ||
| 45 | + | ||
| 46 | +export type PixelIconName = keyof typeof ICONS; | ||
| 47 | + | ||
| 48 | +const sized = (svg: string) => | ||
| 49 | + svg | ||
| 50 | + .replace(/\s(?:width|height)="[^"]*"/g, "") | ||
| 51 | + .replace("<svg", '<svg aria-hidden="true" focusable="false" shape-rendering="crispEdges"'); | ||
| 52 | + | ||
| 53 | +export function PixelIcon(props: { name: PixelIconName; class?: string }) { | ||
| 54 | + return <span class={cn("inline-block shrink-0 [&>svg]:h-full [&>svg]:w-full", props.class ?? "h-4 w-4")} innerHTML={sized(ICONS[props.name])} />; | ||
| 55 | +} | ||
src/components/users/badge-grid.tsxmodified+251 -166
| @@ -1,66 +1,93 @@ | |||
| 1 | -import { Collapsible } from "@kobalte/core/collapsible"; | 1 | +import { For, Show, createMemo, createSignal } from "solid-js"; |
| 2 | -import { For, Match, Show, Switch, createMemo } from "solid-js"; | 2 | +import type { BadgeCatalogEntry, EarnedBadge, ProfileStats, Role } from "@/api/client"; |
| 3 | -import type { BadgeCatalogEntry, EarnedBadge, ProfileStats } from "@/api/client"; | 3 | +import { PixelIcon, type PixelIconName } from "@/components/ui/pixel-icon"; |
| 4 | -import { | ||
| 5 | - IconChevronDown, | ||
| 6 | - IconClipboardCheck, | ||
| 7 | - IconClock, | ||
| 8 | - IconExam, | ||
| 9 | - IconHomework, | ||
| 10 | - IconLock, | ||
| 11 | - IconSparkles, | ||
| 12 | -} from "@/components/ui/icons"; | ||
| 13 | import { Tooltip, TooltipContent, TooltipTrigger } from "@/components/ui/tooltip"; | 4 | import { Tooltip, TooltipContent, TooltipTrigger } from "@/components/ui/tooltip"; |
| 14 | import { | 5 | import { |
| 15 | badgeDescKey, | 6 | badgeDescKey, |
| 7 | + badgeGroupKey, | ||
| 8 | + badgeLadders, | ||
| 9 | + badgeLevel, | ||
| 16 | badgeNameKey, | 10 | badgeNameKey, |
| 17 | badgeProgress, | 11 | badgeProgress, |
| 18 | badgeProgressLabel, | 12 | badgeProgressLabel, |
| 19 | badgeProgressRatio, | 13 | badgeProgressRatio, |
| 20 | badgeRemaining, | 14 | badgeRemaining, |
| 21 | badgeThresholdLabel, | 15 | badgeThresholdLabel, |
| 16 | + badgeTier, | ||
| 17 | + type BadgeTier, | ||
| 22 | } from "@/lib/badges"; | 18 | } from "@/lib/badges"; |
| 23 | import { cn } from "@/lib/cn"; | 19 | import { cn } from "@/lib/cn"; |
| 24 | import { formatDate } from "@/lib/format"; | 20 | import { formatDate } from "@/lib/format"; |
| 25 | import { usePreferences, useT } from "@/stores/preferences-context"; | 21 | import { usePreferences, useT } from "@/stores/preferences-context"; |
| 26 | 22 | ||
| 27 | -function StatIcon(props: { stat: string; class?: string }) { | 23 | +const STAT_ICON: Record<string, PixelIconName> = { |
| 28 | - return ( | 24 | + homework_submitted: "notes", |
| 29 | - <Switch fallback={<IconSparkles class={props.class} />}> | 25 | + homework_on_time: "check-double", |
| 30 | - <Match when={props.stat === "homework_submitted"}> | 26 | + exam_sat: "pen-square", |
| 31 | - <IconHomework class={props.class} /> | 27 | + pomodoro_finished: "zap", |
| 32 | - </Match> | 28 | + pomodoro_focus_ms: "hourglass", |
| 33 | - <Match when={props.stat === "homework_on_time"}> | 29 | + marks_given: "pencil", |
| 34 | - <IconClipboardCheck class={props.class} /> | 30 | + lessons_held: "book-open", |
| 35 | - </Match> | 31 | + pool_approved: "checkbox-on", |
| 36 | - <Match when={props.stat === "exam_sat"}> | 32 | + pool_published: "message-text", |
| 37 | - <IconExam class={props.class} /> | 33 | + lessons_attended: "calendar-weeks", |
| 38 | - </Match> | 34 | + high_mark: "star", |
| 39 | - <Match when={props.stat.startsWith("pomodoro")}> | 35 | + study_streak: "fire", |
| 40 | - <IconClock class={props.class} /> | 36 | +}; |
| 41 | - </Match> | 37 | + |
| 42 | - </Switch> | 38 | +const TIER_MEDAL: Record<BadgeTier, string> = { |
| 43 | - ); | 39 | + bronze: "bg-amber-700/12 text-amber-700 ring-amber-700/25 dark:text-amber-500", |
| 44 | -} | 40 | + silver: "bg-slate-400/15 text-slate-500 ring-slate-400/35 dark:text-slate-300", |
| 41 | + gold: "bg-yellow-400/20 text-yellow-600 ring-yellow-500/40 dark:text-yellow-400", | ||
| 42 | +}; | ||
| 45 | 43 | ||
| 44 | +export const statIcon = (stat: string): PixelIconName => STAT_ICON[stat] ?? "sparkles"; | ||
| 45 | + | ||
| 46 | +/** | ||
| 47 | + * The profile's badge board: one card per counter, each a ladder of | ||
| 48 | + * bronze → silver → gold rungs. Unearned rungs stay visible and locked, so the | ||
| 49 | + * next goal is legible before it is reached; nothing here is scored beyond the | ||
| 50 | + * backend's own counters and thresholds. | ||
| 51 | + */ | ||
| 46 | export function BadgeGrid(props: { | 52 | export function BadgeGrid(props: { |
| 47 | - /** The whole catalogue, from limits.badges.catalog — unearned entries stay | 53 | + /** The whole catalogue, from limits.badges.catalog. */ |
| 48 | - * visible and locked, so the goal is legible before it is reached. */ | ||
| 49 | catalog: BadgeCatalogEntry[]; | 54 | catalog: BadgeCatalogEntry[]; |
| 50 | earned: EarnedBadge[]; | 55 | earned: EarnedBadge[]; |
| 51 | stats: ProfileStats; | 56 | stats: ProfileStats; |
| 57 | + /** Whose profile this is — their role's ladders lead the board. */ | ||
| 58 | + role?: Role; | ||
| 52 | }) { | 59 | }) { |
| 53 | const t = useT(); | 60 | const t = useT(); |
| 54 | const prefs = usePreferences(); | 61 | const prefs = usePreferences(); |
| 55 | 62 | ||
| 56 | - const earnedAt = createMemo(() => { | 63 | + const earnedAt = createMemo(() => new Map(props.earned.map((b) => [b.id, b.earned_at] as const))); |
| 57 | - const map = new Map<string, number>(); | 64 | + const earnedCount = createMemo(() => props.catalog.filter((entry) => earnedAt().has(entry.id)).length); |
| 58 | - for (const b of props.earned) map.set(b.id, b.earned_at); | 65 | + const current = (stat: string) => badgeProgress(stat, props.stats); |
| 59 | - return map; | 66 | + const [showAll, setShowAll] = createSignal(false); |
| 67 | + // Ladders with earned rungs first, then the ones already in progress, then | ||
| 68 | + // the counters the owner's role actually moves; the rest fold away. | ||
| 69 | + const ladders = createMemo(() => { | ||
| 70 | + const staff = props.role === "teacher" || props.role === "manager" || props.role === "admin"; | ||
| 71 | + const staffStats = new Set(["marks_given", "lessons_held", "pool_approved"]); | ||
| 72 | + const score = (ladder: { stat: string; entries: BadgeCatalogEntry[] }) => { | ||
| 73 | + const earned = ladder.entries.filter((entry) => earnedAt().has(entry.id)).length; | ||
| 74 | + const progress = (current(ladder.stat) ?? 0) > 0 ? 1 : 0; | ||
| 75 | + const relevant = props.role == null || staffStats.has(ladder.stat) === staff ? 1 : 0; | ||
| 76 | + return earned * 100 + progress * 10 + relevant; | ||
| 77 | + }; | ||
| 78 | + return badgeLadders(props.catalog) | ||
| 79 | + .map((ladder, index) => ({ ladder, index, score: score(ladder) })) | ||
| 80 | + .sort((a, b) => b.score - a.score || a.index - b.index) | ||
| 81 | + .map((item) => item.ladder); | ||
| 60 | }); | 82 | }); |
| 83 | + // Folded, the board shows exactly one grid row: 1 card on phones, 2 from | ||
| 84 | + // sm, 3 from xl — the extra preview cards hide below their breakpoint. | ||
| 85 | + const LADDER_PREVIEW = 3; | ||
| 86 | + const visibleLadders = () => (showAll() ? ladders() : ladders().slice(0, LADDER_PREVIEW)); | ||
| 87 | + const previewClass = (index: number) => | ||
| 88 | + showAll() ? "" : index === 1 ? "hidden sm:flex" : index === 2 ? "hidden xl:flex" : ""; | ||
| 61 | 89 | ||
| 62 | - // A badge the backend ships before this build has copy for it must still | 90 | + // A badge the backend ships before this build has copy for must still render. |
| 63 | - // render, so both lookups fall back rather than throwing. | ||
| 64 | const label = (id: string) => { | 91 | const label = (id: string) => { |
| 65 | const key = badgeNameKey(id); | 92 | const key = badgeNameKey(id); |
| 66 | return key ? t(key) : id; | 93 | return key ? t(key) : id; |
| @@ -70,151 +97,209 @@ export function BadgeGrid(props: { | |||
| 70 | return key ? t(key) : ""; | 97 | return key ? t(key) : ""; |
| 71 | }; | 98 | }; |
| 72 | 99 | ||
| 73 | - const earnedCount = createMemo( | 100 | + // The closest unearned rung across every tracked ladder. |
| 74 | - () => props.catalog.filter((entry) => earnedAt().has(entry.id)).length, | 101 | + const next = createMemo(() => { |
| 75 | - ); | 102 | + let best: { entry: BadgeCatalogEntry; ratio: number } | null = null; |
| 76 | - const overallRatio = () => | 103 | + for (const entry of props.catalog) { |
| 77 | - props.catalog.length === 0 ? 0 : earnedCount() / props.catalog.length; | 104 | + if (earnedAt().has(entry.id)) continue; |
| 105 | + const value = current(entry.stat); | ||
| 106 | + if (value === null) continue; | ||
| 107 | + const ratio = badgeProgressRatio(value, entry.threshold); | ||
| 108 | + if (!best || ratio > best.ratio) best = { entry, ratio }; | ||
| 109 | + } | ||
| 110 | + return best; | ||
| 111 | + }); | ||
| 112 | + | ||
| 113 | + const level = () => badgeLevel(earnedCount(), props.catalog.length); | ||
| 78 | 114 | ||
| 79 | return ( | 115 | return ( |
| 80 | - <Collapsible defaultOpen class="group/badges rounded-lg border bg-card shadow-xs"> | 116 | + <section class="data-shell space-y-4 p-4"> |
| 81 | - <Collapsible.Trigger class="flex w-full items-center gap-3 px-4 py-3 text-left outline-hidden transition-colors hover:bg-accent/40 focus-visible:ring-2 focus-visible:ring-ring ui-expanded:border-b ui-expanded:border-border"> | 117 | + <div class="flex flex-wrap items-start justify-between gap-3"> |
| 82 | - <span class="flex h-7 w-7 shrink-0 items-center justify-center rounded-md border bg-muted text-muted-foreground"> | 118 | + <div class="min-w-0"> |
| 83 | - <IconSparkles class="h-3.5 w-3.5" /> | 119 | + <h2 class="flex items-center gap-2 text-lg font-semibold tracking-tight text-foreground"> |
| 84 | - </span> | 120 | + <PixelIcon name="trophy" class="h-5 w-5 text-primary" /> |
| 85 | - <span class="min-w-0 flex-1"> | 121 | + {t("badges.title")} |
| 86 | - <span class="block text-sm font-semibold">{t("badges.title")}</span> | 122 | + </h2> |
| 87 | - <span class="block text-xs text-muted-foreground">{t("badges.subtitle")}</span> | 123 | + <p class="mt-1 text-sm text-muted-foreground">{t("badges.subtitle")}</p> |
| 88 | - </span> | 124 | + </div> |
| 89 | <Show when={props.catalog.length > 0}> | 125 | <Show when={props.catalog.length > 0}> |
| 90 | - <span class="hidden items-center gap-2 sm:flex"> | 126 | + <div class="flex items-center gap-3 rounded-lg border border-border/70 bg-muted/40 px-3 py-2"> |
| 91 | - <span class="h-1.5 w-24 overflow-hidden rounded-full bg-muted"> | 127 | + <PixelIcon name="crown" class="h-5 w-5 text-yellow-500" /> |
| 92 | - <span | 128 | + <div class="min-w-0"> |
| 93 | - class="block h-full rounded-full bg-primary transition-[width] duration-500" | 129 | + <p class="text-[11px] font-medium uppercase tracking-wide text-muted-foreground">{t("badges.levelLabel")}</p> |
| 94 | - style={{ width: `${overallRatio() * 100}%` }} | 130 | + <p class="text-sm font-semibold">{t(`badges.level.${level()}`)}</p> |
| 95 | - /> | 131 | + </div> |
| 96 | - </span> | 132 | + <div class="w-28"> |
| 97 | - <span class="text-xs tabular-nums text-muted-foreground"> | 133 | + <span class="block h-1.5 overflow-hidden rounded-full bg-muted"> |
| 98 | - {t("badges.earnedCount", { earned: earnedCount(), total: props.catalog.length })} | 134 | + <span |
| 99 | - </span> | 135 | + class="block h-full rounded-full bg-primary transition-[width] duration-700" |
| 100 | - </span> | 136 | + style={{ width: `${(earnedCount() / props.catalog.length) * 100}%` }} |
| 137 | + /> | ||
| 138 | + </span> | ||
| 139 | + <p class="mt-1 text-right text-[11px] tabular-nums text-muted-foreground"> | ||
| 140 | + {t("badges.earnedCount", { earned: earnedCount(), total: props.catalog.length })} | ||
| 141 | + </p> | ||
| 142 | + </div> | ||
| 143 | + </div> | ||
| 101 | </Show> | 144 | </Show> |
| 102 | - <IconChevronDown class="h-4 w-4 shrink-0 text-muted-foreground transition-transform duration-200 group-data-expanded/badges:rotate-180" /> | 145 | + </div> |
| 103 | - </Collapsible.Trigger> | ||
| 104 | - | ||
| 105 | - <Collapsible.Content> | ||
| 106 | - <div class="p-4"> | ||
| 107 | - <Show | ||
| 108 | - when={props.catalog.length > 0} | ||
| 109 | - fallback={<p class="text-sm text-muted-foreground">{t("badges.none")}</p>} | ||
| 110 | - > | ||
| 111 | - {/* A horizontal rail rather than a grid: thirteen tiles would otherwise | ||
| 112 | - push the rest of the profile off the first screen. Snap points keep | ||
| 113 | - a card from being cut in half mid-scroll, and the edge fade says | ||
| 114 | - there is more to the right without spending a control on it. */} | ||
| 115 | - <div class="relative"> | ||
| 116 | - <div | ||
| 117 | - role="list" | ||
| 118 | - class="-mx-1 flex snap-x snap-mandatory gap-3 overflow-x-auto px-1 pb-2 [scrollbar-width:thin]" | ||
| 119 | - > | ||
| 120 | - <For each={props.catalog}> | ||
| 121 | - {(entry) => { | ||
| 122 | - const at = () => earnedAt().get(entry.id); | ||
| 123 | - const current = () => badgeProgress(entry.stat, props.stats) ?? 0; | ||
| 124 | - const tracked = () => badgeProgress(entry.stat, props.stats) !== null; | ||
| 125 | - const ratio = () => badgeProgressRatio(current(), entry.threshold); | ||
| 126 | - const left = () => badgeRemaining(entry.stat, current(), entry.threshold); | ||
| 127 | - const isHours = entry.stat === "pomodoro_focus_ms"; | ||
| 128 | 146 | ||
| 129 | - // The tooltip enriches; it never carries the only copy of | 147 | + <Show when={props.catalog.length > 0} fallback={<p class="text-sm text-muted-foreground">{t("badges.none")}</p>}> |
| 130 | - // anything, since a touch device can never open one. | 148 | + <Show |
| 131 | - const hint = () => | 149 | + when={next()} |
| 132 | - at() | 150 | + fallback={ |
| 133 | - ? t("badges.earnedOn", { date: formatDate(at()!, prefs.locale()) }) | 151 | + <div class="flex items-center gap-3 rounded-lg border border-yellow-500/30 bg-yellow-400/10 px-4 py-3 text-sm font-medium"> |
| 134 | - : tracked() | 152 | + <PixelIcon name="trophy" class="h-5 w-5 text-yellow-600" /> |
| 135 | - ? t(isHours ? "badges.remainingHours" : "badges.remaining", { count: left() }) | 153 | + {t("badges.allEarned")} |
| 136 | - : t("badges.locked"); | 154 | + </div> |
| 155 | + } | ||
| 156 | + > | ||
| 157 | + {(n) => ( | ||
| 158 | + <div class="flex flex-wrap items-center gap-3 rounded-lg border border-primary/25 bg-primary/5 px-4 py-3"> | ||
| 159 | + <span class="flex h-9 w-9 items-center justify-center rounded-md bg-primary/15 text-primary"> | ||
| 160 | + <PixelIcon name={statIcon(n().entry.stat)} class="h-5 w-5" /> | ||
| 161 | + </span> | ||
| 162 | + <div class="min-w-0 flex-1"> | ||
| 163 | + <p class="text-[11px] font-medium uppercase tracking-wide text-primary">{t("badges.next")}</p> | ||
| 164 | + <p class="truncate text-sm text-muted-foreground">{description(n().entry.id) || label(n().entry.id)}</p> | ||
| 165 | + </div> | ||
| 166 | + <div class="w-40"> | ||
| 167 | + <span class="block h-2 overflow-hidden rounded-full bg-primary/10"> | ||
| 168 | + <span class="block h-full rounded-full bg-primary transition-[width] duration-700" style={{ width: `${n().ratio * 100}%` }} /> | ||
| 169 | + </span> | ||
| 170 | + <p class="mt-1 text-right text-[11px] tabular-nums text-muted-foreground"> | ||
| 171 | + {t(n().entry.stat === "pomodoro_focus_ms" ? "badges.remainingHours" : "badges.remaining", { | ||
| 172 | + count: badgeRemaining(n().entry.stat, current(n().entry.stat) ?? 0, n().entry.threshold), | ||
| 173 | + })} | ||
| 174 | + </p> | ||
| 175 | + </div> | ||
| 176 | + </div> | ||
| 177 | + )} | ||
| 178 | + </Show> | ||
| 137 | 179 | ||
| 180 | + <div class="grid gap-3 sm:grid-cols-2 xl:grid-cols-3"> | ||
| 181 | + <For each={visibleLadders()}> | ||
| 182 | + {(ladder, ladderIndex) => { | ||
| 183 | + const groupKey = badgeGroupKey(ladder.stat); | ||
| 184 | + const earnedInLadder = () => ladder.entries.filter((entry) => earnedAt().has(entry.id)).length; | ||
| 138 | return ( | 185 | return ( |
| 139 | - <Tooltip openDelay={200} closeDelay={80}> | 186 | + <article class={cn("flex flex-col gap-3 rounded-xl border border-border/70 bg-card p-3", previewClass(ladderIndex()))}> |
| 140 | - <TooltipTrigger | 187 | + <header class="flex items-center gap-2.5"> |
| 141 | - as="div" | ||
| 142 | - role="listitem" | ||
| 143 | - // Focusable so the tooltip is reachable without a pointer; | ||
| 144 | - // the label repeats what the tooltip would say, since a | ||
| 145 | - // tooltip can never be opened by touch. | ||
| 146 | - tabindex="0" | ||
| 147 | - aria-label={`${label(entry.id)} — ${hint()}`} | ||
| 148 | - class={cn( | ||
| 149 | - "flex w-60 shrink-0 snap-start gap-3 rounded-lg border bg-card p-3 text-left shadow-xs outline-hidden transition-colors", | ||
| 150 | - "focus-visible:ring-2 focus-visible:ring-ring", | ||
| 151 | - at() ? "border-primary/40" : "border-border/70", | ||
| 152 | - )} | ||
| 153 | - > | ||
| 154 | <span | 188 | <span |
| 155 | class={cn( | 189 | class={cn( |
| 156 | - "relative flex h-10 w-10 shrink-0 items-center justify-center rounded-full", | 190 | + "flex h-8 w-8 items-center justify-center rounded-md", |
| 157 | - at() ? "bg-primary/15 text-primary" : "bg-muted text-muted-foreground grayscale", | 191 | + earnedInLadder() > 0 ? "bg-primary/12 text-primary" : "bg-muted text-muted-foreground", |
| 158 | )} | 192 | )} |
| 159 | > | 193 | > |
| 160 | - <StatIcon stat={entry.stat} class="h-5 w-5" /> | 194 | + <PixelIcon name={statIcon(ladder.stat)} class="h-[18px] w-[18px]" /> |
| 161 | - {/* A locked badge reads as locked, not as disabled: the | ||
| 162 | - padlock says "not yet", dimming alone says "off". */} | ||
| 163 | - <Show when={!at()}> | ||
| 164 | - <span class="absolute -bottom-0.5 -right-0.5 flex h-4 w-4 items-center justify-center rounded-full border border-card bg-muted-foreground/80 text-card"> | ||
| 165 | - <IconLock class="h-2.5 w-2.5" /> | ||
| 166 | - </span> | ||
| 167 | - </Show> | ||
| 168 | </span> | 195 | </span> |
| 196 | + <p class="min-w-0 flex-1 truncate text-sm font-semibold">{groupKey ? t(groupKey) : ladder.stat}</p> | ||
| 197 | + <span class="flex gap-0.5" aria-hidden="true"> | ||
| 198 | + <For each={ladder.entries}> | ||
| 199 | + {(entry, index) => ( | ||
| 200 | + <span | ||
| 201 | + class={cn( | ||
| 202 | + "h-2 w-2 rounded-[1px]", | ||
| 203 | + earnedAt().has(entry.id) | ||
| 204 | + ? { bronze: "bg-amber-700", silver: "bg-slate-400", gold: "bg-yellow-500" }[badgeTier(index(), ladder.entries.length)] | ||
| 205 | + : "bg-muted-foreground/20", | ||
| 206 | + )} | ||
| 207 | + /> | ||
| 208 | + )} | ||
| 209 | + </For> | ||
| 210 | + </span> | ||
| 211 | + </header> | ||
| 169 | 212 | ||
| 170 | - <div class="min-w-0 flex-1 space-y-1"> | 213 | + <div class="grid gap-1.5" role="list"> |
| 171 | - <p class={cn("truncate text-sm font-semibold", !at() && "text-muted-foreground")}> | 214 | + <For each={ladder.entries}> |
| 172 | - {label(entry.id)} | 215 | + {(entry, index) => { |
| 173 | - </p> | 216 | + const at = () => earnedAt().get(entry.id); |
| 174 | - <p class="line-clamp-2 text-xs text-muted-foreground">{description(entry.id)}</p> | 217 | + const value = () => current(entry.stat) ?? 0; |
| 175 | - | 218 | + const tracked = () => current(entry.stat) !== null; |
| 176 | - <Show | 219 | + const tier = () => badgeTier(index(), ladder.entries.length); |
| 177 | - when={!at() && tracked()} | 220 | + const isHours = entry.stat === "pomodoro_focus_ms"; |
| 178 | - fallback={ | 221 | + // The tooltip enriches; the row itself carries every |
| 179 | - <p class="text-[11px] tabular-nums text-muted-foreground">{hint()}</p> | 222 | + // number, since a touch device can never open one. |
| 180 | - } | 223 | + const hint = () => |
| 181 | - > | 224 | + at() |
| 182 | - <div class="space-y-1"> | 225 | + ? t("badges.earnedOn", { date: formatDate(at()!, prefs.locale()) }) |
| 183 | - <span class="block h-1 overflow-hidden rounded-full bg-muted"> | 226 | + : tracked() |
| 184 | - <span | 227 | + ? t(isHours ? "badges.remainingHours" : "badges.remaining", { |
| 185 | - class="block h-full rounded-full bg-muted-foreground/60 transition-[width] duration-500" | 228 | + count: badgeRemaining(entry.stat, value(), entry.threshold), |
| 186 | - style={{ width: `${ratio() * 100}%` }} | 229 | + }) |
| 187 | - /> | 230 | + : t("badges.locked"); |
| 188 | - </span> | ||
| 189 | - <p class="text-[11px] tabular-nums text-muted-foreground"> | ||
| 190 | - {badgeProgressLabel(entry.stat, current())} /{" "} | ||
| 191 | - {badgeThresholdLabel(entry.stat, entry.threshold)} | ||
| 192 | - </p> | ||
| 193 | - </div> | ||
| 194 | - </Show> | ||
| 195 | - </div> | ||
| 196 | - </TooltipTrigger> | ||
| 197 | 231 | ||
| 198 | - <TooltipContent> | 232 | + return ( |
| 199 | - <p class="font-semibold">{label(entry.id)}</p> | 233 | + <Tooltip openDelay={200} closeDelay={80}> |
| 200 | - <Show when={description(entry.id)}> | 234 | + <TooltipTrigger |
| 201 | - <p class="mt-0.5 text-muted-foreground">{description(entry.id)}</p> | 235 | + as="div" |
| 202 | - </Show> | 236 | + role="listitem" |
| 203 | - <p class="mt-1 tabular-nums">{hint()}</p> | 237 | + tabindex="0" |
| 204 | - </TooltipContent> | 238 | + aria-label={`${label(entry.id)} — ${hint()}`} |
| 205 | - </Tooltip> | 239 | + class={cn( |
| 240 | + "group/rung flex items-center gap-2.5 rounded-lg border p-2 outline-hidden transition-[transform,border-color,background-color] duration-200 hover:-translate-y-px focus-visible:ring-2 focus-visible:ring-ring", | ||
| 241 | + at() ? "border-transparent bg-muted/40" : "border-dashed border-border/70", | ||
| 242 | + )} | ||
| 243 | + > | ||
| 244 | + <span | ||
| 245 | + class={cn( | ||
| 246 | + "relative flex h-9 w-9 shrink-0 items-center justify-center rounded-md ring-1", | ||
| 247 | + at() ? TIER_MEDAL[tier()] : "bg-muted text-muted-foreground/50 ring-transparent", | ||
| 248 | + )} | ||
| 249 | + > | ||
| 250 | + <PixelIcon name={at() ? "trophy" : "lock"} class="h-5 w-5 transition-transform duration-200 group-hover/rung:scale-110" /> | ||
| 251 | + </span> | ||
| 252 | + <div class="min-w-0 flex-1"> | ||
| 253 | + <p class={cn("truncate text-[13px] font-semibold", !at() && "text-muted-foreground")}>{label(entry.id)}</p> | ||
| 254 | + <Show | ||
| 255 | + when={!at() && tracked()} | ||
| 256 | + fallback={<p class="truncate text-[11px] tabular-nums text-muted-foreground">{hint()}</p>} | ||
| 257 | + > | ||
| 258 | + <div class="flex items-center gap-2"> | ||
| 259 | + <span class="block h-1 flex-1 overflow-hidden rounded-full bg-muted"> | ||
| 260 | + <span | ||
| 261 | + class="block h-full rounded-full bg-primary/70 transition-[width] duration-500" | ||
| 262 | + style={{ width: `${badgeProgressRatio(value(), entry.threshold) * 100}%` }} | ||
| 263 | + /> | ||
| 264 | + </span> | ||
| 265 | + <span class="shrink-0 text-[11px] tabular-nums text-muted-foreground"> | ||
| 266 | + {badgeProgressLabel(entry.stat, value())} / {badgeThresholdLabel(entry.stat, entry.threshold)} | ||
| 267 | + </span> | ||
| 268 | + </div> | ||
| 269 | + </Show> | ||
| 270 | + </div> | ||
| 271 | + </TooltipTrigger> | ||
| 272 | + <TooltipContent> | ||
| 273 | + <p class="font-semibold">{label(entry.id)}</p> | ||
| 274 | + <Show when={description(entry.id)}> | ||
| 275 | + <p class="mt-0.5 text-muted-foreground">{description(entry.id)}</p> | ||
| 276 | + </Show> | ||
| 277 | + <p class="mt-1 tabular-nums">{hint()}</p> | ||
| 278 | + </TooltipContent> | ||
| 279 | + </Tooltip> | ||
| 280 | + ); | ||
| 281 | + }} | ||
| 282 | + </For> | ||
| 283 | + </div> | ||
| 284 | + </article> | ||
| 206 | ); | 285 | ); |
| 207 | }} | 286 | }} |
| 208 | - </For> | 287 | + </For> |
| 209 | - </div> | ||
| 210 | - <span | ||
| 211 | - aria-hidden="true" | ||
| 212 | - class="pointer-events-none absolute inset-y-0 right-0 w-10 bg-gradient-to-l from-card to-transparent" | ||
| 213 | - /> | ||
| 214 | </div> | 288 | </div> |
| 289 | + <Show when={ladders().length > 1}> | ||
| 290 | + <div class="flex justify-center"> | ||
| 291 | + <button | ||
| 292 | + type="button" | ||
| 293 | + class="inline-flex h-8 items-center gap-2 rounded-lg border border-border/70 bg-muted/40 px-3 text-[13px] font-medium text-foreground transition-colors hover:bg-muted focus-visible:outline-hidden focus-visible:ring-2 focus-visible:ring-ring" | ||
| 294 | + aria-expanded={showAll()} | ||
| 295 | + onClick={() => setShowAll(!showAll())} | ||
| 296 | + > | ||
| 297 | + <PixelIcon name={showAll() ? "chevron-up" : "chevron-down"} class="h-4 w-4" /> | ||
| 298 | + {showAll() ? t("badges.showLess") : t("badges.showAll", { count: ladders().length })} | ||
| 299 | + </button> | ||
| 300 | + </div> | ||
| 301 | + </Show> | ||
| 215 | </Show> | 302 | </Show> |
| 216 | - </div> | 303 | + </section> |
| 217 | - </Collapsible.Content> | ||
| 218 | - </Collapsible> | ||
| 219 | ); | 304 | ); |
| 220 | } | 305 | } |
src/i18n/messages.tsmodified+81 -0
| @@ -175,6 +175,33 @@ export type MessageKey = | |||
| 175 | | "avatar.typeInvalid" | 175 | | "avatar.typeInvalid" |
| 176 | | "avatar.tooLarge" | 176 | | "avatar.tooLarge" |
| 177 | | "badges.title" | 177 | | "badges.title" |
| 178 | + | "badges.group.homework_submitted" | ||
| 179 | + | "badges.group.homework_on_time" | ||
| 180 | + | "badges.group.exam_sat" | ||
| 181 | + | "badges.group.pomodoro_finished" | ||
| 182 | + | "badges.group.pomodoro_focus_ms" | ||
| 183 | + | "badges.group.marks_given" | ||
| 184 | + | "badges.group.lessons_held" | ||
| 185 | + | "badges.group.pool_approved" | ||
| 186 | + | "badges.group.pool_published" | ||
| 187 | + | "badges.group.lessons_attended" | ||
| 188 | + | "badges.group.high_mark" | ||
| 189 | + | "badges.group.study_streak" | ||
| 190 | + | "badges.level.rookie" | ||
| 191 | + | "badges.level.explorer" | ||
| 192 | + | "badges.level.master" | ||
| 193 | + | "badges.level.legend" | ||
| 194 | + | "badges.levelLabel" | ||
| 195 | + | "badges.next" | ||
| 196 | + | "badges.showAll" | ||
| 197 | + | "badges.showLess" | ||
| 198 | + | "badges.allEarned" | ||
| 199 | + | "badges.nextOf" | ||
| 200 | + | "profile.statLessonsHeld" | ||
| 201 | + | "profile.statMarksGiven" | ||
| 202 | + | "profile.statPoolApproved" | ||
| 203 | + | "profile.statLessonsAttended" | ||
| 204 | + | "profile.statStreak" | ||
| 178 | | "badges.subtitle" | 205 | | "badges.subtitle" |
| 179 | | "badges.earnedOn" | 206 | | "badges.earnedOn" |
| 180 | | "badges.locked" | 207 | | "badges.locked" |
| @@ -2034,6 +2061,33 @@ const en: Dict = { | |||
| 2034 | "avatar.typeInvalid": "Use a PNG, JPEG, WebP or GIF image.", | 2061 | "avatar.typeInvalid": "Use a PNG, JPEG, WebP or GIF image.", |
| 2035 | "avatar.tooLarge": "This image is larger than {size}.", | 2062 | "avatar.tooLarge": "This image is larger than {size}.", |
| 2036 | "badges.title": "Badges", | 2063 | "badges.title": "Badges", |
| 2064 | + "badges.group.homework_submitted": "Homework", | ||
| 2065 | + "badges.group.homework_on_time": "On time", | ||
| 2066 | + "badges.group.exam_sat": "Exams", | ||
| 2067 | + "badges.group.pomodoro_finished": "Focus sessions", | ||
| 2068 | + "badges.group.pomodoro_focus_ms": "Focus time", | ||
| 2069 | + "badges.group.marks_given": "Grading", | ||
| 2070 | + "badges.group.lessons_held": "Lessons taught", | ||
| 2071 | + "badges.group.pool_approved": "Answers approved", | ||
| 2072 | + "badges.group.pool_published": "Questions shared", | ||
| 2073 | + "badges.group.lessons_attended": "Lessons attended", | ||
| 2074 | + "badges.group.high_mark": "High marks", | ||
| 2075 | + "badges.group.study_streak": "Study streak", | ||
| 2076 | + "badges.level.rookie": "Rookie", | ||
| 2077 | + "badges.level.explorer": "Explorer", | ||
| 2078 | + "badges.level.master": "Master", | ||
| 2079 | + "badges.level.legend": "Legend", | ||
| 2080 | + "badges.levelLabel": "Badge level", | ||
| 2081 | + "badges.next": "Next badge", | ||
| 2082 | + "badges.showAll": "Show all badge groups ({count})", | ||
| 2083 | + "badges.showLess": "Show less", | ||
| 2084 | + "badges.allEarned": "Every badge earned", | ||
| 2085 | + "badges.nextOf": "{current} / {threshold}", | ||
| 2086 | + "profile.statLessonsHeld": "Lessons taught", | ||
| 2087 | + "profile.statMarksGiven": "Marks given", | ||
| 2088 | + "profile.statPoolApproved": "Answers approved", | ||
| 2089 | + "profile.statLessonsAttended": "Lessons attended", | ||
| 2090 | + "profile.statStreak": "Study streak", | ||
| 2037 | "badges.subtitle": "Earned automatically as the work adds up.", | 2091 | "badges.subtitle": "Earned automatically as the work adds up.", |
| 2038 | "badges.earnedOn": "Earned {date}", | 2092 | "badges.earnedOn": "Earned {date}", |
| 2039 | "badges.locked": "Not earned yet", | 2093 | "badges.locked": "Not earned yet", |
| @@ -3901,6 +3955,33 @@ const tr: Dict = { | |||
| 3901 | "avatar.typeInvalid": "PNG, JPEG, WebP veya GIF bir görsel kullan.", | 3955 | "avatar.typeInvalid": "PNG, JPEG, WebP veya GIF bir görsel kullan.", |
| 3902 | "avatar.tooLarge": "Bu görsel {size} sınırından büyük.", | 3956 | "avatar.tooLarge": "Bu görsel {size} sınırından büyük.", |
| 3903 | "badges.title": "Rozetler", | 3957 | "badges.title": "Rozetler", |
| 3958 | + "badges.group.homework_submitted": "Ödev teslimi", | ||
| 3959 | + "badges.group.homework_on_time": "Zamanında teslim", | ||
| 3960 | + "badges.group.exam_sat": "Sınavlar", | ||
| 3961 | + "badges.group.pomodoro_finished": "Odak oturumları", | ||
| 3962 | + "badges.group.pomodoro_focus_ms": "Odak süresi", | ||
| 3963 | + "badges.group.marks_given": "Not verme", | ||
| 3964 | + "badges.group.lessons_held": "Verilen dersler", | ||
| 3965 | + "badges.group.pool_approved": "Onaylanan cevaplar", | ||
| 3966 | + "badges.group.pool_published": "Paylaşılan sorular", | ||
| 3967 | + "badges.group.lessons_attended": "Katıldığı dersler", | ||
| 3968 | + "badges.group.high_mark": "Yüksek notlar", | ||
| 3969 | + "badges.group.study_streak": "Çalışma serisi", | ||
| 3970 | + "badges.level.rookie": "Çaylak", | ||
| 3971 | + "badges.level.explorer": "Kaşif", | ||
| 3972 | + "badges.level.master": "Usta", | ||
| 3973 | + "badges.level.legend": "Efsane", | ||
| 3974 | + "badges.levelLabel": "Rozet seviyesi", | ||
| 3975 | + "badges.next": "Sıradaki rozet", | ||
| 3976 | + "badges.showAll": "Tüm rozet gruplarını göster ({count})", | ||
| 3977 | + "badges.showLess": "Daha az göster", | ||
| 3978 | + "badges.allEarned": "Tüm rozetler kazanıldı", | ||
| 3979 | + "badges.nextOf": "{current} / {threshold}", | ||
| 3980 | + "profile.statLessonsHeld": "Verilen ders", | ||
| 3981 | + "profile.statMarksGiven": "Verilen not", | ||
| 3982 | + "profile.statPoolApproved": "Onaylanan cevap", | ||
| 3983 | + "profile.statLessonsAttended": "Katıldığı ders", | ||
| 3984 | + "profile.statStreak": "Çalışma serisi", | ||
| 3904 | "badges.subtitle": "Çalışma biriktikçe otomatik kazanılır.", | 3985 | "badges.subtitle": "Çalışma biriktikçe otomatik kazanılır.", |
| 3905 | "badges.earnedOn": "{date} tarihinde kazanıldı", | 3986 | "badges.earnedOn": "{date} tarihinde kazanıldı", |
| 3906 | "badges.locked": "Henüz kazanılmadı", | 3987 | "badges.locked": "Henüz kazanılmadı", |
src/index.cssmodified+10 -0
| @@ -545,3 +545,13 @@ | |||
| 545 | 50% { opacity: 1; transform: scale(1.02); filter: drop-shadow(0 0 20px hsl(var(--primary) / 0.45)); } | 545 | 50% { opacity: 1; transform: scale(1.02); filter: drop-shadow(0 0 20px hsl(var(--primary) / 0.45)); } |
| 546 | } | 546 | } |
| 547 | } | 547 | } |
| 548 | + | ||
| 549 | +/* Profile cover: brand tint under an 8px pixel grid. */ | ||
| 550 | +.profile-cover { | ||
| 551 | + background-color: hsl(var(--primary) / 0.12); | ||
| 552 | + background-image: | ||
| 553 | + linear-gradient(hsl(var(--primary) / 0.1) 1px, transparent 1px), | ||
| 554 | + linear-gradient(90deg, hsl(var(--primary) / 0.1) 1px, transparent 1px), | ||
| 555 | + linear-gradient(120deg, hsl(var(--primary) / 0.28), transparent 65%); | ||
| 556 | + background-size: 8px 8px, 8px 8px, 100% 100%; | ||
| 557 | +} | ||
src/lib/badges.tsmodified+42 -0
| @@ -102,3 +102,45 @@ export function badgeRemaining(stat: string, current: number, threshold: number) | |||
| 102 | } | 102 | } |
| 103 | return Math.max(0, threshold - current); | 103 | return Math.max(0, threshold - current); |
| 104 | } | 104 | } |
| 105 | + | ||
| 106 | +// ---- Grouping for the profile's badge board ---------------------------------- | ||
| 107 | + | ||
| 108 | +const KNOWN_STATS = new Set<string>(Object.keys(STAT_TOTAL_FIELD)); | ||
| 109 | + | ||
| 110 | +/** Section title for one counter's badge ladder, or null for a stat this build has no copy for. */ | ||
| 111 | +export function badgeGroupKey(stat: string): MessageKey | null { | ||
| 112 | + return KNOWN_STATS.has(stat) ? (`badges.group.${stat}` as MessageKey) : null; | ||
| 113 | +} | ||
| 114 | + | ||
| 115 | +export type BadgeLadder<T extends { stat: string; threshold: number }> = { stat: string; entries: T[] }; | ||
| 116 | + | ||
| 117 | +/** The catalogue split into one ladder per counter, each ladder in threshold order. */ | ||
| 118 | +export function badgeLadders<T extends { stat: string; threshold: number }>(catalog: T[]): BadgeLadder<T>[] { | ||
| 119 | + const byStat = new Map<string, T[]>(); | ||
| 120 | + for (const entry of catalog) byStat.set(entry.stat, [...(byStat.get(entry.stat) ?? []), entry]); | ||
| 121 | + return [...byStat].map(([stat, entries]) => ({ | ||
| 122 | + stat, | ||
| 123 | + entries: [...entries].sort((a, b) => a.threshold - b.threshold), | ||
| 124 | + })); | ||
| 125 | +} | ||
| 126 | + | ||
| 127 | +export type BadgeTier = "bronze" | "silver" | "gold"; | ||
| 128 | + | ||
| 129 | +/** Medal colour for a rung: the last rung of a ladder is gold, the one before silver. */ | ||
| 130 | +export function badgeTier(index: number, count: number): BadgeTier { | ||
| 131 | + const fromTop = count - 1 - index; | ||
| 132 | + if (fromTop === 0 && count > 1) return "gold"; | ||
| 133 | + if (fromTop === 1) return "silver"; | ||
| 134 | + return "bronze"; | ||
| 135 | +} | ||
| 136 | + | ||
| 137 | +export type BadgeLevel = "rookie" | "explorer" | "master" | "legend"; | ||
| 138 | + | ||
| 139 | +/** A title that follows the share of the catalogue already earned — no score of its own. */ | ||
| 140 | +export function badgeLevel(earned: number, total: number): BadgeLevel { | ||
| 141 | + const share = total === 0 ? 0 : earned / total; | ||
| 142 | + if (share >= 0.75) return "legend"; | ||
| 143 | + if (share >= 0.4) return "master"; | ||
| 144 | + if (earned > 0) return "explorer"; | ||
| 145 | + return "rookie"; | ||
| 146 | +} | ||
src/pages/profile-page.tsxmodified+54 -20
| @@ -1,4 +1,4 @@ | |||
| 1 | -import { Show, Suspense, createMemo, createResource, createSignal } from "solid-js"; | 1 | +import { For, Show, Suspense, createMemo, createResource, createSignal } from "solid-js"; |
| 2 | import { useLocation, useParams } from "@tanstack/solid-router"; | 2 | import { useLocation, useParams } from "@tanstack/solid-router"; |
| 3 | import { getClassesByUserId, getMyClasses } from "@/api/classes"; | 3 | import { getClassesByUserId, getMyClasses } from "@/api/classes"; |
| 4 | import { getLimits } from "@/api/limits"; | 4 | import { getLimits } from "@/api/limits"; |
| @@ -11,6 +11,7 @@ import { Button } from "@/components/ui/button"; | |||
| 11 | import { ErrorAlert } from "@/components/ui/error-alert"; | 11 | import { ErrorAlert } from "@/components/ui/error-alert"; |
| 12 | import { IconEdit, IconSchool } from "@/components/ui/icons"; | 12 | import { IconEdit, IconSchool } from "@/components/ui/icons"; |
| 13 | import { PageSpinner } from "@/components/ui/page-spinner"; | 13 | import { PageSpinner } from "@/components/ui/page-spinner"; |
| 14 | +import { PixelIcon, type PixelIconName } from "@/components/ui/pixel-icon"; | ||
| 14 | import { SidePanel } from "@/components/ui/side-panel"; | 15 | import { SidePanel } from "@/components/ui/side-panel"; |
| 15 | import { AvatarUpload } from "@/components/users/avatar-upload"; | 16 | import { AvatarUpload } from "@/components/users/avatar-upload"; |
| 16 | import { BadgeGrid } from "@/components/users/badge-grid"; | 17 | import { BadgeGrid } from "@/components/users/badge-grid"; |
| @@ -50,6 +51,25 @@ function ProfileContent() { | |||
| 50 | const [limits] = createResource(() => getLimits()); | 51 | const [limits] = createResource(() => getLimits()); |
| 51 | const [editing, setEditing] = createSignal(false); | 52 | const [editing, setEditing] = createSignal(false); |
| 52 | 53 | ||
| 54 | + // The five counters that fit the profile owner's role: a student's own | ||
| 55 | + // work, or a teacher's / manager's teaching work. | ||
| 56 | + const profileStats = (p: Profile): { icon: PixelIconName; label: string; value: number }[] => | ||
| 57 | + p.role === "student" || p.role === "parent" | ||
| 58 | + ? [ | ||
| 59 | + { icon: "hourglass", label: t("profile.statFocusHours"), value: Math.floor(p.stats.pomodoro_focus_ms_total / 3_600_000) }, | ||
| 60 | + { icon: "zap", label: t("profile.statSessions"), value: p.stats.pomodoro_finished_total }, | ||
| 61 | + { icon: "notes", label: t("profile.statHomework"), value: p.stats.homework_submitted_total }, | ||
| 62 | + { icon: "check-double", label: t("profile.statOnTime"), value: p.stats.homework_on_time_total }, | ||
| 63 | + { icon: "pen-square", label: t("profile.statExams"), value: p.stats.exam_sat_total }, | ||
| 64 | + ] | ||
| 65 | + : [ | ||
| 66 | + { icon: "book-open", label: t("profile.statLessonsHeld"), value: p.stats.lessons_held_total }, | ||
| 67 | + { icon: "pencil", label: t("profile.statMarksGiven"), value: p.stats.marks_given_total }, | ||
| 68 | + { icon: "checkbox-on", label: t("profile.statPoolApproved"), value: p.stats.pool_approved_total }, | ||
| 69 | + { icon: "users", label: t("profile.statClasses"), value: p.stats.classes }, | ||
| 70 | + { icon: "calendar-weeks", label: t("profile.statCourses"), value: p.stats.courses }, | ||
| 71 | + ]; | ||
| 72 | + | ||
| 53 | const isSelf = (p: Profile) => target() === "me" || p.id === auth.user()?.id; | 73 | const isSelf = (p: Profile) => target() === "me" || p.id === auth.user()?.id; |
| 54 | const name = (p: Profile) => p.display_name || p.username; | 74 | const name = (p: Profile) => p.display_name || p.username; |
| 55 | 75 | ||
| @@ -105,8 +125,16 @@ function ProfileContent() { | |||
| 105 | <Show when={!profile.error && profile()}> | 125 | <Show when={!profile.error && profile()}> |
| 106 | {(p) => ( | 126 | {(p) => ( |
| 107 | <> | 127 | <> |
| 108 | - <section class="flex flex-wrap items-start justify-between gap-4 rounded-xl border bg-card p-4 shadow-xs"> | 128 | + <section class="overflow-hidden rounded-xl border bg-card shadow-xs"> |
| 109 | - <div class="flex min-w-0 flex-wrap items-center gap-4"> | 129 | + {/* Cover: brand tint under a pixel grid, purely decorative. */} |
| 130 | + <div class="profile-cover relative h-24 sm:h-28" aria-hidden="true"> | ||
| 131 | + <PixelIcon name="sparkles" class="absolute right-6 top-5 h-6 w-6 text-primary/50" /> | ||
| 132 | + <PixelIcon name="star" class="absolute right-20 top-12 h-4 w-4 text-primary/35" /> | ||
| 133 | + <PixelIcon name="trophy" class="absolute right-36 top-6 h-5 w-5 text-primary/30" /> | ||
| 134 | + </div> | ||
| 135 | + <div class="flex flex-wrap items-start justify-between gap-4 px-4 pb-4"> | ||
| 136 | + <div class="flex min-w-0 flex-wrap items-start gap-4"> | ||
| 137 | + <div class="-mt-12 shrink-0 rounded-full bg-card p-1"> | ||
| 110 | <Show | 138 | <Show |
| 111 | when={isSelf(p())} | 139 | when={isSelf(p())} |
| 112 | fallback={ | 140 | fallback={ |
| @@ -125,8 +153,9 @@ function ProfileContent() { | |||
| 125 | onChanged={() => void refetch()} | 153 | onChanged={() => void refetch()} |
| 126 | /> | 154 | /> |
| 127 | </Show> | 155 | </Show> |
| 128 | - <div class="min-w-0 space-y-1"> | 156 | + </div> |
| 129 | - <h1 class="truncate text-xl font-semibold">{name(p())}</h1> | 157 | + <div class="min-w-0 space-y-1 pt-3"> |
| 158 | + <h1 class="truncate text-2xl font-semibold tracking-tight">{name(p())}</h1> | ||
| 130 | <div class="flex flex-wrap items-center gap-2"> | 159 | <div class="flex flex-wrap items-center gap-2"> |
| 131 | <span class="text-sm text-muted-foreground">@{p().username}</span> | 160 | <span class="text-sm text-muted-foreground">@{p().username}</span> |
| 132 | <RoleBadge role={p().role} /> | 161 | <RoleBadge role={p().role} /> |
| @@ -154,27 +183,27 @@ function ProfileContent() { | |||
| 154 | )} | 183 | )} |
| 155 | </Show> | 184 | </Show> |
| 156 | </div> | 185 | </div> |
| 186 | + </div> | ||
| 187 | + <Show when={isSelf(p()) && auth.user()}> | ||
| 188 | + <Button type="button" size="sm" variant="outline" class="mt-3 rounded-lg" onClick={() => setEditing(true)}> | ||
| 189 | + <IconEdit class="mr-1.5 h-4 w-4" /> | ||
| 190 | + {t("profile.edit")} | ||
| 191 | + </Button> | ||
| 192 | + </Show> | ||
| 157 | </div> | 193 | </div> |
| 158 | - <Show when={isSelf(p()) && auth.user()}> | ||
| 159 | - <Button type="button" size="sm" variant="outline" class="rounded-lg" onClick={() => setEditing(true)}> | ||
| 160 | - <IconEdit class="mr-1.5 h-4 w-4" /> | ||
| 161 | - {t("profile.edit")} | ||
| 162 | - </Button> | ||
| 163 | - </Show> | ||
| 164 | </section> | 194 | </section> |
| 165 | 195 | ||
| 166 | <section class="grid gap-3 sm:grid-cols-3 lg:grid-cols-5"> | 196 | <section class="grid gap-3 sm:grid-cols-3 lg:grid-cols-5"> |
| 167 | - <StatCard label={t("profile.statFocusHours")} value={Math.floor(p().stats.pomodoro_focus_ms_total / 3_600_000)} /> | 197 | + <For each={profileStats(p())}> |
| 168 | - <StatCard label={t("profile.statSessions")} value={p().stats.pomodoro_finished_total} /> | 198 | + {(stat) => <StatCard icon={stat.icon} label={stat.label} value={stat.value} />} |
| 169 | - <StatCard label={t("profile.statHomework")} value={p().stats.homework_submitted_total} /> | 199 | + </For> |
| 170 | - <StatCard label={t("profile.statOnTime")} value={p().stats.homework_on_time_total} /> | ||
| 171 | - <StatCard label={t("profile.statExams")} value={p().stats.exam_sat_total} /> | ||
| 172 | </section> | 200 | </section> |
| 173 | 201 | ||
| 174 | <BadgeGrid | 202 | <BadgeGrid |
| 175 | catalog={limits.latest?.badges?.catalog ?? []} | 203 | catalog={limits.latest?.badges?.catalog ?? []} |
| 176 | earned={p().badges} | 204 | earned={p().badges} |
| 177 | stats={p().stats} | 205 | stats={p().stats} |
| 206 | + role={p().role} | ||
| 178 | /> | 207 | /> |
| 179 | 208 | ||
| 180 | <ProfileMemberships | 209 | <ProfileMemberships |
| @@ -210,11 +239,16 @@ function ProfileContent() { | |||
| 210 | ); | 239 | ); |
| 211 | } | 240 | } |
| 212 | 241 | ||
| 213 | -function StatCard(props: { label: string; value: number }) { | 242 | +function StatCard(props: { icon: PixelIconName; label: string; value: number }) { |
| 214 | return ( | 243 | return ( |
| 215 | - <div class="rounded-lg border bg-card p-3 shadow-xs"> | 244 | + <div class="group flex items-center gap-3 rounded-lg border bg-card p-3 shadow-xs transition-colors hover:border-primary/30"> |
| 216 | - <p class="text-xs text-muted-foreground">{props.label}</p> | 245 | + <span class="flex h-10 w-10 shrink-0 items-center justify-center rounded-md bg-primary/10 text-primary transition-transform duration-200 group-hover:-rotate-6"> |
| 217 | - <p class="text-xl font-semibold tabular-nums">{props.value}</p> | 246 | + <PixelIcon name={props.icon} class="h-5 w-5" /> |
| 247 | + </span> | ||
| 248 | + <div class="min-w-0"> | ||
| 249 | + <p class="text-xl font-semibold leading-6 tabular-nums">{props.value}</p> | ||
| 250 | + <p class="truncate text-xs text-muted-foreground">{props.label}</p> | ||
| 251 | + </div> | ||
| 218 | </div> | 252 | </div> |
| 219 | ); | 253 | ); |
| 220 | } | 254 | } |