feat(ui): add grouped actions; add contextual menu for grouped actions; items & folders can be selected without precisly clicking the checkbox (#16)
CD — Deployment / deploy (push) Successful in 15s
CD — Deployment / deploy (push) Successful in 15s
PR automatique de feat/bulk-move-upload-progress vers main. --------- Co-authored-by: xEsiah <[email protected]> Reviewed-on: #16 Reviewed-by: Esiah <[email protected]> Co-authored-by: Gitea Actions <-[email protected]>
This commit was merged in pull request #16.
This commit is contained in:
@@ -11,7 +11,7 @@ export const IconAction = ({
|
||||
}: {
|
||||
label: string;
|
||||
icon: ReactNode;
|
||||
onClick: () => void;
|
||||
onClick: (event: React.MouseEvent<HTMLButtonElement>) => void;
|
||||
isLoading?: boolean;
|
||||
tone?: "neutral" | "danger";
|
||||
badge?: number;
|
||||
|
||||
@@ -157,14 +157,19 @@ const loadTree = async (): Promise<TreeEntry[]> => {
|
||||
|
||||
export const MoveDialog = ({
|
||||
target,
|
||||
targets,
|
||||
onClose,
|
||||
onDone,
|
||||
}: {
|
||||
target: Target;
|
||||
target?: Target;
|
||||
targets?: Target[];
|
||||
onClose: () => void;
|
||||
onDone: () => void;
|
||||
}) => {
|
||||
const { t } = useI18n();
|
||||
const items = targets && targets.length > 0 ? targets : target ? [target] : [];
|
||||
const single = items.length === 1 ? items[0] : null;
|
||||
const title = single ? t("Déplacer") : t("Déplacer {count} éléments", { count: items.length });
|
||||
const [entries, setEntries] = useState<TreeEntry[] | null>(null);
|
||||
const [destination, setDestination] = useState<string>("");
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
@@ -182,8 +187,10 @@ export const MoveDialog = ({
|
||||
setError(null);
|
||||
const parentId = destination === "" ? null : destination;
|
||||
try {
|
||||
if (target.type === "folder") await api.moveFolder(target.id, parentId);
|
||||
else await api.moveFile(target.id, parentId);
|
||||
for (const item of items) {
|
||||
if (item.type === "folder") await api.moveFolder(item.id, parentId);
|
||||
else await api.moveFile(item.id, parentId);
|
||||
}
|
||||
onDone();
|
||||
} catch (caught) {
|
||||
setError(messageOf(caught, t("Déplacement impossible.")));
|
||||
@@ -193,10 +200,12 @@ export const MoveDialog = ({
|
||||
};
|
||||
|
||||
return (
|
||||
<Modal open title={t("Déplacer")} onClose={onClose}>
|
||||
<Modal open title={title} onClose={onClose}>
|
||||
<form className="flex flex-col gap-4" onSubmit={(event) => void submit(event)}>
|
||||
<p className="text-sm text-muted-foreground">
|
||||
{t("Destination de {name}.", { name: target.name })}
|
||||
{single
|
||||
? t("Destination de {name}.", { name: single.name })
|
||||
: t("{count} éléments seront déplacés.", { count: items.length })}
|
||||
</p>
|
||||
{entries === null && !error ? (
|
||||
<Alert tone="info">{t("Chargement des dossiers…")}</Alert>
|
||||
@@ -214,13 +223,13 @@ export const MoveDialog = ({
|
||||
)}
|
||||
>
|
||||
<option value="">{t("Racine")}</option>
|
||||
{(entries ?? [])
|
||||
.filter((entry) => entry.id !== target.id)
|
||||
.map((entry) => (
|
||||
<option key={entry.id} value={entry.id}>
|
||||
{entry.label}
|
||||
</option>
|
||||
))}
|
||||
{(entries ?? [])
|
||||
.filter((entry) => !items.some((item) => item.type === "folder" && item.id === entry.id))
|
||||
.map((entry) => (
|
||||
<option key={entry.id} value={entry.id}>
|
||||
{entry.label}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
</label>
|
||||
)}
|
||||
|
||||
@@ -42,7 +42,7 @@ export const Modal = ({
|
||||
role="dialog"
|
||||
aria-modal="true"
|
||||
aria-label={title}
|
||||
className="animate-panel-in relative w-full max-w-md rounded-lg border border-border bg-surface p-4 shadow-lg"
|
||||
className="animate-panel-in relative w-full max-w-lg sm:max-w-md rounded-lg border border-border bg-surface p-4 sm:p-5 shadow-lg"
|
||||
>
|
||||
<div className="mb-4 flex items-center justify-between gap-4">
|
||||
<h2 className="font-display text-xs font-semibold uppercase tracking-label text-foreground">
|
||||
|
||||
@@ -0,0 +1,79 @@
|
||||
import { createContext, useCallback, useContext, useState, type ReactNode } from "react";
|
||||
import { cn } from "../ui/index.js";
|
||||
import { CloseIcon } from "./icons.js";
|
||||
|
||||
type ToastTone = "success" | "error" | "info";
|
||||
|
||||
interface Toast {
|
||||
id: number;
|
||||
message: string;
|
||||
tone: ToastTone;
|
||||
duration: number;
|
||||
}
|
||||
|
||||
interface ToastContextValue {
|
||||
toast: (message: string, tone?: ToastTone, duration?: number) => void;
|
||||
success: (message: string, duration?: number) => void;
|
||||
error: (message: string, duration?: number) => void;
|
||||
info: (message: string, duration?: number) => void;
|
||||
}
|
||||
|
||||
const ToastContext = createContext<ToastContextValue | null>(null);
|
||||
|
||||
export const useToast = () => {
|
||||
const ctx = useContext(ToastContext);
|
||||
if (!ctx) throw new Error("useToast must be used within ToastProvider");
|
||||
return ctx;
|
||||
};
|
||||
|
||||
let toastId = 0;
|
||||
|
||||
export const ToastProvider = ({ children }: { children: ReactNode }) => {
|
||||
const [toasts, setToasts] = useState<Toast[]>([]);
|
||||
|
||||
const remove = useCallback((id: number) => {
|
||||
setToasts((prev) => prev.filter((t) => t.id !== id));
|
||||
}, []);
|
||||
|
||||
const toast = useCallback((message: string, tone: ToastTone = "info", duration = 4000) => {
|
||||
const id = ++toastId;
|
||||
setToasts((prev) => [...prev, { id, message, tone, duration }]);
|
||||
if (duration > 0) {
|
||||
setTimeout(() => remove(id), duration);
|
||||
}
|
||||
}, [remove]);
|
||||
|
||||
const success = useCallback((message: string, duration = 4000) => toast(message, "success", duration), [toast]);
|
||||
const error = useCallback((message: string, duration = 5000) => toast(message, "error", duration), [toast]);
|
||||
const info = useCallback((message: string, duration = 4000) => toast(message, "info", duration), [toast]);
|
||||
|
||||
return (
|
||||
<ToastContext.Provider value={{ toast, success, error, info }}>
|
||||
{children}
|
||||
<div className="fixed left-4 right-4 top-6 z-[100] flex flex-col gap-2 sm:left-auto sm:right-4 sm:max-w-sm">
|
||||
{toasts.map((t) => (
|
||||
<div
|
||||
key={t.id}
|
||||
className={cn(
|
||||
"animate-in slide-in-from-right fade-in flex min-w-[280px] max-w-sm items-start gap-3 rounded-lg border px-4 py-3 shadow-lg backdrop-blur",
|
||||
t.tone === "success" && "border-accent/40 bg-accent/10 text-foreground",
|
||||
t.tone === "error" && "border-destructive/40 bg-destructive/10 text-destructive",
|
||||
t.tone === "info" && "border-border bg-surface text-foreground",
|
||||
)}
|
||||
role="status"
|
||||
>
|
||||
<p className="flex-1 text-sm leading-relaxed">{t.message}</p>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => remove(t.id)}
|
||||
className="text-muted-foreground transition-colors hover:text-foreground"
|
||||
aria-label="Fermer"
|
||||
>
|
||||
<CloseIcon className="h-4 w-4" />
|
||||
</button>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</ToastContext.Provider>
|
||||
);
|
||||
};
|
||||
Reference in New Issue
Block a user