Refactor DashboardCollectionList: Simplify search input layout and improve tag selection logic for better user experience.

This commit is contained in:
Peter Meier
2026-03-12 16:36:20 +01:00
parent 22b4367c47
commit 7754d800f5
17 changed files with 759 additions and 151 deletions

View File

@@ -1,20 +1,49 @@
/**
* RustyCMS API client. Base URL from NEXT_PUBLIC_RUSTYCMS_API_URL.
* Optional RUSTYCMS_API_KEY for write operations (sent as X-API-Key).
* API key: from env (NEXT_PUBLIC_RUSTYCMS_API_KEY) or from login (sessionStorage).
*/
export const getBaseUrl = () =>
process.env.NEXT_PUBLIC_RUSTYCMS_API_URL || "http://127.0.0.1:3000";
const STORAGE_KEY = "rustycms_admin_api_key";
/** Client-side only: key set by login when no env key. */
let clientApiKey: string | null = null;
/** Get API key (env or login). Call from client; server uses env only. */
export function getApiKey(): string | null {
if (typeof window !== "undefined") {
const fromEnv = process.env.NEXT_PUBLIC_RUSTYCMS_API_KEY ?? null;
if (fromEnv) return fromEnv;
return clientApiKey ?? sessionStorage.getItem(STORAGE_KEY);
}
return process.env.RUSTYCMS_API_KEY ?? process.env.NEXT_PUBLIC_RUSTYCMS_API_KEY ?? null;
}
/** Set API key after login (sessionStorage + in-memory). */
export function setApiKey(key: string | null): void {
if (key) {
sessionStorage.setItem(STORAGE_KEY, key);
clientApiKey = key;
} else {
sessionStorage.removeItem(STORAGE_KEY);
clientApiKey = null;
}
}
/** Sync stored key into memory (call once on app load). */
export function syncStoredApiKey(): void {
const stored = sessionStorage.getItem(STORAGE_KEY);
if (stored) clientApiKey = stored;
}
const getHeaders = (): HeadersInit => {
const headers: HeadersInit = {
"Content-Type": "application/json",
Accept: "application/json",
};
const key =
typeof window !== "undefined"
? process.env.NEXT_PUBLIC_RUSTYCMS_API_KEY ?? null
: process.env.RUSTYCMS_API_KEY ?? process.env.NEXT_PUBLIC_RUSTYCMS_API_KEY ?? null;
const key = getApiKey();
if (key) headers["X-API-Key"] = key;
return headers;
};
@@ -306,11 +335,8 @@ export async function deleteFolder(name: string): Promise<void> {
}
const getUploadHeaders = (): HeadersInit => {
const key =
typeof window !== "undefined"
? process.env.NEXT_PUBLIC_RUSTYCMS_API_KEY ?? null
: process.env.RUSTYCMS_API_KEY ?? process.env.NEXT_PUBLIC_RUSTYCMS_API_KEY ?? null;
const headers: HeadersInit = {};
const key = getApiKey();
if (key) headers["X-API-Key"] = key;
return headers;
};