From 1c29b3b46397dc3a69ac89a09d4fdcfa51ffa9ee Mon Sep 17 00:00:00 2001 From: xEsiah Date: Sat, 17 Oct 2026 14:33:18 +0200 Subject: [PATCH 1/3] feat(backend): per-user preferences, favorites and chat read tracking - add users.theme and users.language, exposed in the session and through a new GET/PATCH /account/preferences endpoint - replace the global files.is_starred flag with a user_file_stars join table and backfill existing stars to the file owner - track chat read state per user (chat_reads) and expose GET /chat/unread for folder badges - expose GET /directory listing active users - drop the unused folders.description column - let the admin audit log be filtered by user and action, with facets --- backend/migrations/008_user_preferences.sql | 47 +++++++++++++ backend/src/index.ts | 2 + backend/src/routes/account.ts | 26 ++++++++ backend/src/routes/admin.ts | 54 ++++++++++++--- backend/src/routes/auth.ts | 5 ++ backend/src/routes/chat.ts | 50 +++++++++++++- backend/src/routes/directory.ts | 47 +++++++++++++ backend/src/routes/files.ts | 74 +++++++++++++-------- backend/src/routes/folders.ts | 26 +++----- backend/src/routes/media.ts | 5 +- backend/src/routes/search.ts | 9 ++- backend/src/routes/trash.ts | 4 +- 12 files changed, 280 insertions(+), 69 deletions(-) create mode 100644 backend/migrations/008_user_preferences.sql create mode 100644 backend/src/routes/directory.ts diff --git a/backend/migrations/008_user_preferences.sql b/backend/migrations/008_user_preferences.sql new file mode 100644 index 0000000..5566e7c --- /dev/null +++ b/backend/migrations/008_user_preferences.sql @@ -0,0 +1,47 @@ +-- 008_user_preferences.sql +-- +-- 1. Preferences d'affichage par utilisateur (theme et langue), choisies dans +-- le compte. Le rendu serveur reste en francais ; ces colonnes ne servent +-- qu'a l'interface cliente. +-- 2. Favoris par utilisateur : `files.is_starred` etait un marqueur global, +-- partage entre tous les comptes ayant acces au fichier. Une table de +-- jointure remplace ce marqueur. Les etoiles deja posees sont reprises par +-- le proprietaire du fichier. +-- 3. Suivi de lecture du chat par utilisateur, pour les pastilles de messages +-- non lus dans la vue des dossiers. +-- 4. Suppression de `folders.description`, champ jamais affiche. + +ALTER TABLE users + ADD COLUMN theme VARCHAR(10) NOT NULL DEFAULT 'system' AFTER max_file_bytes, + ADD COLUMN language VARCHAR(5) NOT NULL DEFAULT 'fr' AFTER theme, + ADD CONSTRAINT chk_users_theme CHECK (theme IN ('system', 'light', 'dark')), + ADD CONSTRAINT chk_users_language CHECK (language IN ('fr', 'en')); + +CREATE TABLE user_file_stars ( + user_id CHAR(36) NOT NULL, + file_id CHAR(36) NOT NULL, + created_at DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3), + PRIMARY KEY (user_id, file_id), + KEY idx_user_file_stars_file (file_id), + CONSTRAINT fk_user_file_stars_user FOREIGN KEY (user_id) REFERENCES users (id) ON DELETE CASCADE, + CONSTRAINT fk_user_file_stars_file FOREIGN KEY (file_id) REFERENCES files (id) ON DELETE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; + +INSERT INTO user_file_stars (user_id, file_id) +SELECT owner_id, id FROM files WHERE is_starred = 1 AND owner_id IS NOT NULL; + +DROP INDEX idx_files_starred ON files; +ALTER TABLE files DROP COLUMN is_starred; + +CREATE TABLE chat_reads ( + folder_id CHAR(36) NOT NULL, + user_id CHAR(36) NOT NULL, + last_read_message_id BIGINT UNSIGNED NOT NULL DEFAULT 0, + updated_at DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3) ON UPDATE CURRENT_TIMESTAMP(3), + PRIMARY KEY (folder_id, user_id), + KEY idx_chat_reads_user (user_id), + CONSTRAINT fk_chat_reads_folder FOREIGN KEY (folder_id) REFERENCES folders (id) ON DELETE CASCADE, + CONSTRAINT fk_chat_reads_user FOREIGN KEY (user_id) REFERENCES users (id) ON DELETE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; + +ALTER TABLE folders DROP COLUMN description; diff --git a/backend/src/index.ts b/backend/src/index.ts index a66e6d7..c0e64cf 100644 --- a/backend/src/index.ts +++ b/backend/src/index.ts @@ -5,6 +5,7 @@ import { registerAccountRoutes } from "./routes/account.js"; import { registerAdminRoutes } from "./routes/admin.js"; import { registerAuthRoutes } from "./routes/auth.js"; import { registerChatRoutes } from "./routes/chat.js"; +import { registerDirectoryRoutes } from "./routes/directory.js"; import { registerFileRoutes } from "./routes/files.js"; import { registerFolderRoutes } from "./routes/folders.js"; import { registerMediaRoutes } from "./routes/media.js"; @@ -23,6 +24,7 @@ void startService({ registerAuthRoutes(app, db, config); registerAccountRoutes(app, db, config); registerChatRoutes(app, db, config); + registerDirectoryRoutes(app, db); registerFolderRoutes(app, db, config); registerFileRoutes(app, db, config); registerMediaRoutes(app, db); diff --git a/backend/src/routes/account.ts b/backend/src/routes/account.ts index 38b4890..83f6a7a 100644 --- a/backend/src/routes/account.ts +++ b/backend/src/routes/account.ts @@ -51,6 +51,11 @@ const profileInput = z.object({ last_name: z.string().trim().min(1).max(50), }); +const preferencesInput = z.object({ + theme: z.enum(["system", "light", "dark"]), + language: z.enum(["fr", "en"]), +}); + const forgotInput = z.object({ email: z.string().trim().email().max(255) }); const resetInput = z.object({ @@ -90,6 +95,27 @@ export const registerAccountRoutes = (app: App, db: Db, config: Config): void => return context.json({ ok: true, first_name: data.first_name, last_name: data.last_name }); }); + app.get("/api/cloud/account/preferences", requireAuth, async (context) => { + const user = currentUser(context); + const row = await db.one<{ theme: string; language: string }>( + "SELECT theme, language FROM users WHERE id = ? AND deleted_at IS NULL", + [user.id], + ); + if (!row) throw AppError.notFound("Compte introuvable."); + return context.json({ theme: row.theme, language: row.language }); + }); + + app.patch("/api/cloud/account/preferences", requireAuth, async (context) => { + const user = currentUser(context); + const data = parse(preferencesInput, await context.req.json().catch(() => null)); + await db.exec("UPDATE users SET theme = ?, language = ? WHERE id = ?", [ + data.theme, + data.language, + user.id, + ]); + return context.json({ theme: data.theme, language: data.language }); + }); + app.get("/api/cloud/account/sessions", requireAuth, async (context) => { const user = currentUser(context); const current = sha256(context.get("token") ?? ""); diff --git a/backend/src/routes/admin.ts b/backend/src/routes/admin.ts index 6524234..4ba56c7 100644 --- a/backend/src/routes/admin.ts +++ b/backend/src/routes/admin.ts @@ -433,21 +433,53 @@ export const registerAdminRoutes = (app: App, db: Db, config: Config): void => { return context.json({ ok: true }); }); + /** + * Facettes du journal : valeurs distinctes utilisees pour alimenter les + * listes deroulantes de filtre (actions et comptes ayant agi). Un compte + * supprime reste identifiable par son e-mail conserve dans le journal. + */ + app.get("/api/cloud/admin/audit/filters", requireAuth, async (context) => { + requireAdmin(context); + const actions = await db.query<{ action: string }>( + "SELECT DISTINCT action FROM audit_logs ORDER BY action ASC", + ); + const users = await db.query<{ user_id: string; user_email: string | null }>( + `SELECT user_id, MAX(user_email) AS user_email + FROM audit_logs + WHERE user_id IS NOT NULL + GROUP BY user_id + ORDER BY user_email ASC`, + ); + return context.json({ + actions: actions.map((row) => row.action), + users: users.map((row) => ({ id: row.user_id, email: row.user_email })), + }); + }); + app.get("/api/cloud/admin/audit", requireAuth, async (context) => { requireAdmin(context); const limit = Math.min(500, Math.max(1, Number(context.req.query("limit")) || 100)); const offset = Math.max(0, Number(context.req.query("offset")) || 0); - const action = context.req.query("action"); - const rows = action - ? await db.query( - `SELECT id, user_id, user_email, action, resource, resource_id, details, ip_address, created_at - FROM audit_logs WHERE action = ? ORDER BY created_at DESC LIMIT ${limit} OFFSET ${offset}`, - [action], - ) - : await db.query( - `SELECT id, user_id, user_email, action, resource, resource_id, details, ip_address, created_at - FROM audit_logs ORDER BY created_at DESC LIMIT ${limit} OFFSET ${offset}`, - ); + const action = context.req.query("action") || null; + const userId = context.req.query("userId") || null; + + const conditions: string[] = []; + const params: unknown[] = []; + if (action) { + conditions.push("action = ?"); + params.push(action); + } + if (userId) { + conditions.push("user_id = ?"); + params.push(userId); + } + const where = conditions.length > 0 ? ` WHERE ${conditions.join(" AND ")}` : ""; + + const rows = await db.query( + `SELECT id, user_id, user_email, action, resource, resource_id, details, ip_address, created_at + FROM audit_logs${where} ORDER BY created_at DESC LIMIT ${limit} OFFSET ${offset}`, + params, + ); return context.json({ entries: rows }); }); }; diff --git a/backend/src/routes/auth.ts b/backend/src/routes/auth.ts index b4dd8a9..1b40e3e 100644 --- a/backend/src/routes/auth.ts +++ b/backend/src/routes/auth.ts @@ -46,6 +46,8 @@ interface UserRow { max_file_bytes: number; must_change_password: number; is_active: number; + theme: string; + language: string; avatar_updated_at: Date | null; } @@ -60,6 +62,8 @@ const publicUser = (row: UserRow) => ({ used_bytes: row.used_bytes, max_file_bytes: row.max_file_bytes, must_change_password: row.must_change_password, + theme: row.theme, + language: row.language, has_avatar: row.avatar_updated_at !== null, avatar_updated_at: row.avatar_updated_at, }); @@ -68,6 +72,7 @@ const SELECT_USER = ` SELECT u.id, u.email, u.first_name, u.last_name, u.password_hash, r.slug AS role_slug, r.name AS role_name, u.quota_bytes, u.used_bytes, u.max_file_bytes, u.must_change_password, u.is_active, + u.theme, u.language, ua.updated_at AS avatar_updated_at FROM users u JOIN roles r ON r.id = u.role_id diff --git a/backend/src/routes/chat.ts b/backend/src/routes/chat.ts index e43dca8..04adf61 100644 --- a/backend/src/routes/chat.ts +++ b/backend/src/routes/chat.ts @@ -8,7 +8,7 @@ import { type Config, type Db, } from "../lib/index.js"; -import { audit, canManageFolder, canRead } from "../access.js"; +import { audit, canManageFolder, canRead, READ_SQL } from "../access.js"; /** * Chat attache a un dossier. Le salon ne se lit et ne s'ecrit qu'avec l'acces @@ -80,6 +80,51 @@ export const registerChatRoutes = (app: App, db: Db, config: Config): void => { return folder; }; + /** Reprise du curseur de lecture du salon pour la session courante. */ + const markRead = async (folderId: string, userId: string, messageId: number): Promise => { + if (messageId <= 0) return; + await db + .exec( + `INSERT INTO chat_reads (folder_id, user_id, last_read_message_id) + VALUES (?, ?, ?) + ON DUPLICATE KEY UPDATE + last_read_message_id = GREATEST(last_read_message_id, ?), + updated_at = UTC_TIMESTAMP(3)`, + [folderId, userId, messageId, messageId], + ) + .catch(() => undefined); + }; + + /** + * Pastilles de messages non lus : tous les salons accessibles a la session + * qui contiennent au moins un message qu'elle n'a pas encore lu. Les + * messages de la session ignores : il n'a rien de neuf a lire. + */ + app.get("/api/cloud/chat/unread", requireAuth, async (context) => { + const user = currentUser(context); + const rows = await db.query<{ folder_id: string; unread: number }>( + `SELECT f.id AS folder_id, COUNT(m.id) AS unread + FROM folders f + JOIN chat_messages m + ON m.folder_id = f.id + AND m.deleted_at IS NULL + AND m.user_id <> ? + WHERE f.deleted_at IS NULL + AND m.id > COALESCE ( + SELECT cr.last_read_message_id + FROM chat_reads cr + WHERE cr.folder_id = f.id AND cr.user_id = ? ) + AND ${READ_SQL} + GROUP BY f.id + HAVING unread > 0`, + [user.id, user.id, user.id, user.id], + ); + + const unread: Record = {}; + for (const row of rows) unread[row.folder_id] = Number(row.unread); + return context.json({ unread }); + }); + app.get("/api/cloud/folders/:folderId/chat/members", requireAuth, async (context) => { const user = currentUser(context); const folderId = context.req.param("folderId") ?? ""; @@ -158,6 +203,9 @@ export const registerChatRoutes = (app: App, db: Db, config: Config): void => { ) ).reverse(); + const newest = rows.reduce((max, row) => Math.max(max, row.id), 0); + await markRead(folderId, user.id, newest); + return context.json({ messages: rows.map(publicMessage) }); }); diff --git a/backend/src/routes/directory.ts b/backend/src/routes/directory.ts new file mode 100644 index 0000000..248fef2 --- /dev/null +++ b/backend/src/routes/directory.ts @@ -0,0 +1,47 @@ +import { + attachUser, + currentUser, + requireAuth, + type App, + type Db, +} from "../lib/index.js"; + +/** + * Repertoire des comptes actifs, reduit au strict necessaire pour choisir un + * destinataire lors d'un partage. La session courante est exclue : on ne se + * partage pas un dossier a soi-meme. Aucune donnee sensible n'est exposee. + */ +export const registerDirectoryRoutes = (app: App, db: Db): void => { + app.use("/api/cloud/directory", attachUser(db)); + + app.get("/api/cloud/directory", requireAuth, async (context) => { + const user = currentUser(context); + const rows = await db.query<{ + id: string; + first_name: string; + last_name: string; + email: string; + avatar_updated_at: Date | null; + }>( + `SELECT u.id, u.first_name, u.last_name, u.email, + ua.updated_at AS avatar_updated_at + FROM users u + LEFT JOIN user_avatars ua ON ua.user_id = u.id + WHERE u.deleted_at IS NULL AND u.is_active = 1 AND u.id <> ? + ORDER BY u.first_name ASC, u.last_name ASC + LIMIT 1000`, + [user.id], + ); + + return context.json({ + users: rows.map((row) => ({ + id: row.id, + first_name: row.first_name, + last_name: row.last_name, + email: row.email, + has_avatar: row.avatar_updated_at !== null, + avatar_updated_at: row.avatar_updated_at, + })), + }); + }); +}; diff --git a/backend/src/routes/files.ts b/backend/src/routes/files.ts index c031a7a..f12cf47 100644 --- a/backend/src/routes/files.ts +++ b/backend/src/routes/files.ts @@ -71,9 +71,11 @@ interface FileRow { updated_at: string; } -const SELECT_FILE = `SELECT id, folder_id, name, mime_type, size_bytes, checksum_sha256, - relative_path, owner_id, is_starred, download_count, created_at, updated_at - FROM files`; +const SELECT_FILE = `SELECT f.id, f.folder_id, f.name, f.mime_type, f.size_bytes, f.checksum_sha256, + f.relative_path, f.owner_id, + EXISTS (SELECT 1 FROM user_file_stars s WHERE s.file_id = f.id AND s.user_id = ?) AS is_starred, + f.download_count, f.created_at, f.updated_at + FROM files f`; const publicFile = (row: FileRow) => ({ id: row.id, @@ -371,7 +373,7 @@ export const registerFileRoutes = (app: App, db: Db, config: Config): void => { config.TRUST_PROXY, ); - const created = await db.required(`${SELECT_FILE} WHERE id = ?`, [id]); + const created = await db.required(`${SELECT_FILE} WHERE f.id = ?`, [user.id, id]); return context.json({ file: publicFile(created) }, 201); }, ); @@ -398,22 +400,22 @@ export const registerFileRoutes = (app: App, db: Db, config: Config): void => { const rows = await db.query( `${SELECT_FILE} - WHERE deleted_at IS NULL - AND (folder_id <=> ?) + WHERE f.deleted_at IS NULL + AND (f.folder_id <=> ?) AND ( ? = 1 - OR owner_id = ? - OR ( folder_id IS NOT NULL - AND EXISTS ( SELECT 1 FROM folders f - WHERE f.id = files.folder_id AND f.access_type = 'public' ) ) - OR ( folder_id IS NOT NULL + OR f.owner_id = ? + OR ( f.folder_id IS NOT NULL + AND EXISTS ( SELECT 1 FROM folders f2 + WHERE f2.id = f.folder_id AND f2.access_type = 'public' ) ) + OR ( f.folder_id IS NOT NULL AND EXISTS ( SELECT 1 FROM folder_permissions fp - WHERE fp.folder_id = files.folder_id + WHERE fp.folder_id = f.folder_id AND fp.user_id = ? AND fp.level IN ('read', 'write', 'admin') AND ( fp.expires_at IS NULL OR fp.expires_at > UTC_TIMESTAMP() ) ) ) ) - ORDER BY is_starred DESC, name`, - [folderId, 0, user.id, user.id], + ORDER BY is_starred DESC, f.name`, + [user.id, folderId, 0, user.id, user.id], ); return context.json({ folderId, files: rows.map(publicFile) }); @@ -429,12 +431,12 @@ export const registerFileRoutes = (app: App, db: Db, config: Config): void => { const user = currentUser(context); const rows = await db.query( `SELECT fi.id, fi.folder_id, fi.name, fi.mime_type, fi.size_bytes, fi.checksum_sha256, - fi.relative_path, fi.owner_id, fi.is_starred, fi.download_count, + fi.relative_path, fi.owner_id, 1 AS is_starred, fi.download_count, fi.created_at, fi.updated_at, fo.name AS folder_name FROM files fi + JOIN user_file_stars ufs ON ufs.file_id = fi.id AND ufs.user_id = ? LEFT JOIN folders fo ON fo.id = fi.folder_id WHERE fi.deleted_at IS NULL - AND fi.is_starred = 1 AND ( fi.owner_id = ? OR ( fi.folder_id IS NOT NULL AND EXISTS ( SELECT 1 FROM folders f @@ -446,8 +448,8 @@ export const registerFileRoutes = (app: App, db: Db, config: Config): void => { AND fp.level IN ('read', 'write', 'admin') AND ( fp.expires_at IS NULL OR fp.expires_at > UTC_TIMESTAMP() ) ) ) ) - ORDER BY fi.created_at DESC`, - [user.id, user.id], + ORDER BY ufs.created_at DESC`, + [user.id, user.id, user.id], ); return context.json({ @@ -460,7 +462,7 @@ export const registerFileRoutes = (app: App, db: Db, config: Config): void => { const rawId = context.req.param("id"); if (!uuid.safeParse(rawId).success) throw AppError.notFound("Fichier introuvable."); - const row = await db.one(`${SELECT_FILE} WHERE id = ? AND deleted_at IS NULL`, [rawId]); + const row = await db.one(`${SELECT_FILE} WHERE f.id = ? AND f.deleted_at IS NULL`, [user.id, rawId]); if (!row) throw AppError.notFound("Fichier introuvable."); const allowed = @@ -499,7 +501,7 @@ export const registerFileRoutes = (app: App, db: Db, config: Config): void => { const rawId = context.req.param("id"); if (!uuid.safeParse(rawId).success) throw AppError.notFound("Fichier introuvable."); - const row = await db.one(`${SELECT_FILE} WHERE id = ? AND deleted_at IS NULL`, [rawId]); + const row = await db.one(`${SELECT_FILE} WHERE f.id = ? AND f.deleted_at IS NULL`, [user.id, rawId]); if (!row) throw AppError.notFound("Fichier introuvable."); const allowed = @@ -528,7 +530,7 @@ export const registerFileRoutes = (app: App, db: Db, config: Config): void => { const rawId = context.req.param("id"); if (!uuid.safeParse(rawId).success) throw AppError.notFound("Image introuvable."); - const row = await db.one(`${SELECT_FILE} WHERE id = ? AND deleted_at IS NULL`, [rawId]); + const row = await db.one(`${SELECT_FILE} WHERE f.id = ? AND f.deleted_at IS NULL`, [user.id, rawId]); if (!row) throw AppError.notFound("Image introuvable."); const allowed = @@ -563,7 +565,7 @@ export const registerFileRoutes = (app: App, db: Db, config: Config): void => { const rawId = context.req.param("id"); if (!uuid.safeParse(rawId).success) throw AppError.notFound("Fichier introuvable."); - const row = await db.one(`${SELECT_FILE} WHERE id = ? AND deleted_at IS NULL`, [rawId]); + const row = await db.one(`${SELECT_FILE} WHERE f.id = ? AND f.deleted_at IS NULL`, [user.id, rawId]); if (!row) throw AppError.notFound("Fichier introuvable."); const owner = row.owner_id !== null && row.owner_id === user.id; @@ -587,7 +589,7 @@ export const registerFileRoutes = (app: App, db: Db, config: Config): void => { throw error; } - const updated = await db.required(`${SELECT_FILE} WHERE id = ?`, [row.id]); + const updated = await db.required(`${SELECT_FILE} WHERE f.id = ?`, [user.id, row.id]); await audit(db, context, user, "file.rename", "file", row.id, { name }, config.TRUST_PROXY); return context.json({ file: publicFile(updated) }); }); @@ -598,7 +600,7 @@ export const registerFileRoutes = (app: App, db: Db, config: Config): void => { const rawId = context.req.param("id"); if (!uuid.safeParse(rawId).success) throw AppError.notFound("Fichier introuvable."); - const row = await db.one(`${SELECT_FILE} WHERE id = ? AND deleted_at IS NULL`, [rawId]); + const row = await db.one(`${SELECT_FILE} WHERE f.id = ? AND f.deleted_at IS NULL`, [user.id, rawId]); if (!row) throw AppError.notFound("Fichier introuvable."); const owner = row.owner_id !== null && row.owner_id === user.id; @@ -623,7 +625,7 @@ export const registerFileRoutes = (app: App, db: Db, config: Config): void => { throw error; } - const updated = await db.required(`${SELECT_FILE} WHERE id = ?`, [row.id]); + const updated = await db.required(`${SELECT_FILE} WHERE f.id = ?`, [user.id, row.id]); await audit(db, context, user, "file.move", "file", row.id, { folderId: destination }, config.TRUST_PROXY); return context.json({ file: publicFile(updated) }); }); @@ -634,7 +636,7 @@ export const registerFileRoutes = (app: App, db: Db, config: Config): void => { const rawId = context.req.param("id"); if (!uuid.safeParse(rawId).success) throw AppError.notFound("Fichier introuvable."); - const row = await db.one(`${SELECT_FILE} WHERE id = ? AND deleted_at IS NULL`, [rawId]); + const row = await db.one(`${SELECT_FILE} WHERE f.id = ? AND f.deleted_at IS NULL`, [user.id, rawId]); if (!row) throw AppError.notFound("Fichier introuvable."); const allowed = @@ -642,8 +644,22 @@ export const registerFileRoutes = (app: App, db: Db, config: Config): void => { (row.folder_id !== null && (await canRead(db, user, row.folder_id))); if (!allowed) throw AppError.notFound("Fichier introuvable."); - await db.exec("UPDATE files SET is_starred = 1 - is_starred WHERE id = ?", [row.id]); - const updated = await db.required(`${SELECT_FILE} WHERE id = ?`, [row.id]); + const starred = await db.one( + "SELECT 1 AS mark FROM user_file_stars WHERE user_id = ? AND file_id = ?", + [user.id, row.id], + ); + if (starred) { + await db.exec( + "DELETE FROM user_file_stars WHERE user_id = ? AND file_id = ?", + [user.id, row.id], + ); + } else { + await db.exec( + "INSERT INTO user_file_stars (user_id, file_id) VALUES (?, ?)", + [user.id, row.id], + ); + } + const updated = await db.required(`${SELECT_FILE} WHERE f.id = ?`, [user.id, row.id]); return context.json({ file: publicFile(updated) }); }); @@ -652,7 +668,7 @@ export const registerFileRoutes = (app: App, db: Db, config: Config): void => { const rawId = context.req.param("id"); if (!uuid.safeParse(rawId).success) throw AppError.notFound("Fichier introuvable."); - const row = await db.one(`${SELECT_FILE} WHERE id = ? AND deleted_at IS NULL`, [rawId]); + const row = await db.one(`${SELECT_FILE} WHERE f.id = ? AND f.deleted_at IS NULL`, [user.id, rawId]); if (!row) throw AppError.notFound("Fichier introuvable."); const owner = row.owner_id !== null && row.owner_id === user.id; diff --git a/backend/src/routes/folders.ts b/backend/src/routes/folders.ts index f2885de..c3be016 100644 --- a/backend/src/routes/folders.ts +++ b/backend/src/routes/folders.ts @@ -22,12 +22,10 @@ const uuid = z const createFolder = z.object({ name: z.string().trim().min(1).max(255), parentId: uuid.nullish(), - description: z.string().trim().max(2000).nullish(), }); const updateFolder = z.object({ - name: z.string().trim().min(1).max(255).optional(), - description: z.string().trim().max(2000).nullish(), + name: z.string().trim().min(1).max(255), }); const moveFolder = z.object({ @@ -44,7 +42,6 @@ interface FolderRow { id: string; parent_id: string | null; name: string; - description: string | null; owner_id: string | null; access_type: string; is_system: number; @@ -53,7 +50,7 @@ interface FolderRow { updated_at: string; } -const SELECT_FOLDER = `SELECT f.id, f.parent_id, f.name, f.description, f.owner_id, +const SELECT_FOLDER = `SELECT f.id, f.parent_id, f.name, f.owner_id, f.access_type, f.is_system, f.storage_location_id, f.created_at, f.updated_at FROM folders f`; @@ -61,7 +58,6 @@ const publicFolder = (row: FolderRow) => ({ id: row.id, parent_id: row.parent_id, name: row.name, - description: row.description, owner_id: row.owner_id, access_type: row.access_type, is_system: row.is_system === 1, @@ -148,7 +144,7 @@ export const registerFolderRoutes = (app: App, db: Db, config: Config): void => requireRole("admin", "user"), async (context) => { const user = currentUser(context); - const { name: rawName, parentId, description } = parse( + const { name: rawName, parentId } = parse( createFolder, await context.req.json().catch(() => null), ); @@ -190,9 +186,9 @@ export const registerFolderRoutes = (app: App, db: Db, config: Config): void => const id = randomUUID(); try { await db.exec( - `INSERT INTO folders (id, storage_location_id, parent_id, name, description, owner_id, created_by) - VALUES (?, ?, ?, ?, ?, ?, ?)`, - [id, locationId, parentId ?? null, name, description ?? null, user.id, user.id], + `INSERT INTO folders (id, storage_location_id, parent_id, name, owner_id, created_by) + VALUES (?, ?, ?, ?, ?, ?)`, + [id, locationId, parentId ?? null, name, user.id, user.id], ); } catch (error) { if ((error as { errno?: number }).errno === 1062) { @@ -219,16 +215,10 @@ export const registerFolderRoutes = (app: App, db: Db, config: Config): void => if (!(await canManageFolder(db, user, id))) throw AppError.notFound("Dossier introuvable."); const data = parse(updateFolder, await context.req.json().catch(() => null)); - if (data.name === undefined && data.description === undefined) { - throw AppError.badRequest("Rien a modifier."); - } - const name = data.name === undefined ? existing.name : assertName(data.name); + const name = assertName(data.name); try { - await db.exec( - "UPDATE folders SET name = ?, description = ? WHERE id = ?", - [name, data.description === undefined ? existing.description : data.description, id], - ); + await db.exec("UPDATE folders SET name = ? WHERE id = ?", [name, id]); } catch (error) { if ((error as { errno?: number }).errno === 1062) { throw AppError.conflict("Ce nom existe deja ici."); diff --git a/backend/src/routes/media.ts b/backend/src/routes/media.ts index c5a8ddc..271bf1c 100644 --- a/backend/src/routes/media.ts +++ b/backend/src/routes/media.ts @@ -42,10 +42,11 @@ export const registerMediaRoutes = (app: App, db: Db): void => { has_thumbnail: number; }>( `SELECT fi.id, fi.folder_id, fi.name, fi.mime_type, fi.size_bytes, fi.owner_id, - fi.is_starred, mm.kind, mm.width, mm.height, fi.created_at, + (ufs.file_id IS NOT NULL) AS is_starred, mm.kind, mm.width, mm.height, fi.created_at, EXISTS ( SELECT 1 FROM file_variants fv WHERE fv.file_id = fi.id AND fv.purpose = 'thumbnail' ) AS has_thumbnail FROM files fi + LEFT JOIN user_file_stars ufs ON ufs.file_id = fi.id AND ufs.user_id = ? LEFT JOIN media_metadata mm ON mm.file_id = fi.id WHERE fi.deleted_at IS NULL AND ( ? = '' OR mm.kind = ? ) @@ -61,7 +62,7 @@ export const registerMediaRoutes = (app: App, db: Db): void => { AND ( fp.expires_at IS NULL OR fp.expires_at > UTC_TIMESTAMP() ) ) ) ) ORDER BY fi.created_at DESC LIMIT ${limit} OFFSET ${offset}`, - [kind, kind, 0, user.id, user.id], + [user.id, kind, kind, 0, user.id, user.id], ); return context.json({ diff --git a/backend/src/routes/search.ts b/backend/src/routes/search.ts index 6227151..aa95be9 100644 --- a/backend/src/routes/search.ts +++ b/backend/src/routes/search.ts @@ -32,13 +32,12 @@ export const registerSearchRoutes = (app: App, db: Db): void => { id: string; parent_id: string | null; name: string; - description: string | null; owner_id: string | null; access_type: string; created_at: string; updated_at: string; }>( - `SELECT f.id, f.parent_id, f.name, f.description, f.owner_id, + `SELECT f.id, f.parent_id, f.name, f.owner_id, f.access_type, f.created_at, f.updated_at FROM folders f WHERE f.deleted_at IS NULL @@ -66,8 +65,9 @@ export const registerSearchRoutes = (app: App, db: Db): void => { updated_at: string; }>( `SELECT fi.id, fi.folder_id, fi.name, fi.mime_type, fi.size_bytes, fi.owner_id, - fi.is_starred, fi.created_at, fi.updated_at + (ufs.file_id IS NOT NULL) AS is_starred, fi.created_at, fi.updated_at FROM files fi + LEFT JOIN user_file_stars ufs ON ufs.file_id = fi.id AND ufs.user_id = ? WHERE fi.deleted_at IS NULL AND fi.name LIKE ? AND ( ? = 1 @@ -81,7 +81,7 @@ export const registerSearchRoutes = (app: App, db: Db): void => { AND ( fp.expires_at IS NULL OR fp.expires_at > UTC_TIMESTAMP() ) ) ) ) ORDER BY fi.name LIMIT ${LIMIT}`, - [pattern, 0, user.id, user.id], + [user.id, pattern, 0, user.id, user.id], ); return context.json({ @@ -90,7 +90,6 @@ export const registerSearchRoutes = (app: App, db: Db): void => { id: row.id, parent_id: row.parent_id, name: row.name, - description: row.description, owner_id: row.owner_id, access_type: row.access_type, created_at: row.created_at, diff --git a/backend/src/routes/trash.ts b/backend/src/routes/trash.ts index ec793c7..08ca04b 100644 --- a/backend/src/routes/trash.ts +++ b/backend/src/routes/trash.ts @@ -119,7 +119,6 @@ interface TrashFolderRow { id: string; parent_id: string | null; name: string; - description: string | null; owner_id: string | null; access_type: string; created_at: string; @@ -143,7 +142,6 @@ const publicFolder = (row: TrashFolderRow) => ({ id: row.id, parent_id: row.parent_id, name: row.name, - description: row.description, owner_id: row.owner_id, access_type: row.access_type, created_at: row.created_at, @@ -161,7 +159,7 @@ export const registerTrashRoutes = (app: App, db: Db, config: Config): void => { // Seuls les elements dont le parent n'est pas lui-meme supprime figurent en // tete de corbeille : le reste suit la suppression du parent. const folders = await db.query( - `SELECT f.id, f.parent_id, f.name, f.description, f.owner_id, f.access_type, + `SELECT f.id, f.parent_id, f.name, f.owner_id, f.access_type, f.created_at, f.updated_at, f.deleted_at FROM folders f LEFT JOIN folders p ON p.id = f.parent_id -- 2.54.0 From 5e612653da6b1e4e89efcd25453bc4ee15f3d78b Mon Sep 17 00:00:00 2001 From: xEsiah Date: Sat, 17 Oct 2026 14:33:21 +0200 Subject: [PATCH 2/3] feat(frontend): i18n, theming and account/browser/admin UI updates - add French-keyed i18n with an English dictionary, plus theme and locale helpers, applied across all pages and components - account page: theme and language selectors and a two-column layout - browser: per-folder media type filters and unread chat badges - admin: audit log filtered by user and action through dropdowns - global API and type updates to match the new backend endpoints --- frontend/public/theme.js | 5 +- frontend/src/components/AppShell.tsx | 10 +- frontend/src/components/FolderChat.tsx | 65 ++-- frontend/src/components/IconAction.tsx | 12 +- frontend/src/components/MediaViewer.tsx | 73 ++--- frontend/src/components/confirm.tsx | 8 +- frontend/src/components/dialogs.tsx | 137 +++++---- frontend/src/components/feedback.tsx | 5 +- frontend/src/lib/api.ts | 48 ++- frontend/src/lib/i18n.tsx | 375 ++++++++++++++++++++++++ frontend/src/lib/locale.ts | 17 ++ frontend/src/lib/theme.tsx | 38 +++ frontend/src/main.tsx | 25 +- frontend/src/pages/Admin.tsx | 271 ++++++++++------- frontend/src/pages/Browser.tsx | 168 ++++++++--- frontend/src/pages/ChangePassword.tsx | 27 +- frontend/src/pages/ConfirmEmail.tsx | 16 +- frontend/src/pages/Favorites.tsx | 22 +- frontend/src/pages/ForgotPassword.tsx | 21 +- frontend/src/pages/Gallery.tsx | 20 +- frontend/src/pages/Login.tsx | 18 +- frontend/src/pages/Profile.tsx | 174 ++++++++--- frontend/src/pages/ResetPassword.tsx | 28 +- frontend/src/pages/Search.tsx | 30 +- frontend/src/pages/Trash.tsx | 58 ++-- 25 files changed, 1225 insertions(+), 446 deletions(-) create mode 100644 frontend/src/lib/i18n.tsx create mode 100644 frontend/src/lib/locale.ts create mode 100644 frontend/src/lib/theme.tsx diff --git a/frontend/public/theme.js b/frontend/public/theme.js index f2c3678..22f002e 100644 --- a/frontend/public/theme.js +++ b/frontend/public/theme.js @@ -1,9 +1,10 @@ (function () { try { var stored = localStorage.getItem("cohaise-theme"); + var theme = stored === "light" || stored === "dark" ? stored : "system"; var prefersDark = window.matchMedia("(prefers-color-scheme: dark)").matches; - var theme = stored || (prefersDark ? "dark" : "light"); - if (theme === "dark") document.documentElement.classList.add("dark"); + var dark = theme === "dark" || (theme === "system" && prefersDark); + document.documentElement.classList.toggle("dark", dark); } catch (error) { void error; } diff --git a/frontend/src/components/AppShell.tsx b/frontend/src/components/AppShell.tsx index 4c8d59c..0d7d90c 100644 --- a/frontend/src/components/AppShell.tsx +++ b/frontend/src/components/AppShell.tsx @@ -2,6 +2,7 @@ import { useState } from "react"; import { NavLink, Outlet } from "react-router-dom"; import { Button, cn } from "../ui/index.js"; import { useSession } from "../lib/session.js"; +import { useI18n } from "../lib/i18n.js"; import { Avatar } from "./Avatar.js"; import { ActivityIcon, @@ -50,6 +51,7 @@ const navClass = ({ isActive }: { isActive: boolean }) => export const AppShell = () => { const { user, logout } = useSession(); + const { t } = useI18n(); const [menuOpen, setMenuOpen] = useState(false); if (!user) return null; @@ -80,7 +82,7 @@ export const AppShell = () => { return ( setMenuOpen(false)}> - {item.label} + {t(item.label)} ); }; @@ -93,7 +95,7 @@ export const AppShell = () => { {isAdmin ? ( <>

- Administration + {t("Administration")}

{ADMIN_NAV.map(renderLink)} @@ -108,7 +110,7 @@ export const AppShell = () => { diff --git a/frontend/src/components/FolderChat.tsx b/frontend/src/components/FolderChat.tsx index fbb382a..22ae76d 100644 --- a/frontend/src/components/FolderChat.tsx +++ b/frontend/src/components/FolderChat.tsx @@ -9,6 +9,8 @@ import { } from "react"; import { Button, Spinner, cn } from "../ui/index.js"; import { ApiError, api, formatDate, type ChatMember, type ChatMessage } from "../lib/api.js"; +import { useI18n } from "../lib/i18n.js"; +import { getLocale } from "../lib/locale.js"; import { useSession } from "../lib/session.js"; import { useConfirm } from "./confirm.js"; import { Avatar } from "./Avatar.js"; @@ -22,10 +24,10 @@ const POLL_MEMBERS_MS = 30_000; const GROUP_WINDOW_MS = 5 * 60 * 1000; const timeOf = (value: string): string => - new Date(value).toLocaleTimeString("fr-FR", { hour: "2-digit", minute: "2-digit" }); + new Date(value).toLocaleTimeString(getLocale(), { hour: "2-digit", minute: "2-digit" }); const dayOf = (value: string): string => - new Date(value).toLocaleDateString("fr-FR", { + new Date(value).toLocaleDateString(getLocale(), { weekday: "long", day: "numeric", month: "long", @@ -34,8 +36,10 @@ const dayOf = (value: string): string => const isSameDay = (a: string, b: string): boolean => new Date(a).toDateString() === new Date(b).toDateString(); -const fullName = (member: { first_name: string | null; last_name: string | null }): string => - `${member.first_name ?? ""} ${member.last_name ?? ""}`.trim() || "Compte supprimé"; +const fullName = ( + member: { first_name: string | null; last_name: string | null }, + fallback: string, +): string => `${member.first_name ?? ""} ${member.last_name ?? ""}`.trim() || fallback; const MAX_ID = (list: ChatMessage[]): number => list.reduce((max, message) => Math.max(max, message.id), 0); @@ -52,6 +56,7 @@ export interface ChatFolder { * chaque requete, l'interface ne fait que l'afficher. */ export const FolderChat = ({ folder, onClose }: { folder: ChatFolder; onClose: () => void }) => { + const { t } = useI18n(); const { user } = useSession(); const confirm = useConfirm(); const folderId = folder.id; @@ -114,7 +119,7 @@ export const FolderChat = ({ folder, onClose }: { folder: ChatFolder; onClose: ( setError(null); } catch (caught) { if (!active) return; - setError(caught instanceof ApiError ? caught.message : "Chargement impossible."); + setError(caught instanceof ApiError ? caught.message : t("Chargement impossible.")); } finally { if (active) { setLoading(false); @@ -189,7 +194,7 @@ export const FolderChat = ({ folder, onClose }: { folder: ChatFolder; onClose: ( mergeMessages([message]); setDraft(""); } catch (caught) { - setError(caught instanceof ApiError ? caught.message : "Envoi impossible."); + setError(caught instanceof ApiError ? caught.message : t("Envoi impossible.")); } finally { setSending(false); } @@ -198,9 +203,9 @@ export const FolderChat = ({ folder, onClose }: { folder: ChatFolder; onClose: ( const remove = async (message: ChatMessage) => { if ( !(await confirm({ - title: "Supprimer le message", - message: "Ce message sera retiré du salon pour tout le monde.", - confirmLabel: "Supprimer", + title: t("Supprimer le message"), + message: t("Ce message sera retiré du salon pour tout le monde."), + confirmLabel: t("Supprimer"), tone: "danger", })) ) @@ -210,7 +215,7 @@ export const FolderChat = ({ folder, onClose }: { folder: ChatFolder; onClose: ( await api.chatDeleteMessage(folderId, message.id); setMessages((previous) => previous.filter((item) => item.id !== message.id)); } catch (caught) { - setError(caught instanceof ApiError ? caught.message : "Suppression impossible."); + setError(caught instanceof ApiError ? caught.message : t("Suppression impossible.")); } finally { setDeletingId(null); } @@ -249,11 +254,11 @@ export const FolderChat = ({ folder, onClose }: { folder: ChatFolder; onClose: ( "absolute inset-y-0 left-0 z-20 flex w-64 flex-col border-r border-border bg-surface transition-transform md:static md:z-auto md:translate-x-0", membersOpen ? "translate-x-0 shadow-lg md:shadow-none" : "-translate-x-full", )} - aria-label="Membres du dossier" + aria-label={t("Membres du dossier")} >
- Membres + {t("Membres")} {members.length}
@@ -270,15 +275,17 @@ export const FolderChat = ({ folder, onClose }: { folder: ChatFolder; onClose: ( />

- {fullName(member)} + {fullName(member, t("Compte supprimé"))} {member.is_self ? ( - (vous) + {t("(vous)")} ) : null}

{member.last_login_at - ? `Dernière connexion le ${formatDate(member.last_login_at)}` - : "Jamais connecté"} + ? t("Dernière connexion le {date}", { + date: formatDate(member.last_login_at), + }) + : t("Jamais connecté")}

{member.role_slug === "admin" ? Admin : null} @@ -300,7 +307,7 @@ export const FolderChat = ({ folder, onClose }: { folder: ChatFolder; onClose: (

- Discussion · {folder.name} + {t("Discussion · {name}", { name: folder.name })}

- Membres ayant accès à ce dossier + {t("Membres ayant accès à ce dossier")}

diff --git a/frontend/src/components/IconAction.tsx b/frontend/src/components/IconAction.tsx index 3045a2e..ffd1d79 100644 --- a/frontend/src/components/IconAction.tsx +++ b/frontend/src/components/IconAction.tsx @@ -7,12 +7,14 @@ export const IconAction = ({ onClick, isLoading = false, tone = "neutral", + badge = 0, }: { label: string; icon: ReactNode; onClick: () => void; isLoading?: boolean; tone?: "neutral" | "danger"; + badge?: number; }) => ( ); diff --git a/frontend/src/components/MediaViewer.tsx b/frontend/src/components/MediaViewer.tsx index 4b88b4f..2c34898 100644 --- a/frontend/src/components/MediaViewer.tsx +++ b/frontend/src/components/MediaViewer.tsx @@ -1,6 +1,7 @@ import { useEffect, useState } from "react"; import { cn } from "../ui/index.js"; import { api } from "../lib/api.js"; +import { useI18n } from "../lib/i18n.js"; import { ArrowLeftIcon, ArrowRightIcon, CloseIcon, DownloadIcon, FileIcon } from "./icons.js"; export interface MediaViewerItem { @@ -29,6 +30,7 @@ const actionClass = "inline-flex items-center gap-2 rounded-md border border-white/20 bg-white/10 px-3.5 py-2 text-sm font-medium text-white transition-colors hover:bg-white/20"; const TextViewer = ({ id }: { id: string }) => { + const { t } = useI18n(); const [text, setText] = useState(null); const [failed, setFailed] = useState(false); @@ -49,8 +51,8 @@ const TextViewer = ({ id }: { id: string }) => { }; }, [id]); - if (failed) return

Lecture impossible.

; - if (text === null) return

Chargement…

; + if (failed) return

{t("Lecture impossible.")}

; + if (text === null) return

{t("Chargement…")}

; return (
       {text}
@@ -66,33 +68,37 @@ const Panel = ({
   item: MediaViewerItem;
   message: string;
   openable: boolean;
-}) => (
-  
- -
-

{item.name}

-

{message}

-
- -); + ); +}; const Body = ({ item }: { item: MediaViewerItem }) => { + const { t } = useI18n(); const kind = kindOf(item.mime_type); if (kind === "image") { return ( @@ -124,11 +130,11 @@ const Body = ({ item }: { item: MediaViewerItem }) => { } if (kind === "text") return ; if (kind === "pdf") { - return ( - - ); + return ; } - return ; + return ( + + ); }; export const MediaViewer = ({ @@ -140,6 +146,7 @@ export const MediaViewer = ({ startIndex: number; onClose: () => void; }) => { + const { t } = useI18n(); const [index, setIndex] = useState(startIndex); const current = items[index]; @@ -169,11 +176,11 @@ export const MediaViewer = ({ href={api.downloadUrl(current.id)} download={current.name} className={controlClass} - aria-label="Télécharger" + aria-label={t("Télécharger")} > -
@@ -190,7 +197,7 @@ export const MediaViewer = ({ type="button" onClick={() => setIndex((value) => value - 1)} className={cn(controlClass, "absolute left-4 z-10")} - aria-label="Fichier précédent" + aria-label={t("Fichier précédent")} > @@ -203,7 +210,7 @@ export const MediaViewer = ({ type="button" onClick={() => setIndex((value) => value + 1)} className={cn(controlClass, "absolute right-4 z-10")} - aria-label="Fichier suivant" + aria-label={t("Fichier suivant")} > diff --git a/frontend/src/components/confirm.tsx b/frontend/src/components/confirm.tsx index b888262..ed8da6e 100644 --- a/frontend/src/components/confirm.tsx +++ b/frontend/src/components/confirm.tsx @@ -6,6 +6,7 @@ import { type ReactNode, } from "react"; import { Button } from "../ui/index.js"; +import { useI18n } from "../lib/i18n.js"; import { Modal } from "./feedback.js"; export interface ConfirmOptions { @@ -33,6 +34,7 @@ const ConfirmContext = createContext(null); * `useConfirm()` renvoie une promesse resolue a `true` (confirme) ou `false`. */ export const ConfirmProvider = ({ children }: { children: ReactNode }) => { + const { t } = useI18n(); const [pending, setPending] = useState(null); const confirm = useCallback( @@ -52,7 +54,7 @@ export const ConfirmProvider = ({ children }: { children: ReactNode }) => { {children} answer(false)} >
@@ -61,7 +63,7 @@ export const ConfirmProvider = ({ children }: { children: ReactNode }) => {

diff --git a/frontend/src/components/dialogs.tsx b/frontend/src/components/dialogs.tsx index 13bcca2..fb67baf 100644 --- a/frontend/src/components/dialogs.tsx +++ b/frontend/src/components/dialogs.tsx @@ -4,9 +4,11 @@ import { ApiError, api, formatDate, + type DirectoryUser, type Folder, type FolderPermission, } from "../lib/api.js"; +import { useI18n } from "../lib/i18n.js"; import { Alert, Modal } from "./feedback.js"; import { TrashIcon } from "./icons.js"; @@ -35,8 +37,8 @@ export const CreateFolderDialog = ({ onClose: () => void; onCreated: () => void; }) => { + const { t } = useI18n(); const [name, setName] = useState(""); - const [description, setDescription] = useState(""); const [error, setError] = useState(null); const [busy, setBusy] = useState(false); @@ -45,40 +47,34 @@ export const CreateFolderDialog = ({ setBusy(true); setError(null); try { - await api.createFolder(name, parentId, description.trim() || undefined); + await api.createFolder(name, parentId); onCreated(); } catch (caught) { - setError(messageOf(caught, "Création impossible.")); + setError(messageOf(caught, t("Création impossible."))); } finally { setBusy(false); } }; return ( - +
void submit(event)}> setName(event.target.value)} /> - setDescription(event.target.value)} - /> {error ? {error} : null}
@@ -95,6 +91,7 @@ export const RenameDialog = ({ onClose: () => void; onDone: () => void; }) => { + const { t } = useI18n(); const [name, setName] = useState(target.name); const [error, setError] = useState(null); const [busy, setBusy] = useState(false); @@ -104,21 +101,21 @@ export const RenameDialog = ({ setBusy(true); setError(null); try { - if (target.type === "folder") await api.updateFolder(target.id, { name }); + if (target.type === "folder") await api.updateFolder(target.id, name); else await api.renameFile(target.id, name); onDone(); } catch (caught) { - setError(messageOf(caught, "Renommage impossible.")); + setError(messageOf(caught, t("Renommage impossible."))); } finally { setBusy(false); } }; return ( - +
void submit(event)}> {error} : null}
@@ -167,6 +164,7 @@ export const MoveDialog = ({ onClose: () => void; onDone: () => void; }) => { + const { t } = useI18n(); const [entries, setEntries] = useState(null); const [destination, setDestination] = useState(""); const [error, setError] = useState(null); @@ -175,7 +173,7 @@ export const MoveDialog = ({ useEffect(() => { loadTree() .then(setEntries) - .catch((caught: unknown) => setError(messageOf(caught, "Chargement des dossiers impossible."))); + .catch((caught: unknown) => setError(messageOf(caught, t("Chargement des dossiers impossible.")))); }, []); const submit = async (event: FormEvent) => { @@ -188,24 +186,24 @@ export const MoveDialog = ({ else await api.moveFile(target.id, parentId); onDone(); } catch (caught) { - setError(messageOf(caught, "Déplacement impossible.")); + setError(messageOf(caught, t("Déplacement impossible."))); } finally { setBusy(false); } }; return ( - +
void submit(event)}>

- Destination de {target.name}. + {t("Destination de {name}.", { name: target.name })}

{entries === null && !error ? ( - Chargement des dossiers… + {t("Chargement des dossiers…")} ) : (