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

Commit

Permalink
Fixed loading state in Play screen (#33)
Browse files Browse the repository at this point in the history
  • Loading branch information
spietras authored May 26, 2022
1 parent 7d925ca commit 6a2fb6b
Showing 1 changed file with 20 additions and 14 deletions.
34 changes: 20 additions & 14 deletions src/screens/Play.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -243,20 +243,24 @@ export default function Play({ navigation }: PlayProps) {
useCancellable(
(cancelInfo) => {
if (!code) return;
room
.connect(
code,
handleRoomConnected,
handleUserConnected,
handleUserDisconnected,
handleRoomEvent
)
.then(() => {
if (!cancelInfo.cancelled) setRoomReady(true);
})
.catch(() => {
if (!cancelInfo.cancelled) setError("Can't connect to room.");
});
setRoomReady(false);
room.disconnect().then(() => {
if (cancelInfo.cancelled) return;
room
.connect(
code,
handleRoomConnected,
handleUserConnected,
handleUserDisconnected,
handleRoomEvent
)
.then(() => {
if (!cancelInfo.cancelled) setRoomReady(true);
})
.catch(() => {
if (!cancelInfo.cancelled) setError("Can't connect to room.");
});
});
return () => {
room.disconnect().then();
};
Expand Down Expand Up @@ -297,6 +301,8 @@ export default function Play({ navigation }: PlayProps) {
(cancelInfo) => {
if (settings.instrument.value === undefined) return;

setPlayerReady(false);

const load = async (instrument: string, notes: number[]) => {
await player.player.unload();
await player.player.load(instrument, notes);
Expand Down

0 comments on commit 6a2fb6b

Please sign in to comment.