From d057233c4589a26c712d5705e2c5c5fbffc693df Mon Sep 17 00:00:00 2001 From: Ajay Bura <32841439+ajbura@users.noreply.github.com> Date: Tue, 28 Jul 2026 15:01:08 +0530 Subject: [PATCH] move leave room dialog to new sdk --- .../leave-room-prompt/LeaveRoomPrompt.tsx | 40 ++++++------------- .../leave-space-prompt/LeaveSpacePrompt.tsx | 33 ++++++++------- 2 files changed, 32 insertions(+), 41 deletions(-) diff --git a/src/app/components/leave-room-prompt/LeaveRoomPrompt.tsx b/src/app/components/leave-room-prompt/LeaveRoomPrompt.tsx index eba75721..c8f87b9e 100644 --- a/src/app/components/leave-room-prompt/LeaveRoomPrompt.tsx +++ b/src/app/components/leave-room-prompt/LeaveRoomPrompt.tsx @@ -1,4 +1,4 @@ -import React, { useCallback, useEffect } from 'react'; +import React, { useCallback } from 'react'; import FocusTrap from 'focus-trap-react'; import { Dialog, @@ -17,15 +17,12 @@ import { Spinner, } from 'folds'; import { postLeave } from 'neurone/lib/api/matrix/client/v3/rooms'; -import { - MatrixResponseResult, - parseMatrixResp, - printMatrixError, -} from 'neurone/lib/matrix-request'; +import { parseMatrixResp } from 'neurone/lib/matrix-request'; import { AsyncStatus, useAsyncCallback } from '../../hooks/useAsyncCallback'; import { stopPropagation } from '../../utils/keyboard'; import { useClient } from '../../hooks/useClient'; import { deleteJoinRooms } from '../../../client/syncWriter/utils'; +import { useAlive } from '../../hooks/useAlive'; type LeaveRoomPromptProps = { roomId: string; @@ -34,31 +31,25 @@ type LeaveRoomPromptProps = { }; export function LeaveRoomPrompt({ roomId, onDone, onCancel }: LeaveRoomPromptProps) { const ct = useClient(); + const alive = useAlive(); - const [leaveState, leaveRoom] = useAsyncCallback, Error, []>( + const [leaveState, leaveRoom] = useAsyncCallback( useCallback(async () => { const response = await ct.requestAuthJSON(postLeave({ pathParams: { roomId } })); - deleteJoinRooms(ct, [roomId]) - .then(() => console.log('=====> deleted')) - .catch((e) => { - console.error(e); - }); - return parseMatrixResp(response); + deleteJoinRooms(ct, [roomId]); + const [err] = await parseMatrixResp(response); + if (err) throw new Error(err.data.error ?? err.data.errcode); }, [ct, roomId]) ); - const success = leaveState.status === AsyncStatus.Success; - const [requestError] = success ? leaveState.data : []; const handleLeave = () => { - leaveRoom(); + leaveRoom().then(() => { + if (alive()) { + onDone(); + } + }); }; - useEffect(() => { - if (success) { - onDone(); - } - }, [success, onDone]); - return ( }> @@ -94,11 +85,6 @@ export function LeaveRoomPrompt({ roomId, onDone, onCancel }: LeaveRoomPromptPro Failed to leave room! {leaveState.error.message} )} - {requestError && ( - - Failed to leave room! {printMatrixError(requestError)} - - )}