Skip to content

Commit 1509e5e

Browse files
committed
(fix) improve loading pattern
1 parent a020778 commit 1509e5e

File tree

2 files changed

+20
-13
lines changed

2 files changed

+20
-13
lines changed

src/ChatWindow/ChatWindow.vue

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -113,15 +113,18 @@ export default {
113113
},
114114
115115
watch: {
116-
rooms(newVal, oldVal) {
117-
if (newVal[0] && newVal.length !== oldVal.length) {
118-
if (this.roomId) {
119-
const room = newVal.find(r => r.roomId === this.roomId)
120-
this.fetchRoom({ room })
121-
} else if (!this.isMobile) {
122-
this.fetchRoom({ room: this.orderedRooms[0] })
123-
} else {
124-
this.showRoomsList = true
116+
rooms: {
117+
immediate: true,
118+
handler(newVal, oldVal) {
119+
if (newVal[0] && (!oldVal || newVal.length !== oldVal.length)) {
120+
if (this.roomId) {
121+
const room = newVal.find(r => r.roomId === this.roomId)
122+
this.fetchRoom({ room })
123+
} else if (!this.isMobile) {
124+
this.fetchRoom({ room: this.orderedRooms[0] })
125+
} else {
126+
this.showRoomsList = true
127+
}
125128
}
126129
}
127130
},
@@ -157,7 +160,7 @@ export default {
157160
}
158161
},
159162
160-
mounted() {
163+
created() {
161164
this.updateResponsive()
162165
window.addEventListener('resize', ev => {
163166
if (ev.isTrusted) this.updateResponsive()

src/ChatWindow/RoomsList.vue

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,12 @@ export default {
114114
rooms(val) {
115115
this.filteredRooms = val
116116
},
117-
room(val) {
118-
if (val) this.selectedRoomId = val.roomId
117+
118+
room: {
119+
immediate: true,
120+
handler(val) {
121+
if (val && !this.isMobile) this.selectedRoomId = val.roomId
122+
}
119123
}
120124
},
121125
@@ -129,7 +133,7 @@ export default {
129133
},
130134
openRoom(room) {
131135
if (room.roomId === this.room.roomId && !this.isMobile) return
132-
this.selectedRoomId = room.roomId
136+
if (!this.isMobile) this.selectedRoomId = room.roomId
133137
this.$emit('fetchRoom', { room })
134138
},
135139
addRoom() {

0 commit comments

Comments
 (0)