feat(chat,files): salon par dossier, favoris, cloisonnement des droits admin (#8)
CD — Déploiement / deploy (push) Successful in 19s
CD — Déploiement / deploy (push) Successful in 19s
- 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 --------- Co-authored-by: xEsiah <[email protected]> Reviewed-on: #8 Reviewed-by: Esiah <[email protected]> Co-authored-by: Gitea Actions <-[email protected]>
This commit was merged in pull request #8.
This commit is contained in:
@@ -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