improve ui

This commit is contained in:
sparshg
2024-09-20 02:51:49 +05:30
parent 8a85437feb
commit 9cc0defa05
6 changed files with 103 additions and 32 deletions

View File

@@ -35,6 +35,7 @@ pub async fn add_room(sid: Sid, code: String, pool: &sqlx::PgPool) -> Result<()>
}
pub async fn join_room(sid: Sid, code: String, pool: &sqlx::PgPool) -> Result<()> {
let code = code.to_uppercase();
let room = sqlx::query!(
r#"SELECT player1_id, player2_id FROM rooms WHERE code = $1"#,
code
@@ -108,9 +109,9 @@ pub async fn start(sid: Sid, code: String, pool: &sqlx::PgPool) -> Result<()> {
};
let status = if sid.as_str() == player1 {
Status::P2Turn
} else if sid.as_str() == player2 {
Status::P1Turn
} else if sid.as_str() == player2 {
Status::P2Turn
} else {
return Err(Error::NotInRoom); // not in room
};

View File

@@ -66,7 +66,7 @@ fn on_connect(socket: SocketRef) {
}
socket.leave_all().unwrap();
socket.join(room.clone()).unwrap();
socket.emit("created-room", &room).unwrap();
socket.emit("joined-room", &room).unwrap();
},
);
@@ -83,6 +83,8 @@ fn on_connect(socket: SocketRef) {
}
socket.leave_all().unwrap();
socket.join(room.clone()).unwrap();
socket.emit("joined-room", &room).unwrap();
if socket.within(room.clone()).sockets().unwrap().len() != 2 {
return;
}