feat(files): improve bulk selection, upload progress and i18n (#17)
CD — Deployment / deploy (push) Successful in 15s
CD — Deployment / deploy (push) Successful in 15s
PR automatique de feat/bulk-selection-ux vers main. --------- Co-authored-by: xEsiah <[email protected]> Reviewed-on: #17 Reviewed-by: Esiah <[email protected]> Co-authored-by: Gitea Actions <-[email protected]>
This commit was merged in pull request #17.
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import { createContext, useCallback, useContext, useState, type ReactNode } from "react";
|
||||
import { cn } from "../ui/index.js";
|
||||
import { useI18n } from "../lib/i18n.js";
|
||||
import { CloseIcon } from "./icons.js";
|
||||
|
||||
type ToastTone = "success" | "error" | "info";
|
||||
@@ -29,6 +30,7 @@ export const useToast = () => {
|
||||
let toastId = 0;
|
||||
|
||||
export const ToastProvider = ({ children }: { children: ReactNode }) => {
|
||||
const { t } = useI18n();
|
||||
const [toasts, setToasts] = useState<Toast[]>([]);
|
||||
|
||||
const remove = useCallback((id: number) => {
|
||||
@@ -51,23 +53,23 @@ export const ToastProvider = ({ children }: { children: ReactNode }) => {
|
||||
<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) => (
|
||||
{toasts.map((toastItem) => (
|
||||
<div
|
||||
key={t.id}
|
||||
key={toastItem.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",
|
||||
toastItem.tone === "success" && "border-accent/40 bg-accent/10 text-foreground",
|
||||
toastItem.tone === "error" && "border-destructive/40 bg-destructive/10 text-destructive",
|
||||
toastItem.tone === "info" && "border-border bg-surface text-foreground",
|
||||
)}
|
||||
role="status"
|
||||
>
|
||||
<p className="flex-1 text-sm leading-relaxed">{t.message}</p>
|
||||
<p className="flex-1 text-sm leading-relaxed">{toastItem.message}</p>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => remove(t.id)}
|
||||
onClick={() => remove(toastItem.id)}
|
||||
className="text-muted-foreground transition-colors hover:text-foreground"
|
||||
aria-label="Fermer"
|
||||
aria-label={t("Fermer")}
|
||||
>
|
||||
<CloseIcon className="h-4 w-4" />
|
||||
</button>
|
||||
|
||||
@@ -192,6 +192,18 @@ const en: Record<string, string> = {
|
||||
"Déposez vos fichiers ici": "Drop your files here",
|
||||
"{count} fichier(s) déposé(s) dans {name}.": "{count} file(s) uploaded to {name}.",
|
||||
"{count} fichier(s) déposé(s) dans ce dossier.": "{count} file(s) uploaded to this folder.",
|
||||
"Envoi en cours": "Uploading",
|
||||
"Envoi {current}/{total}…": "Uploading {current}/{total}…",
|
||||
"{current}/{total}": "{current}/{total}",
|
||||
|
||||
// --- Sélection multiple -----------------------------------------------
|
||||
"Sélectionner {name}": "Select {name}",
|
||||
"{count} élément(s) sélectionné(s).": "{count} item(s) selected.",
|
||||
"Annuler la sélection": "Clear selection",
|
||||
"Déplacer {count} éléments": "Move {count} items",
|
||||
"{count} éléments seront déplacés.": "{count} items will be moved.",
|
||||
"{count} élément(s) seront placés dans la corbeille.":
|
||||
"{count} item(s) will be moved to the trash.",
|
||||
|
||||
// --- Visionneuse -------------------------------------------------------
|
||||
"Lecture impossible.": "Unable to read.",
|
||||
|
||||
@@ -339,6 +339,35 @@ export const Browser = () => {
|
||||
}
|
||||
};
|
||||
|
||||
const removeSelected = async () => {
|
||||
const ok = await confirm({
|
||||
title: t("Mettre à la corbeille"),
|
||||
message: t("{count} élément(s) seront placés dans la corbeille.", {
|
||||
count: selectedItems.length,
|
||||
}),
|
||||
confirmLabel: t("Corbeille"),
|
||||
tone: "danger",
|
||||
});
|
||||
if (!ok) return;
|
||||
setError(null);
|
||||
try {
|
||||
for (const target of selectedItems) {
|
||||
if (target.type === "folder") await api.deleteFolder(target.id);
|
||||
else await api.deleteFile(target.id);
|
||||
}
|
||||
clearSelection();
|
||||
await reload();
|
||||
void refresh();
|
||||
} catch (caught) {
|
||||
const msg =
|
||||
caught instanceof ApiError
|
||||
? caught.message
|
||||
: t("Suppression impossible.");
|
||||
setError(msg);
|
||||
toast.error(msg);
|
||||
}
|
||||
};
|
||||
|
||||
const toggleStar = async (file: UploadedFile) => {
|
||||
setError(null);
|
||||
try {
|
||||
@@ -603,21 +632,26 @@ export const Browser = () => {
|
||||
>
|
||||
{t("Déplacer")}
|
||||
</Button>
|
||||
<Button
|
||||
size="sm"
|
||||
variant="secondary"
|
||||
onClick={() => {
|
||||
for (const target of selectedItems) {
|
||||
if (target.type === "file") {
|
||||
const link = document.createElement("a");
|
||||
link.href = api.downloadUrl(target.id);
|
||||
link.download = target.name;
|
||||
link.click();
|
||||
}
|
||||
}
|
||||
}}
|
||||
>
|
||||
{t("Télécharger")}
|
||||
</Button>
|
||||
<Button
|
||||
size="sm"
|
||||
variant="destructive"
|
||||
onClick={() =>
|
||||
void Promise.all(
|
||||
selectedItems.map((target) =>
|
||||
target.type === "folder"
|
||||
? api.deleteFolder(target.id)
|
||||
: api.deleteFile(target.id),
|
||||
),
|
||||
).then(async () => {
|
||||
clearSelection();
|
||||
await reload();
|
||||
})
|
||||
}
|
||||
onClick={() => void removeSelected()}
|
||||
>
|
||||
{t("Supprimer")}
|
||||
</Button>
|
||||
@@ -677,15 +711,17 @@ export const Browser = () => {
|
||||
aria-label={t("Sélectionner {name}", {
|
||||
name: folder.name,
|
||||
})}
|
||||
onChange={(event) => {
|
||||
event.stopPropagation();
|
||||
toggleSelection(`f:${folder.id}`);
|
||||
}}
|
||||
onClick={(event) => event.stopPropagation()}
|
||||
onChange={() => toggleSelection(`f:${folder.id}`)}
|
||||
/>
|
||||
<button
|
||||
type="button"
|
||||
onClick={(event) => {
|
||||
event.stopPropagation();
|
||||
if (selectedItems.length > 0) {
|
||||
toggleSelection(`f:${folder.id}`);
|
||||
return;
|
||||
}
|
||||
open(folder);
|
||||
}}
|
||||
className="flex min-w-0 flex-1 items-center gap-3 rounded-sm p-1 text-left focus-visible:ring-ring focus-visible:ring-2 focus-visible:outline-none"
|
||||
@@ -795,10 +831,8 @@ export const Browser = () => {
|
||||
aria-label={t("Sélectionner {name}", {
|
||||
name: file.name,
|
||||
})}
|
||||
onChange={(event) => {
|
||||
event.stopPropagation();
|
||||
toggleSelection(`i:${file.id}`);
|
||||
}}
|
||||
onClick={(event) => event.stopPropagation()}
|
||||
onChange={() => toggleSelection(`i:${file.id}`)}
|
||||
/>
|
||||
<button
|
||||
type="button"
|
||||
|
||||
Reference in New Issue
Block a user