fix: unified tab layout, full lightbox, global toasts
CD — Kai-Sa-Cam Deployment / deploy (push) Successful in 9s
CD — Kai-Sa-Cam Deployment / deploy (push) Successful in 9s
This commit is contained in:
+43
-18
@@ -11,6 +11,13 @@ import {
|
||||
startSessionMonitor,
|
||||
} from "./lib/api";
|
||||
|
||||
type ToastType = "info" | "success" | "error" | "warning";
|
||||
|
||||
interface Toast {
|
||||
message: string;
|
||||
type: ToastType;
|
||||
}
|
||||
|
||||
export function App() {
|
||||
const [activeTab, setActiveTab] = useState<"live" | "media">("live");
|
||||
const [isRecording, setIsRecording] = useState(false);
|
||||
@@ -19,7 +26,12 @@ export function App() {
|
||||
const [snapshots, setSnapshots] = useState<string[]>([]);
|
||||
const [sessionExpired, setSessionExpired] = useState(false);
|
||||
const [streamKey, setStreamKey] = useState(0);
|
||||
const [toast, setToast] = useState<string | null>(null);
|
||||
const [toast, setToast] = useState<Toast | null>(null);
|
||||
|
||||
const showToast = (message: string, type: ToastType = "info") => {
|
||||
setToast({ message, type });
|
||||
setTimeout(() => setToast(null), 2500);
|
||||
};
|
||||
|
||||
const {
|
||||
startRecording,
|
||||
@@ -48,7 +60,12 @@ export function App() {
|
||||
useEffect(() => {
|
||||
const off = onSessionChange((expired) => {
|
||||
setSessionExpired(expired);
|
||||
if (!expired) setStreamKey((k) => k + 1); // recharge le flux vidéo après reconnexion
|
||||
if (expired) {
|
||||
showToast("Session expirée", "warning");
|
||||
} else {
|
||||
showToast("Session reconnectée", "success");
|
||||
setStreamKey((k) => k + 1); // recharge le flux vidéo après reconnexion
|
||||
}
|
||||
});
|
||||
const stop = startSessionMonitor();
|
||||
return () => {
|
||||
@@ -71,12 +88,10 @@ export function App() {
|
||||
if (!res.ok) throw new Error("Snapshot failed");
|
||||
const data = await res.json();
|
||||
setSnapshots((prev) => [data.filename, ...prev]);
|
||||
setToast("Capture d'écran prise");
|
||||
setTimeout(() => setToast(null), 2000);
|
||||
showToast("Capture d'écran prise", "success");
|
||||
} catch (e) {
|
||||
console.error("Snapshot error:", e);
|
||||
setToast("Erreur lors de la capture");
|
||||
setTimeout(() => setToast(null), 2000);
|
||||
showToast("Erreur lors de la capture", "error");
|
||||
}
|
||||
};
|
||||
|
||||
@@ -110,31 +125,41 @@ export function App() {
|
||||
|
||||
<main className="flex-1 flex flex-col min-h-0 relative">
|
||||
{toast && (
|
||||
<div className="absolute top-2 right-2 z-50 glass-card px-4 py-2 rounded-[50px] text-sm animate-fade-in">
|
||||
{toast}
|
||||
<div
|
||||
className={`absolute top-2 right-2 z-50 px-4 py-2 rounded-[50px] text-sm animate-fade-in shadow-lg ${
|
||||
toast.type === "success"
|
||||
? "bg-green-500/40 text-green-100 border border-green-400/60"
|
||||
: toast.type === "error"
|
||||
? "bg-red-500/40 text-red-100 border border-red-400/60"
|
||||
: toast.type === "warning"
|
||||
? "bg-amber-500/40 text-amber-100 border border-amber-400/60"
|
||||
: "glass-card"
|
||||
}`}
|
||||
>
|
||||
{toast.message}
|
||||
</div>
|
||||
)}
|
||||
<nav className="mx-auto mt-[1vh] sm:mt-[1.5vh] flex gap-2 trans-bloc p-1 rounded-[50px] w-fit shrink-0 relative overflow-hidden">
|
||||
<nav className="mx-auto mt-[1vh] sm:mt-[1.5vh] flex trans-bloc rounded-[50px] w-[min(90vw,320px)] shrink-0 relative overflow-hidden">
|
||||
<div
|
||||
className={`absolute top-1 bottom-1 w-[calc(50%-4px)] rounded-[50px] glass-button transition-transform duration-300 ease-in-out ${
|
||||
activeTab === "media" ? "translate-x-[calc(100%+4px)]" : "translate-x-0"
|
||||
className={`absolute top-0 bottom-0 left-0 w-1/2 rounded-[50px] glass-button transition-transform duration-300 ease-in-out ${
|
||||
activeTab === "media" ? "translate-x-full" : "translate-x-0"
|
||||
}`}
|
||||
/>
|
||||
<button
|
||||
className={`relative z-10 px-6 sm:px-8 md:px-10 py-1.5 sm:py-2 md:py-2.5 rounded-[50px] text-sm sm:text-base md:text-lg transition-all active:scale-95 ${
|
||||
className={`relative z-10 flex-1 py-1.5 sm:py-2 md:py-2.5 text-center text-sm sm:text-base md:text-lg transition-all active:scale-95 ${
|
||||
activeTab === "live"
|
||||
? "font-medium"
|
||||
: "hover:bg-white/5"
|
||||
: "hover:bg-white/10"
|
||||
}`}
|
||||
onClick={() => setActiveTab("live")}
|
||||
>
|
||||
Live
|
||||
</button>
|
||||
<button
|
||||
className={`relative z-10 px-6 sm:px-8 md:px-10 py-1.5 sm:py-2 md:py-2.5 rounded-[50px] text-sm sm:text-base md:text-lg transition-all active:scale-95 ${
|
||||
className={`relative z-10 flex-1 py-1.5 sm:py-2 md:py-2.5 text-center text-sm sm:text-base md:text-lg transition-all active:scale-95 ${
|
||||
activeTab === "media"
|
||||
? "font-medium"
|
||||
: "hover:bg-white/5"
|
||||
: "hover:bg-white/10"
|
||||
}`}
|
||||
onClick={() => setActiveTab("media")}
|
||||
>
|
||||
@@ -149,7 +174,7 @@ export function App() {
|
||||
}`}
|
||||
>
|
||||
<div className="flex-1 flex flex-col items-center gap-2 sm:gap-3 md:gap-4 mt-2 sm:mt-3 px-1 sm:px-2 min-h-0">
|
||||
<div className="w-full flex-1 min-h-0 rounded-[20px] sm:rounded-[30px] overflow-hidden glass-card animate-fade-in">
|
||||
<div className="w-full flex-1 min-h-0 rounded-[20px] sm:rounded-[30px] overflow-hidden glass-card">
|
||||
{/* Même origine => même session Access, plus de stream.esiah.dev.
|
||||
Le key force le rechargement du flux après une reconnexion. */}
|
||||
<VideoPlayer
|
||||
@@ -182,8 +207,8 @@ export function App() {
|
||||
activeTab === "media" ? "translate-x-0" : "translate-x-full"
|
||||
}`}
|
||||
>
|
||||
<div className="flex-1 flex flex-col mt-2 sm:mt-3 px-1 sm:px-2 min-h-0 overflow-auto no-scrollbar">
|
||||
<MediaGallery />
|
||||
<div className="flex-1 flex flex-col mt-2 sm:mt-3 px-1 sm:px-2 min-h-0">
|
||||
<MediaGallery showToast={showToast} />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -9,7 +9,11 @@ interface MediaItem {
|
||||
url: string;
|
||||
}
|
||||
|
||||
export function MediaGallery() {
|
||||
interface MediaGalleryProps {
|
||||
showToast?: (message: string, type?: "info" | "success" | "error" | "warning") => void;
|
||||
}
|
||||
|
||||
export function MediaGallery({ showToast }: MediaGalleryProps) {
|
||||
const [media, setMedia] = useState<MediaItem[]>([]);
|
||||
const [selectedItem, setSelectedItem] = useState<MediaItem | null>(null);
|
||||
const [itemToDelete, setItemToDelete] = useState<string | null>(null);
|
||||
@@ -22,11 +26,12 @@ export function MediaGallery() {
|
||||
const data = await res.json();
|
||||
setMedia(data);
|
||||
} catch (e) {
|
||||
setError(
|
||||
const msg =
|
||||
e instanceof SessionExpiredError
|
||||
? "Session expirée, reconnecte-toi"
|
||||
: "Erreur chargement médias",
|
||||
);
|
||||
: "Erreur chargement médias";
|
||||
setError(msg);
|
||||
showToast?.(msg, e instanceof SessionExpiredError ? "warning" : "error");
|
||||
}
|
||||
};
|
||||
|
||||
@@ -42,12 +47,14 @@ export function MediaGallery() {
|
||||
if (!res.ok) throw new Error();
|
||||
setMedia((prev) => prev.filter((m) => m.filename !== filename));
|
||||
setItemToDelete(null);
|
||||
showToast?.("Fichier supprimé", "success");
|
||||
} catch (e) {
|
||||
setError(
|
||||
const msg =
|
||||
e instanceof SessionExpiredError
|
||||
? "Session expirée, reconnecte-toi"
|
||||
: "Erreur suppression",
|
||||
);
|
||||
: "Erreur suppression";
|
||||
setError(msg);
|
||||
showToast?.(msg, e instanceof SessionExpiredError ? "warning" : "error");
|
||||
}
|
||||
};
|
||||
|
||||
@@ -65,18 +72,20 @@ export function MediaGallery() {
|
||||
a.remove();
|
||||
window.URL.revokeObjectURL(url);
|
||||
fetchMedia();
|
||||
showToast?.("Export terminé", "success");
|
||||
} catch (e) {
|
||||
setError(
|
||||
const msg =
|
||||
e instanceof SessionExpiredError
|
||||
? "Session expirée, reconnecte-toi"
|
||||
: "Erreur export",
|
||||
);
|
||||
: "Erreur export";
|
||||
setError(msg);
|
||||
showToast?.(msg, e instanceof SessionExpiredError ? "warning" : "error");
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="flex-1 flex flex-col p-2 sm:p-3 md:p-4 gap-2 sm:gap-3 md:gap-4 overflow-y-auto">
|
||||
<div className="flex justify-between items-center glass-card px-3 sm:px-4 md:px-5 py-1.5 sm:py-2 md:py-2.5 rounded-[30px] sm:rounded-[50px] flex-wrap gap-2">
|
||||
<div className="flex-1 flex flex-col p-1 sm:p-2 md:p-3 gap-2 sm:gap-3 min-h-0">
|
||||
<div className="flex justify-between items-center glass-card px-3 sm:px-4 md:px-5 py-1.5 sm:py-2 rounded-[30px] sm:rounded-[50px] flex-wrap gap-2 shrink-0">
|
||||
<span className="text-xs sm:text-sm md:text-base opacity-80">{media.length} fichiers</span>
|
||||
<div className="flex gap-2">
|
||||
<button
|
||||
@@ -95,8 +104,7 @@ export function MediaGallery() {
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
{error && <div className="text-red-400 text-xs sm:text-sm text-center error-message animate-fade-in">{error}</div>}
|
||||
<div className="grid grid-cols-1 sm:grid-cols-2 md:grid-cols-3 lg:grid-cols-4 gap-2 sm:gap-3 md:gap-4">
|
||||
<div className="flex-1 min-h-0 overflow-y-auto no-scrollbar grid grid-cols-1 sm:grid-cols-2 md:grid-cols-3 lg:grid-cols-4 gap-2 sm:gap-3 content-start">
|
||||
{media.map((item) => (
|
||||
<div
|
||||
key={item.filename}
|
||||
@@ -169,11 +177,11 @@ export function MediaGallery() {
|
||||
|
||||
{selectedItem && (
|
||||
<div
|
||||
className="fixed inset-0 bg-black/80 backdrop-blur-md flex items-center justify-center z-50 p-4 animate-fade-in"
|
||||
className="fixed inset-0 bg-black/90 backdrop-blur-md flex items-center justify-center z-[60] p-4 animate-fade-in"
|
||||
onClick={() => setSelectedItem(null)}
|
||||
>
|
||||
<div
|
||||
className="relative max-w-5xl w-full max-h-[90vh] flex items-center justify-center"
|
||||
className="relative max-w-[95vw] w-full max-h-[95vh] flex items-center justify-center"
|
||||
onClick={(e) => e.stopPropagation()}
|
||||
>
|
||||
{selectedItem.type === "video" ? (
|
||||
@@ -181,13 +189,13 @@ export function MediaGallery() {
|
||||
src={selectedItem.url}
|
||||
controls
|
||||
autoPlay
|
||||
className="max-w-full max-h-[85vh] rounded-[30px] glass-card"
|
||||
className="max-w-full max-h-[90vh] rounded-[30px] glass-card"
|
||||
/>
|
||||
) : (
|
||||
<img
|
||||
src={selectedItem.url}
|
||||
alt={selectedItem.filename}
|
||||
className="max-w-full max-h-[85vh] rounded-[30px] glass-card object-contain"
|
||||
className="max-w-full max-h-[90vh] rounded-[30px] glass-card object-contain"
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user