import { useEffect, useState } from "react"; import { get, put } from "../api"; import { useT } from "../i18n"; import { useStore } from "../store"; interface DirUser { id: string; username: string; display_name: string; } /** Choose users a session is shared with (read-only for them). */ export function ShareDialog({ sessionId, onClose }: { sessionId: string; onClose: () => void }) { const t = useT(); const me = useStore((s) => s.me); const owner = useStore((s) => s.sessionById[sessionId]?.owner_id); const [users, setUsers] = useState([]); const [selected, setSelected] = useState>(new Set()); const [error, setError] = useState(); useEffect(() => { Promise.all([get("/users/directory"), get(`/sessions/${sessionId}/shares`)]) .then(([u, s]) => { setUsers(u.filter((x) => x.id !== owner && x.id !== me?.id)); setSelected(new Set(s)); }) .catch((e) => setError(e.message)); }, [sessionId, owner, me?.id]); const save = async () => { try { await put(`/sessions/${sessionId}/shares`, { users: [...selected] }); onClose(); } catch (e: any) { setError(e.message); } }; return (
e.stopPropagation()}>

{t("share.title")}

{t("share.hint")}
{users.length === 0 &&
{t("share.noUsers")}
} {users.map((u) => ( ))}
{error &&
{error}
}
); }