Skip to content

Commit

Permalink
入室の遷移周りfix
Browse files Browse the repository at this point in the history
  • Loading branch information
Rozelin-dc committed Jun 16, 2024
1 parent 001908a commit 67dee3a
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 13 deletions.
8 changes: 7 additions & 1 deletion src/pages/CreateRoom.vue
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,15 @@ const submit = async () => {
try {
const resp = await api.apiRoomPost(roomInfo)
const roomId = resp.data.roomId
let query = undefined
if (!isPublic.value) {
query = { password: roomPassword.value, isPrivate: 1 }
}
router.push({
path: `/rooms/${roomId}/enter`,
query: { password: roomPassword.value },
query,
})
} catch (e) {
console.error(e)
Expand Down
21 changes: 10 additions & 11 deletions src/pages/EnterRoom.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script setup lang="ts">
import { ref, onMounted } from 'vue'
import { ref, onMounted, computed } from 'vue'
import api, { EnterRoom } from '@/lib/apis'
import router from '@/router'
Expand All @@ -25,22 +25,21 @@ const submit = async () => {
// enterRoom を送る
const resp = await api.apiRoomRoomIdEnterPost(thisRoomId.value, enterInfo)
// ここで resp から userId と userName を持たせて IndividualRoom へ
if (resp.status == 200) {
submitError.value = false
// stores/user に userId と userName を記録して、 /rooms/:id に移動させる
const userId = resp.data.userId
store.setUser(resp.data.userName, userId)
router.push({ path: `/rooms/${thisRoomId.value}` })
} else {
userSettingError.value = true
}
submitError.value = false
// stores/user に userId と userName を記録して、 /rooms/:id に移動させる
const userId = resp.data.userId
store.setUser(resp.data.userName, userId)
router.push({ path: `/rooms/${thisRoomId.value}` })
} catch (e) {
// 通信エラー or userNameエラー or password エラー
console.error(e)
submitError.value = true
}
}
const isPrivate = computed(() => 'isPrivate' in router.currentRoute.value.query)
onMounted(() => {
const roomId = router.currentRoute.value.params.id
if (typeof roomId == 'string') {
Expand All @@ -64,7 +63,7 @@ onMounted(() => {
<input v-model="userNickName" />
</label>
</p>
<p>
<p v-if="isPrivate">
<label>
合言葉
<input v-model="roomPassword" />
Expand Down
12 changes: 11 additions & 1 deletion src/pages/RoomList.vue
Original file line number Diff line number Diff line change
@@ -1,12 +1,22 @@
<script setup lang="ts">
import { onMounted, ref } from 'vue'
import { useRouter } from 'vue-router'
import api, { GetRoomsInner } from '@/lib/apis'
const rooms = ref<GetRoomsInner[]>([])
onMounted(async () => {
const res = await api.apiRoomsGet()
rooms.value = res.data
})
const router = useRouter()
const enterRoom = (room: GetRoomsInner) => {
let query = undefined
if (!room.isPublic) {
query = { isPrivate: 1 }
}
router.push({ path: '/rooms/' + room.roomId + '/enter', query })
}
</script>

<template>
Expand All @@ -20,7 +30,7 @@ onMounted(async () => {
<button
@click="
() => {
$router.push({ path: '/rooms/' + room.roomId + '/enter' })
enterRoom(room)
}
"
>
Expand Down

0 comments on commit 67dee3a

Please sign in to comment.