fix: verbleibende Lint-Befunde ausraeumen (Lint jetzt ohne Beanstandung)
Vier offene Befunde standen einem sauberen Produktionslauf im Weg:
- recently-viewed-section und site-chrome riefen setState direkt im
Effektrumpf auf, um einen Leerzustand herzustellen ("keine angesehenen
Produkte" bzw. "Eingabe kuerzer als zwei Zeichen"). Beides ergibt sich
unmittelbar aus vorhandenen Werten und wird jetzt beim Rendern
abgeleitet — das spart je einen zusaetzlichen Renderdurchlauf. Bei der
Suche verschwindet die Vorschlagsliste dadurch sofort beim Leeren des
Feldes statt erst nach dem naechsten Effektlauf.
- STAT_KEYS im Admin-Dashboard wurde ausschliesslich als Typ verwendet,
landete als `as const`-Array aber trotzdem im Bundle. Ersetzt durch
einen Typ-Alias.
- Ein DHL-Test importierte DhlApiError, ohne es zu benutzen, und pruefte
nur den Meldungstext — er haette damit jeden beliebigen anderen Fehler
mit passendem Text durchgehen lassen. Er prueft jetzt zusaetzlich den
Fehlertyp, wie seine beiden Geschwistertests.
Stand danach: eslint ohne Beanstandung (vorher 2 Fehler, 2 Warnungen),
tsc ohne Fehler, 201 Tests gruen, Produktions-Build erfolgreich.
This commit is contained in:
1 parent
107cbadf79
commit
02d493dede
4 files changed
+57
-35
No files matched your search
+17
-12
@@ -52,17 +52,22 @@ function PeopleIcon() {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
const STAT_KEYS = [
|
/**
|
||||||
"revenueToday",
|
* Die Kennzahlen-Kacheln des Dashboards. Bewusst ein Typ und keine
|
||||||
"revenueMonth",
|
* Wert-Konstante: die Liste wurde nie zur Laufzeit durchlaufen, sondern
|
||||||
"openOrders",
|
* ausschliesslich benutzt, um die Record-/Array-Typen unten vollstaendig zu
|
||||||
"inventory",
|
* halten — als `as const`-Array landete sie trotzdem im Bundle.
|
||||||
"soldGlasses",
|
*/
|
||||||
"avgCart",
|
type StatKey =
|
||||||
"repeatCustomers",
|
| "revenueToday"
|
||||||
] as const;
|
| "revenueMonth"
|
||||||
|
| "openOrders"
|
||||||
|
| "inventory"
|
||||||
|
| "soldGlasses"
|
||||||
|
| "avgCart"
|
||||||
|
| "repeatCustomers";
|
||||||
|
|
||||||
const statIcons: Record<(typeof STAT_KEYS)[number], () => ReturnType<typeof CoinIcon>> = {
|
const statIcons: Record<StatKey, () => ReturnType<typeof CoinIcon>> = {
|
||||||
revenueToday: CoinIcon,
|
revenueToday: CoinIcon,
|
||||||
revenueMonth: CoinIcon,
|
revenueMonth: CoinIcon,
|
||||||
openOrders: OrdersIcon,
|
openOrders: OrdersIcon,
|
||||||
@@ -161,7 +166,7 @@ export default async function AdminDashboardPage() {
|
|||||||
}
|
}
|
||||||
const repeatCustomerCount = [...ordersPerCustomer.values()].filter((count) => count > 1).length;
|
const repeatCustomerCount = [...ordersPerCustomer.values()].filter((count) => count > 1).length;
|
||||||
|
|
||||||
const statLabels: Record<(typeof STAT_KEYS)[number], string> = {
|
const statLabels: Record<StatKey, string> = {
|
||||||
revenueToday: t.adminDashboardPage.statRevenueToday,
|
revenueToday: t.adminDashboardPage.statRevenueToday,
|
||||||
revenueMonth: t.adminDashboardPage.statRevenueMonth,
|
revenueMonth: t.adminDashboardPage.statRevenueMonth,
|
||||||
openOrders: t.adminDashboardPage.statOpenOrders,
|
openOrders: t.adminDashboardPage.statOpenOrders,
|
||||||
@@ -171,7 +176,7 @@ export default async function AdminDashboardPage() {
|
|||||||
repeatCustomers: t.adminDashboardPage.statRepeatCustomers,
|
repeatCustomers: t.adminDashboardPage.statRepeatCustomers,
|
||||||
};
|
};
|
||||||
|
|
||||||
const stats: { key: (typeof STAT_KEYS)[number]; value: string }[] = [
|
const stats: { key: StatKey; value: string }[] = [
|
||||||
{ key: "revenueToday", value: formatPrice(revenueToday._sum.totalCents ?? 0) },
|
{ key: "revenueToday", value: formatPrice(revenueToday._sum.totalCents ?? 0) },
|
||||||
{ key: "revenueMonth", value: formatPrice(revenueMonth._sum.totalCents ?? 0) },
|
{ key: "revenueMonth", value: formatPrice(revenueMonth._sum.totalCents ?? 0) },
|
||||||
{ key: "openOrders", value: String(openOrders) },
|
{ key: "openOrders", value: String(openOrders) },
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
"use client";
|
"use client";
|
||||||
|
|
||||||
import { useEffect, useState } from "react";
|
import { useEffect, useMemo, useState } from "react";
|
||||||
import { useRecentlyViewedStore } from "@/store/recently-viewed-store";
|
import { useRecentlyViewedStore } from "@/store/recently-viewed-store";
|
||||||
import { getRecentlyViewedProducts } from "@/app/shop/actions";
|
import { getRecentlyViewedProducts } from "@/app/shop/actions";
|
||||||
import { ProductCard } from "@/components/product-card";
|
import { ProductCard } from "@/components/product-card";
|
||||||
@@ -15,22 +15,29 @@ import type { ProductWithRelations } from "@/lib/data";
|
|||||||
export function RecentlyViewedSection({ excludeProductId }: { excludeProductId?: string }) {
|
export function RecentlyViewedSection({ excludeProductId }: { excludeProductId?: string }) {
|
||||||
const { t } = useI18n();
|
const { t } = useI18n();
|
||||||
const viewedIds = useRecentlyViewedStore((s) => s.viewedIds);
|
const viewedIds = useRecentlyViewedStore((s) => s.viewedIds);
|
||||||
const [products, setProducts] = useState<ProductWithRelations[]>([]);
|
const ids = useMemo(
|
||||||
|
() => viewedIds.filter((id) => id !== excludeProductId),
|
||||||
|
[viewedIds, excludeProductId]
|
||||||
|
);
|
||||||
|
const [fetched, setFetched] = useState<ProductWithRelations[]>([]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const ids = viewedIds.filter((id) => id !== excludeProductId);
|
// Der Leerfall wird bewusst NICHT mehr per setState im Effekt behandelt:
|
||||||
if (ids.length === 0) {
|
// "keine angesehenen Produkte" ergibt sich unmittelbar aus ids und laesst
|
||||||
setProducts([]);
|
// sich beim Rendern ableiten. Ein setState direkt im Effektrumpf loest
|
||||||
return;
|
// dagegen einen zusaetzlichen Renderdurchlauf aus, nur um einen Zustand
|
||||||
}
|
// herzustellen, der ohnehin schon feststand.
|
||||||
|
if (ids.length === 0) return;
|
||||||
let cancelled = false;
|
let cancelled = false;
|
||||||
getRecentlyViewedProducts(ids).then((result) => {
|
getRecentlyViewedProducts(ids).then((result) => {
|
||||||
if (!cancelled) setProducts(result);
|
if (!cancelled) setFetched(result);
|
||||||
});
|
});
|
||||||
return () => {
|
return () => {
|
||||||
cancelled = true;
|
cancelled = true;
|
||||||
};
|
};
|
||||||
}, [viewedIds, excludeProductId]);
|
}, [ids]);
|
||||||
|
|
||||||
|
const products = ids.length === 0 ? [] : fetched;
|
||||||
|
|
||||||
if (products.length === 0) return null;
|
if (products.length === 0) return null;
|
||||||
|
|
||||||
|
|||||||
@@ -101,12 +101,17 @@ function SearchButton() {
|
|||||||
const [suggestions, setSuggestions] = useState<SearchSuggestion[]>([]);
|
const [suggestions, setSuggestions] = useState<SearchSuggestion[]>([]);
|
||||||
const toggleButtonRef = useRef<HTMLButtonElement>(null);
|
const toggleButtonRef = useRef<HTMLButtonElement>(null);
|
||||||
|
|
||||||
|
// "Eingabe zu kurz" ergibt sich unmittelbar aus query und wird beim
|
||||||
|
// Rendern abgeleitet, statt im Effekt per setState hergestellt zu werden —
|
||||||
|
// ein setState direkt im Effektrumpf loest einen zusaetzlichen
|
||||||
|
// Renderdurchlauf aus, nur um einen ohnehin feststehenden Zustand zu
|
||||||
|
// erzeugen. Nebeneffekt: beim Leeren des Feldes verschwindet die Liste
|
||||||
|
// sofort, statt erst nach dem naechsten Effektlauf.
|
||||||
|
const visibleSuggestions = query.trim().length < 2 ? [] : suggestions;
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const trimmed = query.trim();
|
const trimmed = query.trim();
|
||||||
if (trimmed.length < 2) {
|
if (trimmed.length < 2) return;
|
||||||
setSuggestions([]);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
const controller = new AbortController();
|
const controller = new AbortController();
|
||||||
const timeout = setTimeout(() => {
|
const timeout = setTimeout(() => {
|
||||||
fetch(`/api/shop/search-suggestions?q=${encodeURIComponent(trimmed)}`, {
|
fetch(`/api/shop/search-suggestions?q=${encodeURIComponent(trimmed)}`, {
|
||||||
@@ -153,9 +158,9 @@ function SearchButton() {
|
|||||||
placeholder={t.nav.searchPlaceholder}
|
placeholder={t.nav.searchPlaceholder}
|
||||||
className="w-full border-b border-forest bg-transparent px-2 py-1 text-sm focus:outline-none"
|
className="w-full border-b border-forest bg-transparent px-2 py-1 text-sm focus:outline-none"
|
||||||
/>
|
/>
|
||||||
{suggestions.length > 0 ? (
|
{visibleSuggestions.length > 0 ? (
|
||||||
<ul className="absolute top-full left-0 mt-2 w-72 bg-background border border-ink/10 shadow-[0_16px_32px_-16px_rgba(36,53,43,0.25)] z-50">
|
<ul className="absolute top-full left-0 mt-2 w-72 bg-background border border-ink/10 shadow-[0_16px_32px_-16px_rgba(36,53,43,0.25)] z-50">
|
||||||
{suggestions.map((s) => (
|
{visibleSuggestions.map((s) => (
|
||||||
<li key={s.slug}>
|
<li key={s.slug}>
|
||||||
<Link
|
<Link
|
||||||
href={`/honig/${s.slug}`}
|
href={`/honig/${s.slug}`}
|
||||||
|
|||||||
+13
-8
@@ -165,13 +165,18 @@ describe("createDhlShipmentLabel", () => {
|
|||||||
vi.stubGlobal("fetch", fetchMock);
|
vi.stubGlobal("fetch", fetchMock);
|
||||||
const { createDhlShipmentLabel, DhlApiError } = await import("./dhl");
|
const { createDhlShipmentLabel, DhlApiError } = await import("./dhl");
|
||||||
|
|
||||||
await expect(
|
const attempt = createDhlShipmentLabel({
|
||||||
createDhlShipmentLabel({
|
reference: "WH-2026-0004",
|
||||||
reference: "WH-2026-0004",
|
weightGrams: 500,
|
||||||
weightGrams: 500,
|
shipper: validShipper,
|
||||||
shipper: validShipper,
|
receiver: validAddress,
|
||||||
receiver: validAddress,
|
});
|
||||||
})
|
|
||||||
).rejects.toThrow(/Ungültige Anfrage/);
|
// Neben der Meldung auch den Fehlertyp pruefen — wie in den beiden Tests
|
||||||
|
// darueber. Ohne diese Zusage blieb das bereits importierte DhlApiError
|
||||||
|
// hier ungenutzt, und der Test haette jeden beliebigen anderen Fehler mit
|
||||||
|
// passendem Text durchgehen lassen.
|
||||||
|
await expect(attempt).rejects.toThrow(DhlApiError);
|
||||||
|
await expect(attempt).rejects.toThrow(/Ungültige Anfrage/);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
Reference in new issue
Block a user