mirror of
https://github.com/nicotsx/ironmount.git
synced 2025-12-10 12:10:51 +01:00
refactor: unify backend and frontend servers (#3)
* refactor: unify backend and frontend servers * refactor: correct paths for openapi & drizzle * refactor: move api-client to client * fix: drizzle paths * chore: fix linting issues * fix: form reset issue
This commit is contained in:
86
app/client/lib/breadcrumbs.ts
Normal file
86
app/client/lib/breadcrumbs.ts
Normal file
@@ -0,0 +1,86 @@
|
||||
import { useLocation, useParams } from "react-router";
|
||||
|
||||
export interface BreadcrumbItem {
|
||||
label: string;
|
||||
href?: string;
|
||||
isCurrentPage?: boolean;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates breadcrumb items based on the current route
|
||||
* @param pathname - Current pathname from useLocation
|
||||
* @param params - Route parameters from useParams
|
||||
* @returns Array of breadcrumb items
|
||||
*/
|
||||
export function generateBreadcrumbs(pathname: string, params: Record<string, string | undefined>): BreadcrumbItem[] {
|
||||
const breadcrumbs: BreadcrumbItem[] = [];
|
||||
|
||||
if (pathname.startsWith("/repositories")) {
|
||||
breadcrumbs.push({
|
||||
label: "Repositories",
|
||||
href: "/repositories",
|
||||
isCurrentPage: pathname === "/repositories",
|
||||
});
|
||||
|
||||
if (pathname.startsWith("/repositories/") && params.name) {
|
||||
const isSnapshotPage = !!params.snapshotId;
|
||||
|
||||
breadcrumbs.push({
|
||||
label: params.name,
|
||||
href: isSnapshotPage ? `/repositories/${params.name}` : undefined,
|
||||
isCurrentPage: !isSnapshotPage,
|
||||
});
|
||||
|
||||
if (isSnapshotPage && params.snapshotId) {
|
||||
breadcrumbs.push({
|
||||
label: params.snapshotId,
|
||||
isCurrentPage: true,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return breadcrumbs;
|
||||
}
|
||||
|
||||
if (pathname.startsWith("/backups")) {
|
||||
breadcrumbs.push({
|
||||
label: "Backups",
|
||||
href: "/backups",
|
||||
isCurrentPage: pathname === "/backups",
|
||||
});
|
||||
|
||||
if (pathname.startsWith("/backups/") && params.id) {
|
||||
breadcrumbs.push({
|
||||
label: `Schedule #${params.id}`,
|
||||
isCurrentPage: true,
|
||||
});
|
||||
}
|
||||
|
||||
return breadcrumbs;
|
||||
}
|
||||
|
||||
breadcrumbs.push({
|
||||
label: "Volumes",
|
||||
href: "/volumes",
|
||||
isCurrentPage: pathname === "/volumes",
|
||||
});
|
||||
|
||||
if (pathname.startsWith("/volumes/") && params.name) {
|
||||
breadcrumbs.push({
|
||||
label: params.name,
|
||||
isCurrentPage: true,
|
||||
});
|
||||
}
|
||||
|
||||
return breadcrumbs;
|
||||
}
|
||||
|
||||
/**
|
||||
* Hook to get breadcrumb data for the current route
|
||||
*/
|
||||
export function useBreadcrumbs(): BreadcrumbItem[] {
|
||||
const location = useLocation();
|
||||
const params = useParams();
|
||||
|
||||
return generateBreadcrumbs(location.pathname, params);
|
||||
}
|
||||
11
app/client/lib/errors.ts
Normal file
11
app/client/lib/errors.ts
Normal file
@@ -0,0 +1,11 @@
|
||||
export const parseError = (error?: unknown) => {
|
||||
if (error && typeof error === "object" && "message" in error) {
|
||||
return { message: error.message as string };
|
||||
}
|
||||
|
||||
if (typeof error === "string") {
|
||||
return { message: error };
|
||||
}
|
||||
|
||||
return undefined;
|
||||
};
|
||||
19
app/client/lib/types.ts
Normal file
19
app/client/lib/types.ts
Normal file
@@ -0,0 +1,19 @@
|
||||
import type {
|
||||
GetBackupScheduleResponse,
|
||||
GetMeResponse,
|
||||
GetRepositoryResponse,
|
||||
GetVolumeResponse,
|
||||
ListSnapshotsResponse,
|
||||
} from "../api-client";
|
||||
|
||||
export type Volume = GetVolumeResponse["volume"];
|
||||
export type StatFs = GetVolumeResponse["statfs"];
|
||||
export type VolumeStatus = Volume["status"];
|
||||
|
||||
export type User = GetMeResponse["user"];
|
||||
|
||||
export type Repository = GetRepositoryResponse;
|
||||
|
||||
export type BackupSchedule = GetBackupScheduleResponse;
|
||||
|
||||
export type Snapshot = ListSnapshotsResponse[number];
|
||||
30
app/client/lib/utils.ts
Normal file
30
app/client/lib/utils.ts
Normal file
@@ -0,0 +1,30 @@
|
||||
import { type ClassValue, clsx } from "clsx";
|
||||
import { twMerge } from "tailwind-merge";
|
||||
|
||||
/** Conditional merge of class names */
|
||||
export function cn(...inputs: ClassValue[]) {
|
||||
return twMerge(clsx(inputs));
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts an arbitrary string into a URL-safe slug:
|
||||
* - lowercase
|
||||
* - trims whitespace
|
||||
* - replaces non-alphanumeric runs with "-"
|
||||
* - collapses multiple hyphens
|
||||
* - trims leading/trailing hyphens
|
||||
*/
|
||||
/**
|
||||
* Live slugify for UI: lowercases, normalizes dashes, replaces invalid runs with "-",
|
||||
* collapses repeats, but DOES NOT trim leading/trailing hyphens so the user can type
|
||||
* spaces/dashes progressively while editing.
|
||||
*/
|
||||
export function slugify(input: string): string {
|
||||
return input
|
||||
.toLowerCase()
|
||||
.replace(/[ ]/g, "-")
|
||||
.replace(/[^a-z0-9_-]+/g, "")
|
||||
.replace(/[-]{2,}/g, "-")
|
||||
.replace(/[_]{2,}/g, "_")
|
||||
.trim();
|
||||
}
|
||||
Reference in New Issue
Block a user