diff --git a/src/components/OrbitExitModal.tsx b/src/components/OrbitExitModal.tsx new file mode 100644 index 00000000..23fa1990 --- /dev/null +++ b/src/components/OrbitExitModal.tsx @@ -0,0 +1,59 @@ +import { createPortal } from 'react-dom'; +import { useOrbitStore } from '../store/orbitStore'; +import { leaveOrbitSession } from '../utils/orbit'; + +/** + * Orbit — exit notification modal. + * + * Shown when: + * - `phase === 'ended'` (host closed the session; guest sees it) + * - `phase === 'error' && errorMessage === 'kicked'` (host removed us) + * + * "OK" cleans up the guest-side outbox + resets the local store. + */ +export default function OrbitExitModal() { + const phase = useOrbitStore(s => s.phase); + const errorMessage = useOrbitStore(s => s.errorMessage); + const role = useOrbitStore(s => s.role); + const sessionName = useOrbitStore(s => s.state?.name); + const hostName = useOrbitStore(s => s.state?.host); + + const isEnded = phase === 'ended'; + const isKicked = phase === 'error' && errorMessage === 'kicked'; + if (!isEnded && !isKicked) return null; + + const title = isKicked + ? 'You were removed from the session' + : 'The host ended the session'; + const body = isKicked + ? `@${hostName ?? 'host'} removed you from "${sessionName ?? 'the session'}".` + : `"${sessionName ?? 'The session'}" has ended. Hope you had fun.`; + + const onOk = async () => { + try { + if (role === 'guest') await leaveOrbitSession(); + else useOrbitStore.getState().reset(); + } catch { + useOrbitStore.getState().reset(); + } + }; + + return createPortal( +
{body}
+