refactor(admin): remove sidebar favorites
CI / check (push) Successful in 1m8s
CI / deploy (push) Successful in 1m5s

This commit is contained in:
Simo committed 2026-09-06 17:25:04 +02:00
1 parent a070004e7b
commit 96234075f8
7 files changed
+1 -152

No files matched your search

-106
View File
@@ -1,106 +0,0 @@
"use client";
import { Star, X } from "lucide-react";
import { useTranslations } from "next-intl";
import { useEffect, useState } from "react";
import type { AdminNavItem } from "@/lib/admin-nav";
import { parseFavoritePages } from "@/lib/admin-navigation";
import { AdminNavLink } from "./admin-nav-link";
export function AdminFavorites({
userId,
items,
}: {
userId: number;
items: AdminNavItem[];
}) {
const t = useTranslations("pages.admin.nav");
const key = `admin-favorites:${userId}`;
const [saved, setSaved] = useState<{ key: string; hrefs: string[] }>({
key: "",
hrefs: [],
});
const [storageError, setStorageError] = useState(false);
useEffect(() => {
try {
setSaved({ key, hrefs: parseFavoritePages(localStorage.getItem(key)) });
} catch {
setSaved({ key, hrefs: [] });
}
}, [key]);
const favorites =
saved.key === key
? saved.hrefs.flatMap((href) => items.find((i) => i.href === href) ?? [])
: [];
function save(hrefs: string[]) {
setSaved({ key, hrefs });
try {
localStorage.setItem(key, JSON.stringify(hrefs));
setStorageError(false);
} catch {
setStorageError(true);
}
}
return (
<section
className="mb-3 border-b border-[var(--admin-border)] pb-3"
aria-label={t("favorites")}
>
<h2
style={{ fontSize: ".75rem", margin: 0 }}
className="flex items-center gap-2 px-2 py-2 text-xs font-semibold text-[var(--admin-sidebar-muted-readable)]"
>
<Star size={14} aria-hidden />
{t("favorites")}
</h2>
{favorites.map((item) => (
<div key={item.href} className="flex items-center">
<div className="min-w-0 flex-1">
<AdminNavLink {...item} icon={<item.icon size={16} />}>
{t(item.labelKey)}
</AdminNavLink>
</div>
<button
type="button"
onClick={() =>
save(
favorites
.filter((i) => i.href !== item.href)
.map((i) => i.href),
)
}
aria-label={t("removeFavorite", { name: t(item.labelKey) })}
className="grid h-9 w-9 shrink-0 place-items-center rounded focus-visible:ring-2 focus-visible:ring-[var(--admin-accent)]"
>
<X size={14} />
</button>
</div>
))}
{favorites.length < 6 && (
<select
aria-label={t("addFavorite")}
value=""
disabled={saved.key !== key}
onChange={(event) => {
if (event.target.value)
save([...favorites.map((i) => i.href), event.target.value]);
}}
className="mt-1 h-9 w-full min-w-0 rounded-lg border border-[var(--admin-border)] bg-[var(--admin-sidebar-background)] px-2 text-xs text-[var(--admin-sidebar-text-readable)]"
>
<option value="">{t("addFavorite")}</option>
{items
.filter((item) => !favorites.some((f) => f.href === item.href))
.map((item) => (
<option key={item.href} value={item.href}>
{t(item.labelKey)}
</option>
))}
</select>
)}
{storageError && (
<p role="status" className="px-2 text-xs">
{t("favoriteStorageError")}
</p>
)}
</section>
);
}
@@ -15,7 +15,6 @@ import type { AdminNavItem } from "@/lib/admin-nav";
import type { AdminNavConfig } from "@/lib/admin-nav-config";
import { visibleAdminNavigation } from "@/lib/admin-navigation";
import { cn } from "@/lib/utils";
import { AdminFavorites } from "./admin-favorites";
const STORAGE_KEY = "admin-nav-collapsed";
@@ -62,12 +61,10 @@ function persistCollapsed(next: Record<string, boolean>) {
}
export function AdminSidebarNav({
userId = 0,
allowedPermissions = [],
isSuperAdmin = false,
navConfig = {},
}: {
userId?: number;
/** ACL slugs the staff member holds (ignored when isSuperAdmin). */
allowedPermissions?: string[];
isSuperAdmin?: boolean;
@@ -263,12 +260,6 @@ export function AdminSidebarNav({
</div>
<div className="min-h-0 flex-1 overflow-y-auto overscroll-contain px-3 py-3">
{!search && (
<AdminFavorites
userId={userId}
items={groups.flatMap((group) => group.items)}
/>
)}
{visibleGroups.length === 0 && (
<p
role="status"