Skip to content
This repository was archived by the owner on Apr 29, 2024. It is now read-only.

Commit 6a2fb6b

Browse files
authored
Fixed loading state in Play screen (#33)
1 parent 7d925ca commit 6a2fb6b

File tree

1 file changed

+20
-14
lines changed

1 file changed

+20
-14
lines changed

src/screens/Play.tsx

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -243,20 +243,24 @@ export default function Play({ navigation }: PlayProps) {
243243
useCancellable(
244244
(cancelInfo) => {
245245
if (!code) return;
246-
room
247-
.connect(
248-
code,
249-
handleRoomConnected,
250-
handleUserConnected,
251-
handleUserDisconnected,
252-
handleRoomEvent
253-
)
254-
.then(() => {
255-
if (!cancelInfo.cancelled) setRoomReady(true);
256-
})
257-
.catch(() => {
258-
if (!cancelInfo.cancelled) setError("Can't connect to room.");
259-
});
246+
setRoomReady(false);
247+
room.disconnect().then(() => {
248+
if (cancelInfo.cancelled) return;
249+
room
250+
.connect(
251+
code,
252+
handleRoomConnected,
253+
handleUserConnected,
254+
handleUserDisconnected,
255+
handleRoomEvent
256+
)
257+
.then(() => {
258+
if (!cancelInfo.cancelled) setRoomReady(true);
259+
})
260+
.catch(() => {
261+
if (!cancelInfo.cancelled) setError("Can't connect to room.");
262+
});
263+
});
260264
return () => {
261265
room.disconnect().then();
262266
};
@@ -297,6 +301,8 @@ export default function Play({ navigation }: PlayProps) {
297301
(cancelInfo) => {
298302
if (settings.instrument.value === undefined) return;
299303

304+
setPlayerReady(false);
305+
300306
const load = async (instrument: string, notes: number[]) => {
301307
await player.player.unload();
302308
await player.player.load(instrument, notes);

0 commit comments

Comments
 (0)