feat(chat,files): salon par dossier, favoris, cloisonnement des droits admin
PR — Ouverture automatique / create-pr (push) Successful in 2s
PR — Ouverture automatique / create-pr (push) Successful in 2s
- chat: salon attache a un dossier, membres = comptes ayant acces au dossier - securite: suppression du passage automatique admin sur fichiers/dossiers/ corbeille/recherche/galerie/chat ; l'admin n'accede qu'a ses partages - favoris: tri en tete dans l'explorateur + page dediee (GET /favorites) - ui: retrait des pastilles Systeme/Public sur la carte dossier - migration 007_chat : table chat_messages
This commit is contained in:
@@ -8,6 +8,7 @@ import { ResetPassword } from "./pages/ResetPassword.js";
|
||||
import { ConfirmEmail } from "./pages/ConfirmEmail.js";
|
||||
import { ChangePassword } from "./pages/ChangePassword.js";
|
||||
import { Browser } from "./pages/Browser.js";
|
||||
import { Favorites } from "./pages/Favorites.js";
|
||||
import { Search } from "./pages/Search.js";
|
||||
import { Gallery } from "./pages/Gallery.js";
|
||||
import { Trash } from "./pages/Trash.js";
|
||||
@@ -52,6 +53,7 @@ export const App = () => (
|
||||
<Route element={<RequireReady />}>
|
||||
<Route element={<AppShell />}>
|
||||
<Route path="/files" element={<Browser />} />
|
||||
<Route path="/favorites" element={<Favorites />} />
|
||||
<Route path="/search" element={<Search />} />
|
||||
<Route path="/gallery" element={<Gallery />} />
|
||||
<Route path="/trash" element={<Trash />} />
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import { useState } from "react";
|
||||
import { NavLink, Outlet } from "react-router-dom";
|
||||
import { Button, cn } from "../ui/index.js";
|
||||
import { api } from "../lib/api.js";
|
||||
import { useSession } from "../lib/session.js";
|
||||
import { Avatar } from "./Avatar.js";
|
||||
import {
|
||||
ActivityIcon,
|
||||
CloseIcon,
|
||||
@@ -14,6 +14,7 @@ import {
|
||||
SearchNavIcon,
|
||||
SettingsIcon,
|
||||
ShieldIcon,
|
||||
StarIcon,
|
||||
TrashIcon,
|
||||
} from "./icons.js";
|
||||
|
||||
@@ -25,6 +26,7 @@ interface NavItem {
|
||||
|
||||
const NAV: NavItem[] = [
|
||||
{ to: "/files", label: "Fichiers", icon: FolderIcon },
|
||||
{ to: "/favorites", label: "Favoris", icon: StarIcon },
|
||||
{ to: "/search", label: "Recherche", icon: SearchNavIcon },
|
||||
{ to: "/gallery", label: "Galerie", icon: ImageIcon },
|
||||
{ to: "/trash", label: "Corbeille", icon: TrashIcon },
|
||||
@@ -38,9 +40,6 @@ const ADMIN_NAV: NavItem[] = [
|
||||
|
||||
const ACCOUNT_NAV: NavItem = { to: "/profile", label: "Mon compte", icon: SettingsIcon };
|
||||
|
||||
const initials = (first: string, last: string): string =>
|
||||
`${first.charAt(0)}${last.charAt(0)}`.toUpperCase() || "?";
|
||||
|
||||
const navClass = ({ isActive }: { isActive: boolean }) =>
|
||||
cn(
|
||||
"flex items-center gap-3 rounded-md px-3 py-2 text-sm font-medium transition-colors",
|
||||
@@ -127,22 +126,13 @@ export const AppShell = () => {
|
||||
{user.role_name}
|
||||
</p>
|
||||
</div>
|
||||
<span
|
||||
className="relative flex h-9 w-9 shrink-0 items-center justify-center overflow-hidden rounded-full border border-border bg-surface text-xs font-semibold text-foreground"
|
||||
aria-hidden="true"
|
||||
>
|
||||
{initials(user.first_name, user.last_name)}
|
||||
{user.has_avatar ? (
|
||||
<img
|
||||
src={`${api.avatarUrl(user.id)}?v=${encodeURIComponent(user.avatar_updated_at ?? "")}`}
|
||||
alt=""
|
||||
className="absolute inset-0 h-full w-full object-cover"
|
||||
onError={(event) => {
|
||||
event.currentTarget.style.display = "none";
|
||||
}}
|
||||
/>
|
||||
) : null}
|
||||
</span>
|
||||
<Avatar
|
||||
userId={user.id}
|
||||
firstName={user.first_name}
|
||||
lastName={user.last_name}
|
||||
hasAvatar={user.has_avatar}
|
||||
avatarUpdatedAt={user.avatar_updated_at}
|
||||
/>
|
||||
<Button
|
||||
variant="secondary"
|
||||
size="sm"
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
import { api } from "../lib/api.js";
|
||||
import { cn } from "../ui/index.js";
|
||||
|
||||
const initials = (first: string, last: string): string =>
|
||||
`${first.charAt(0)}${last.charAt(0)}`.toUpperCase() || "?";
|
||||
|
||||
/**
|
||||
* Pastille d'identite : initiales sur fond neutre, remplacees par la photo de
|
||||
* profil quand elle existe. La version de la photo est passee en parametre
|
||||
* pour invalider le cache navigateur des qu'elle change.
|
||||
*/
|
||||
export const Avatar = ({
|
||||
userId,
|
||||
firstName,
|
||||
lastName,
|
||||
hasAvatar,
|
||||
avatarUpdatedAt,
|
||||
className,
|
||||
}: {
|
||||
userId: string;
|
||||
firstName: string;
|
||||
lastName: string;
|
||||
hasAvatar: boolean;
|
||||
avatarUpdatedAt: string | null;
|
||||
className?: string;
|
||||
}) => (
|
||||
<span
|
||||
className={cn(
|
||||
"relative flex h-9 w-9 shrink-0 items-center justify-center overflow-hidden rounded-full border border-border bg-surface text-xs font-semibold text-foreground",
|
||||
className,
|
||||
)}
|
||||
aria-hidden="true"
|
||||
>
|
||||
{initials(firstName, lastName)}
|
||||
{hasAvatar ? (
|
||||
<img
|
||||
src={`${api.avatarUrl(userId)}?v=${encodeURIComponent(avatarUpdatedAt ?? "")}`}
|
||||
alt=""
|
||||
className="absolute inset-0 h-full w-full object-cover"
|
||||
onError={(event) => {
|
||||
event.currentTarget.style.display = "none";
|
||||
}}
|
||||
/>
|
||||
) : null}
|
||||
</span>
|
||||
);
|
||||
@@ -0,0 +1,442 @@
|
||||
import {
|
||||
useCallback,
|
||||
useEffect,
|
||||
useMemo,
|
||||
useRef,
|
||||
useState,
|
||||
type FormEvent,
|
||||
type KeyboardEvent as ReactKeyboardEvent,
|
||||
} from "react";
|
||||
import { Button, Spinner, cn } from "../ui/index.js";
|
||||
import { ApiError, api, formatDate, type ChatMember, type ChatMessage } from "../lib/api.js";
|
||||
import { useSession } from "../lib/session.js";
|
||||
import { useConfirm } from "./confirm.js";
|
||||
import { Avatar } from "./Avatar.js";
|
||||
import { IconAction } from "./IconAction.js";
|
||||
import { Alert, Badge, EmptyState } from "./feedback.js";
|
||||
import { ChatIcon, CloseIcon, SendIcon, TrashIcon, UsersIcon } from "./icons.js";
|
||||
|
||||
const MAX_LENGTH = 2000;
|
||||
const POLL_MESSAGES_MS = 4000;
|
||||
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" });
|
||||
|
||||
const dayOf = (value: string): string =>
|
||||
new Date(value).toLocaleDateString("fr-FR", {
|
||||
weekday: "long",
|
||||
day: "numeric",
|
||||
month: "long",
|
||||
});
|
||||
|
||||
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 MAX_ID = (list: ChatMessage[]): number =>
|
||||
list.reduce((max, message) => Math.max(max, message.id), 0);
|
||||
|
||||
export interface ChatFolder {
|
||||
id: string;
|
||||
name: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Salon de discussion d'un dossier, ouvert en plein ecran par-dessus la vue
|
||||
* des fichiers. Les membres sont les comptes ayant acces au dossier (le role
|
||||
* admin n'ouvre aucun acces supplementaire) ; le serveur reevalue cet acces a
|
||||
* chaque requete, l'interface ne fait que l'afficher.
|
||||
*/
|
||||
export const FolderChat = ({ folder, onClose }: { folder: ChatFolder; onClose: () => void }) => {
|
||||
const { user } = useSession();
|
||||
const confirm = useConfirm();
|
||||
const folderId = folder.id;
|
||||
|
||||
const [members, setMembers] = useState<ChatMember[]>([]);
|
||||
const [messages, setMessages] = useState<ChatMessage[]>([]);
|
||||
const [loading, setLoading] = useState(true);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
const [draft, setDraft] = useState("");
|
||||
const [sending, setSending] = useState(false);
|
||||
const [deletingId, setDeletingId] = useState<number | null>(null);
|
||||
const [membersOpen, setMembersOpen] = useState(false);
|
||||
|
||||
const scrollRef = useRef<HTMLDivElement | null>(null);
|
||||
const lastIdRef = useRef(0);
|
||||
// Tant que l'utilisateur reste au bas de la conversation, chaque nouveau
|
||||
// message le ramene en bas ; s'il remonte lire l'historique, on ne le force
|
||||
// pas a redescendre.
|
||||
const stickToBottomRef = useRef(true);
|
||||
|
||||
const scrollToBottom = useCallback(() => {
|
||||
const node = scrollRef.current;
|
||||
if (node) node.scrollTop = node.scrollHeight;
|
||||
}, []);
|
||||
|
||||
const mergeMessages = useCallback(
|
||||
(incoming: ChatMessage[]) => {
|
||||
if (incoming.length === 0) return;
|
||||
setMessages((previous) => {
|
||||
const known = new Set(previous.map((message) => message.id));
|
||||
const fresh = incoming.filter((message) => !known.has(message.id));
|
||||
return fresh.length > 0 ? [...previous, ...fresh] : previous;
|
||||
});
|
||||
lastIdRef.current = Math.max(lastIdRef.current, MAX_ID(incoming));
|
||||
if (stickToBottomRef.current) queueMicrotask(scrollToBottom);
|
||||
},
|
||||
[scrollToBottom],
|
||||
);
|
||||
|
||||
const loadMembers = useCallback(async () => {
|
||||
const { members: list } = await api.chatMembers(folderId);
|
||||
setMembers(list);
|
||||
}, [folderId]);
|
||||
|
||||
useEffect(() => {
|
||||
let active = true;
|
||||
setLoading(true);
|
||||
setMessages([]);
|
||||
lastIdRef.current = 0;
|
||||
void (async () => {
|
||||
try {
|
||||
const [memberResult, messageResult] = await Promise.all([
|
||||
api.chatMembers(folderId),
|
||||
api.chatMessages(folderId, 0, 50),
|
||||
]);
|
||||
if (!active) return;
|
||||
setMembers(memberResult.members);
|
||||
setMessages(messageResult.messages);
|
||||
lastIdRef.current = MAX_ID(messageResult.messages);
|
||||
setError(null);
|
||||
} catch (caught) {
|
||||
if (!active) return;
|
||||
setError(caught instanceof ApiError ? caught.message : "Chargement impossible.");
|
||||
} finally {
|
||||
if (active) {
|
||||
setLoading(false);
|
||||
queueMicrotask(scrollToBottom);
|
||||
}
|
||||
}
|
||||
})();
|
||||
return () => {
|
||||
active = false;
|
||||
};
|
||||
}, [folderId, scrollToBottom]);
|
||||
|
||||
// Synchronisation incrementale : rien n'est charge tant que l'onglet est en
|
||||
// arriere-plan, la reprise se fait au retour de visibilite.
|
||||
useEffect(() => {
|
||||
const poll = async () => {
|
||||
if (document.hidden) return;
|
||||
try {
|
||||
const { messages: fresh } = await api.chatMessages(folderId, lastIdRef.current, 100);
|
||||
mergeMessages(fresh);
|
||||
} catch {
|
||||
/* le prochain cycle retentera */
|
||||
}
|
||||
};
|
||||
const onVisible = () => {
|
||||
if (!document.hidden) void poll();
|
||||
};
|
||||
const timer = window.setInterval(() => void poll(), POLL_MESSAGES_MS);
|
||||
document.addEventListener("visibilitychange", onVisible);
|
||||
return () => {
|
||||
window.clearInterval(timer);
|
||||
document.removeEventListener("visibilitychange", onVisible);
|
||||
};
|
||||
}, [folderId, mergeMessages]);
|
||||
|
||||
useEffect(() => {
|
||||
const timer = window.setInterval(() => {
|
||||
if (!document.hidden) void loadMembers().catch(() => undefined);
|
||||
}, POLL_MEMBERS_MS);
|
||||
return () => window.clearInterval(timer);
|
||||
}, [loadMembers]);
|
||||
|
||||
// Fermeture au clavier et blocage du defilement de la page sous l'overlay.
|
||||
useEffect(() => {
|
||||
const onKeyDown = (event: KeyboardEvent) => {
|
||||
if (event.key === "Escape") onClose();
|
||||
};
|
||||
window.addEventListener("keydown", onKeyDown);
|
||||
const previousOverflow = document.body.style.overflow;
|
||||
document.body.style.overflow = "hidden";
|
||||
return () => {
|
||||
window.removeEventListener("keydown", onKeyDown);
|
||||
document.body.style.overflow = previousOverflow;
|
||||
};
|
||||
}, [onClose]);
|
||||
|
||||
const onScroll = () => {
|
||||
const node = scrollRef.current;
|
||||
if (!node) return;
|
||||
stickToBottomRef.current = node.scrollHeight - node.scrollTop - node.clientHeight < 80;
|
||||
};
|
||||
|
||||
const send = async (event: FormEvent) => {
|
||||
event.preventDefault();
|
||||
const body = draft.trim();
|
||||
if (!body || sending) return;
|
||||
setSending(true);
|
||||
setError(null);
|
||||
try {
|
||||
const { message } = await api.chatSend(folderId, body);
|
||||
stickToBottomRef.current = true;
|
||||
mergeMessages([message]);
|
||||
setDraft("");
|
||||
} catch (caught) {
|
||||
setError(caught instanceof ApiError ? caught.message : "Envoi impossible.");
|
||||
} finally {
|
||||
setSending(false);
|
||||
}
|
||||
};
|
||||
|
||||
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",
|
||||
tone: "danger",
|
||||
}))
|
||||
)
|
||||
return;
|
||||
setDeletingId(message.id);
|
||||
try {
|
||||
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.");
|
||||
} finally {
|
||||
setDeletingId(null);
|
||||
}
|
||||
};
|
||||
|
||||
const onComposerKeyDown = (event: ReactKeyboardEvent<HTMLTextAreaElement>) => {
|
||||
if (event.key === "Enter" && !event.shiftKey) {
|
||||
event.preventDefault();
|
||||
event.currentTarget.form?.requestSubmit();
|
||||
}
|
||||
};
|
||||
|
||||
const rendered = useMemo(
|
||||
() =>
|
||||
messages.map((message, index) => {
|
||||
const previous = index > 0 ? messages[index - 1] : null;
|
||||
const newDay = !previous || !isSameDay(previous.created_at, message.created_at);
|
||||
const continuation =
|
||||
!newDay &&
|
||||
previous !== null &&
|
||||
previous.user_id === message.user_id &&
|
||||
new Date(message.created_at).getTime() - new Date(previous.created_at).getTime() <
|
||||
GROUP_WINDOW_MS;
|
||||
const own = message.user_id === user?.id;
|
||||
const canDelete = own;
|
||||
return { message, newDay, continuation, own, canDelete };
|
||||
}),
|
||||
[messages, user?.id],
|
||||
);
|
||||
|
||||
return (
|
||||
<div className="fixed inset-0 z-40 flex flex-col bg-background">
|
||||
<div className="relative flex h-full min-h-0">
|
||||
<aside
|
||||
className={cn(
|
||||
"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"
|
||||
>
|
||||
<div className="flex shrink-0 items-center justify-between gap-2 border-b border-border px-4 py-3">
|
||||
<span className="font-display text-xs font-semibold uppercase tracking-label text-foreground">
|
||||
Membres
|
||||
</span>
|
||||
<span className="text-xs text-subtle-foreground">{members.length}</span>
|
||||
</div>
|
||||
<ul className="min-h-0 flex-1 overflow-y-auto p-2">
|
||||
{members.map((member) => (
|
||||
<li key={member.id} className="flex items-center gap-3 rounded-md px-2 py-2">
|
||||
<Avatar
|
||||
userId={member.id}
|
||||
firstName={member.first_name}
|
||||
lastName={member.last_name}
|
||||
hasAvatar={member.has_avatar}
|
||||
avatarUpdatedAt={member.avatar_updated_at}
|
||||
className="h-8 w-8"
|
||||
/>
|
||||
<div className="min-w-0 flex-1">
|
||||
<p className="flex items-center gap-1.5 truncate text-xs font-medium text-foreground">
|
||||
{fullName(member)}
|
||||
{member.is_self ? (
|
||||
<span className="text-subtle-foreground">(vous)</span>
|
||||
) : null}
|
||||
</p>
|
||||
<p className="truncate text-[0.6875rem] text-subtle-foreground">
|
||||
{member.last_login_at
|
||||
? `Dernière connexion le ${formatDate(member.last_login_at)}`
|
||||
: "Jamais connecté"}
|
||||
</p>
|
||||
</div>
|
||||
{member.role_slug === "admin" ? <Badge tone="accent">Admin</Badge> : null}
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
</aside>
|
||||
|
||||
{membersOpen ? (
|
||||
<div
|
||||
className="absolute inset-0 z-10 bg-black/30 md:hidden"
|
||||
onClick={() => setMembersOpen(false)}
|
||||
aria-hidden="true"
|
||||
/>
|
||||
) : null}
|
||||
|
||||
<section className="flex min-w-0 flex-1 flex-col">
|
||||
<div className="flex shrink-0 items-center gap-3 border-b border-border bg-background px-4 py-3">
|
||||
<button
|
||||
type="button"
|
||||
className="text-muted-foreground md:hidden"
|
||||
aria-label={membersOpen ? "Masquer les membres" : "Afficher les membres"}
|
||||
aria-expanded={membersOpen}
|
||||
onClick={() => setMembersOpen((value) => !value)}
|
||||
>
|
||||
<UsersIcon className="h-5 w-5" />
|
||||
</button>
|
||||
<div className="min-w-0 flex-1">
|
||||
<h1 className="truncate font-display text-sm font-semibold uppercase tracking-label text-foreground">
|
||||
Discussion · {folder.name}
|
||||
</h1>
|
||||
<p className="text-[0.6875rem] text-subtle-foreground">
|
||||
Membres ayant accès à ce dossier
|
||||
</p>
|
||||
</div>
|
||||
<button
|
||||
type="button"
|
||||
onClick={onClose}
|
||||
aria-label="Fermer la discussion"
|
||||
className="rounded-sm text-muted-foreground transition-colors hover:text-foreground focus-visible:ring-ring focus-visible:ring-2 focus-visible:outline-none"
|
||||
>
|
||||
<CloseIcon className="h-5 w-5" />
|
||||
</button>
|
||||
</div>
|
||||
|
||||
{error ? (
|
||||
<div className="shrink-0 px-4 pt-3">
|
||||
<Alert>{error}</Alert>
|
||||
</div>
|
||||
) : null}
|
||||
|
||||
<div
|
||||
ref={scrollRef}
|
||||
onScroll={onScroll}
|
||||
className="min-h-0 flex-1 overflow-y-auto px-4 py-4"
|
||||
>
|
||||
{loading ? (
|
||||
<div className="flex justify-center py-16">
|
||||
<Spinner size="md" />
|
||||
</div>
|
||||
) : messages.length === 0 ? (
|
||||
<EmptyState
|
||||
icon={<ChatIcon className="h-8 w-8" />}
|
||||
title="Aucun message"
|
||||
description="Lancez la discussion : les membres du dossier verront votre message."
|
||||
/>
|
||||
) : (
|
||||
<ol className="flex flex-col gap-1">
|
||||
{rendered.map(({ message, newDay, continuation, own, canDelete }) => (
|
||||
<li key={message.id}>
|
||||
{newDay ? (
|
||||
<div className="my-3 flex items-center gap-3" role="separator">
|
||||
<span className="h-px flex-1 bg-border" />
|
||||
<span className="font-display text-[0.625rem] font-semibold uppercase tracking-label text-subtle-foreground">
|
||||
{dayOf(message.created_at)}
|
||||
</span>
|
||||
<span className="h-px flex-1 bg-border" />
|
||||
</div>
|
||||
) : null}
|
||||
<div
|
||||
className={cn(
|
||||
"group flex items-start gap-3 rounded-md px-2 py-1.5 hover:bg-surface-hover",
|
||||
continuation && "mt-0",
|
||||
)}
|
||||
>
|
||||
{continuation ? (
|
||||
<span className="w-9 shrink-0" aria-hidden="true" />
|
||||
) : (
|
||||
<Avatar
|
||||
userId={message.user_id ?? message.first_name ?? "unknown"}
|
||||
firstName={message.first_name ?? "?"}
|
||||
lastName={message.last_name ?? ""}
|
||||
hasAvatar={message.has_avatar}
|
||||
avatarUpdatedAt={message.avatar_updated_at}
|
||||
className="h-9 w-9"
|
||||
/>
|
||||
)}
|
||||
<div className="min-w-0 flex-1">
|
||||
{continuation ? null : (
|
||||
<p className="flex items-center gap-2 text-xs">
|
||||
<span
|
||||
className={cn("font-medium", own ? "text-accent" : "text-foreground")}
|
||||
>
|
||||
{fullName(message)}
|
||||
</span>
|
||||
<span className="text-[0.6875rem] text-subtle-foreground">
|
||||
{timeOf(message.created_at)}
|
||||
</span>
|
||||
</p>
|
||||
)}
|
||||
<p className="whitespace-pre-wrap break-words text-sm leading-relaxed text-foreground">
|
||||
{message.body}
|
||||
</p>
|
||||
</div>
|
||||
{canDelete ? (
|
||||
<span className="opacity-0 transition-opacity group-hover:opacity-100 focus-within:opacity-100">
|
||||
<IconAction
|
||||
label="Supprimer le message"
|
||||
tone="danger"
|
||||
isLoading={deletingId === message.id}
|
||||
icon={<TrashIcon className="h-3.5 w-3.5" />}
|
||||
onClick={() => void remove(message)}
|
||||
/>
|
||||
</span>
|
||||
) : null}
|
||||
</div>
|
||||
</li>
|
||||
))}
|
||||
</ol>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<form
|
||||
onSubmit={(event) => void send(event)}
|
||||
className="flex shrink-0 items-end gap-2 border-t border-border bg-background px-4 py-3"
|
||||
>
|
||||
<textarea
|
||||
value={draft}
|
||||
onChange={(event) => setDraft(event.target.value.slice(0, MAX_LENGTH))}
|
||||
onKeyDown={onComposerKeyDown}
|
||||
rows={1}
|
||||
maxLength={MAX_LENGTH}
|
||||
placeholder="Écrire un message… (Entrée pour envoyer, Maj+Entrée pour retour à la ligne)"
|
||||
aria-label="Votre message"
|
||||
className="max-h-40 min-h-[2.5rem] flex-1 resize-y rounded-sm border border-border-control bg-surface px-3 py-2 text-sm text-foreground placeholder:text-subtle-foreground focus-visible:border-border-strong focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background focus-visible:outline-none"
|
||||
/>
|
||||
<Button
|
||||
type="submit"
|
||||
size="md"
|
||||
isLoading={sending}
|
||||
disabled={draft.trim().length === 0}
|
||||
iconLeading={<SendIcon className="h-4 w-4" />}
|
||||
>
|
||||
<span className="hidden sm:inline">Envoyer</span>
|
||||
</Button>
|
||||
</form>
|
||||
</section>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
@@ -191,3 +191,17 @@ export const MoveIcon = (props: IconProps) => (
|
||||
<path d="m9 7 3-3 3 3M9 17l3 3 3-3M7 9l-3 3 3 3M17 9l3 3-3 3" />
|
||||
</svg>
|
||||
);
|
||||
|
||||
export const ChatIcon = (props: IconProps) => (
|
||||
<svg {...base(props)}>
|
||||
<path d="M20 15.5a1.5 1.5 0 0 1-1.5 1.5H8l-4 3.5V6.5A1.5 1.5 0 0 1 5.5 5h13A1.5 1.5 0 0 1 20 6.5Z" />
|
||||
<path d="M8 9.5h8M8 13h5" />
|
||||
</svg>
|
||||
);
|
||||
|
||||
export const SendIcon = (props: IconProps) => (
|
||||
<svg {...base(props)}>
|
||||
<path d="M4.5 12 20 4.5 15 20l-3.5-6.5L4.5 12Z" />
|
||||
<path d="m11.5 13.5 4-4" />
|
||||
</svg>
|
||||
);
|
||||
|
||||
@@ -39,6 +39,10 @@ export interface UploadedFile {
|
||||
updated_at: string;
|
||||
}
|
||||
|
||||
export interface FavoriteFile extends UploadedFile {
|
||||
folder_name: string | null;
|
||||
}
|
||||
|
||||
export interface FolderPermission {
|
||||
user_id: string;
|
||||
email: string;
|
||||
@@ -145,6 +149,28 @@ export interface AuditEntry {
|
||||
created_at: string;
|
||||
}
|
||||
|
||||
export interface ChatMember {
|
||||
id: string;
|
||||
first_name: string;
|
||||
last_name: string;
|
||||
role_slug: string;
|
||||
has_avatar: boolean;
|
||||
avatar_updated_at: string | null;
|
||||
last_login_at: string | null;
|
||||
is_self: boolean;
|
||||
}
|
||||
|
||||
export interface ChatMessage {
|
||||
id: number;
|
||||
user_id: string | null;
|
||||
first_name: string | null;
|
||||
last_name: string | null;
|
||||
body: string;
|
||||
created_at: string;
|
||||
has_avatar: boolean;
|
||||
avatar_updated_at: string | null;
|
||||
}
|
||||
|
||||
export class ApiError extends Error {
|
||||
readonly status: number;
|
||||
|
||||
@@ -291,6 +317,7 @@ export const api = {
|
||||
post<{ file: UploadedFile }>(`/files/${encodeURIComponent(id)}/move`, { folderId }),
|
||||
starFile: (id: string) =>
|
||||
request<{ file: UploadedFile }>(`/files/${encodeURIComponent(id)}/star`, { method: "PUT" }),
|
||||
favorites: () => request<{ files: FavoriteFile[] }>("/favorites"),
|
||||
deleteFile: (id: string) => del<{ ok: boolean }>(`/files/${encodeURIComponent(id)}`),
|
||||
downloadUrl: (id: string) => `${BASE}/files/${encodeURIComponent(id)}/download`,
|
||||
thumbnailUrl: (id: string) => `${BASE}/files/${encodeURIComponent(id)}/thumbnail`,
|
||||
@@ -314,6 +341,18 @@ export const api = {
|
||||
`/media${query({ kind, limit, offset })}`,
|
||||
),
|
||||
|
||||
// --- Chat d'un dossier ------------------------------------------------
|
||||
chatMembers: (folderId: string) =>
|
||||
request<{ members: ChatMember[] }>(`/folders/${encodeURIComponent(folderId)}/chat/members`),
|
||||
chatMessages: (folderId: string, after = 0, limit = 50) =>
|
||||
request<{ messages: ChatMessage[] }>(
|
||||
`/folders/${encodeURIComponent(folderId)}/chat/messages${query({ after, limit })}`,
|
||||
),
|
||||
chatSend: (folderId: string, body: string) =>
|
||||
post<{ message: ChatMessage }>(`/folders/${encodeURIComponent(folderId)}/chat/messages`, { body }),
|
||||
chatDeleteMessage: (folderId: string, id: number) =>
|
||||
del<{ ok: boolean }>(`/folders/${encodeURIComponent(folderId)}/chat/messages/${id}`),
|
||||
|
||||
// --- Administration ----------------------------------------------------
|
||||
adminStats: () => request<AdminStats>("/admin/stats"),
|
||||
adminUsers: (q?: string) =>
|
||||
|
||||
@@ -8,11 +8,12 @@ import {
|
||||
type UploadedFile,
|
||||
} from "../lib/api.js";
|
||||
import { useSession } from "../lib/session.js";
|
||||
import { Alert, Badge, EmptyState, PageHeader } from "../components/feedback.js";
|
||||
import { Alert, EmptyState, PageHeader } from "../components/feedback.js";
|
||||
import { useConfirm } from "../components/confirm.js";
|
||||
import { MediaViewer } from "../components/MediaViewer.js";
|
||||
import { MediaThumb } from "../components/MediaThumb.js";
|
||||
import { IconAction } from "../components/IconAction.js";
|
||||
import { FolderChat, type ChatFolder } from "../components/FolderChat.js";
|
||||
import {
|
||||
CreateFolderDialog,
|
||||
MoveDialog,
|
||||
@@ -21,6 +22,7 @@ import {
|
||||
} from "../components/dialogs.js";
|
||||
import {
|
||||
ArrowLeftIcon,
|
||||
ChatIcon,
|
||||
DownloadIcon,
|
||||
FolderIcon,
|
||||
MoveIcon,
|
||||
@@ -58,6 +60,7 @@ export const Browser = () => {
|
||||
const [removing, setRemoving] = useState<string | null>(null);
|
||||
const [dialog, setDialog] = useState<Dialog>(null);
|
||||
const [viewer, setViewer] = useState<number | null>(null);
|
||||
const [chat, setChat] = useState<ChatFolder | null>(null);
|
||||
const fileInputRef = useRef<HTMLInputElement>(null);
|
||||
|
||||
const current = path[path.length - 1] ?? { id: null, name: "Racine" };
|
||||
@@ -203,6 +206,17 @@ export const Browser = () => {
|
||||
))}
|
||||
</ol>
|
||||
</nav>
|
||||
|
||||
{current.id ? (
|
||||
<Button
|
||||
variant="secondary"
|
||||
size="sm"
|
||||
iconLeading={<ChatIcon className="h-3.5 w-3.5" />}
|
||||
onClick={() => setChat({ id: current.id as string, name: current.name })}
|
||||
>
|
||||
Discussion
|
||||
</Button>
|
||||
) : null}
|
||||
</div>
|
||||
}
|
||||
/>
|
||||
@@ -292,17 +306,16 @@ export const Browser = () => {
|
||||
<span className="block truncate text-sm font-medium text-foreground">
|
||||
{folder.name}
|
||||
</span>
|
||||
<span className="mt-0.5 flex items-center gap-2">
|
||||
{folder.is_system ? <Badge>Système</Badge> : null}
|
||||
{folder.access_type === "public" ? (
|
||||
<Badge tone="accent">Public</Badge>
|
||||
) : null}
|
||||
<span className="text-[0.6875rem] text-subtle-foreground">
|
||||
{new Date(folder.created_at).toLocaleDateString("fr-FR")}
|
||||
</span>
|
||||
<span className="mt-0.5 block text-[0.6875rem] text-subtle-foreground">
|
||||
{new Date(folder.created_at).toLocaleDateString("fr-FR")}
|
||||
</span>
|
||||
</span>
|
||||
</button>
|
||||
<IconAction
|
||||
label={`Discussion ${folder.name}`}
|
||||
icon={<ChatIcon className="h-4 w-4" />}
|
||||
onClick={() => setChat({ id: folder.id, name: folder.name })}
|
||||
/>
|
||||
{canWrite ? (
|
||||
<div className="flex shrink-0 items-center gap-0.5">
|
||||
<IconAction
|
||||
@@ -475,6 +488,10 @@ export const Browser = () => {
|
||||
onClose={() => setViewer(null)}
|
||||
/>
|
||||
) : null}
|
||||
|
||||
{chat ? (
|
||||
<FolderChat key={chat.id} folder={chat} onClose={() => setChat(null)} />
|
||||
) : null}
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
@@ -0,0 +1,116 @@
|
||||
import { useEffect, useState } from "react";
|
||||
import { Spinner } from "../ui/index.js";
|
||||
import { ApiError, api, formatBytes, type FavoriteFile } from "../lib/api.js";
|
||||
import { Alert, EmptyState, PageHeader } from "../components/feedback.js";
|
||||
import { MediaViewer } from "../components/MediaViewer.js";
|
||||
import { MediaThumb } from "../components/MediaThumb.js";
|
||||
import { IconAction } from "../components/IconAction.js";
|
||||
import { DownloadIcon, FolderIcon, StarIcon } from "../components/icons.js";
|
||||
|
||||
export const Favorites = () => {
|
||||
const [files, setFiles] = useState<FavoriteFile[]>([]);
|
||||
const [loading, setLoading] = useState(true);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
const [viewer, setViewer] = useState<number | null>(null);
|
||||
|
||||
useEffect(() => {
|
||||
setLoading(true);
|
||||
void api
|
||||
.favorites()
|
||||
.then(({ files: list }) => {
|
||||
setFiles(list);
|
||||
setError(null);
|
||||
})
|
||||
.catch((caught: unknown) => {
|
||||
setError(caught instanceof ApiError ? caught.message : "Chargement impossible.");
|
||||
setFiles([]);
|
||||
})
|
||||
.finally(() => setLoading(false));
|
||||
}, []);
|
||||
|
||||
const unstar = async (file: FavoriteFile) => {
|
||||
setError(null);
|
||||
try {
|
||||
await api.starFile(file.id);
|
||||
setFiles((previous) => previous.filter((item) => item.id !== file.id));
|
||||
} catch (caught) {
|
||||
setError(caught instanceof ApiError ? caught.message : "Action impossible.");
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="flex flex-col gap-5">
|
||||
<PageHeader
|
||||
title="Favoris"
|
||||
description="Les fichiers que vous avez étoilés, tous dossiers confondus."
|
||||
/>
|
||||
|
||||
{error ? <Alert>{error}</Alert> : null}
|
||||
|
||||
{loading ? (
|
||||
<div className="flex justify-center py-16">
|
||||
<Spinner size="md" />
|
||||
</div>
|
||||
) : files.length === 0 ? (
|
||||
<EmptyState
|
||||
icon={<StarIcon className="h-8 w-8" />}
|
||||
title="Aucun favori"
|
||||
description="Étoilez un fichier dans l'explorateur pour le retrouver ici."
|
||||
/>
|
||||
) : (
|
||||
<ul className="flex flex-col divide-y divide-border rounded-lg border border-border bg-surface">
|
||||
{files.map((file, index) => (
|
||||
<li key={file.id} className="flex items-center gap-2 px-3 py-2.5">
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => setViewer(index)}
|
||||
className="flex h-10 w-10 shrink-0 items-center justify-center overflow-hidden rounded-sm border border-border bg-surface-muted text-muted-foreground transition-colors hover:border-border-strong focus-visible:ring-ring focus-visible:ring-2 focus-visible:outline-none"
|
||||
aria-label={`Aperçu de ${file.name}`}
|
||||
>
|
||||
<MediaThumb id={file.id} mime={file.mime_type} name={file.name} />
|
||||
</button>
|
||||
<span className="min-w-0 flex-1">
|
||||
<span className="block truncate text-sm font-medium text-foreground">
|
||||
{file.name}
|
||||
</span>
|
||||
<span className="flex items-center gap-1.5 text-[0.6875rem] text-subtle-foreground">
|
||||
<FolderIcon className="h-3 w-3 shrink-0" />
|
||||
<span className="truncate">{file.folder_name ?? "Racine"}</span>
|
||||
<span aria-hidden="true">·</span>
|
||||
<span className="shrink-0">{formatBytes(file.size_bytes)}</span>
|
||||
</span>
|
||||
</span>
|
||||
|
||||
<IconAction
|
||||
label={`Retirer l'étoile de ${file.name}`}
|
||||
icon={<StarIcon className="h-4 w-4" filled />}
|
||||
onClick={() => void unstar(file)}
|
||||
/>
|
||||
|
||||
<a
|
||||
href={api.downloadUrl(file.id)}
|
||||
download={file.name}
|
||||
className="inline-flex h-8 items-center gap-1.5 rounded-sm border border-border-strong bg-surface px-3 font-display text-[0.6875rem] font-semibold uppercase tracking-label text-foreground transition-colors hover:bg-surface-hover"
|
||||
>
|
||||
<DownloadIcon className="h-3.5 w-3.5" />
|
||||
<span className="hidden sm:inline">Télécharger</span>
|
||||
</a>
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
)}
|
||||
|
||||
{viewer !== null ? (
|
||||
<MediaViewer
|
||||
items={files.map((item) => ({
|
||||
id: item.id,
|
||||
name: item.name,
|
||||
mime_type: item.mime_type,
|
||||
}))}
|
||||
startIndex={viewer}
|
||||
onClose={() => setViewer(null)}
|
||||
/>
|
||||
) : null}
|
||||
</div>
|
||||
);
|
||||
};
|
||||
Reference in New Issue
Block a user