Skip to content

Commit d8a23d2

Browse files
committed
(responsive) auto hide/show rooms list on mobile
1 parent 865ad6c commit d8a23d2

File tree

3 files changed

+36
-5
lines changed

3 files changed

+36
-5
lines changed

src/ChatWindow/ChatWindow.vue

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
:room="room"
88
:textMessages="t"
99
:showRoomsList="showRoomsList"
10+
:isMobile="isMobile"
1011
@fetchRoom="fetchRoom"
1112
@addRoom="addRoom"
1213
>
@@ -23,6 +24,7 @@
2324
:showReactionEmojis="showReactionEmojis"
2425
:textMessages="t"
2526
:showRoomsList="showRoomsList"
27+
:isMobile="isMobile"
2628
@toggleRoomsList="showRoomsList = !showRoomsList"
2729
@fetchMessages="fetchMessages"
2830
@sendMessage="sendMessage"
@@ -79,7 +81,9 @@ export default {
7981
data() {
8082
return {
8183
room: {},
82-
showRoomsList: true
84+
showRoomsList: true,
85+
mobileBreakpoint: 700,
86+
isMobile: false
8387
}
8488
},
8589
@@ -103,6 +107,11 @@ export default {
103107
}
104108
},
105109
110+
mounted() {
111+
this.updateResponsive()
112+
window.addEventListener('resize', () => this.updateResponsive())
113+
},
114+
106115
computed: {
107116
t() {
108117
return {
@@ -121,9 +130,14 @@ export default {
121130
},
122131
123132
methods: {
133+
updateResponsive() {
134+
this.isMobile = window.innerWidth < this.mobileBreakpoint
135+
this.showRoomsList = !this.isMobile
136+
},
124137
fetchRoom({ room }) {
125138
this.room = room
126139
this.fetchMessages({ reset: true })
140+
if (this.isMobile) this.showRoomsList = false
127141
},
128142
addRoom() {
129143
this.$emit('addRoom')

src/ChatWindow/MessagesList.vue

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
<template>
2-
<div class="col-messages" :class="{ 'col-messages-full': !showRoomsList }">
2+
<div
3+
class="col-messages"
4+
:class="{ 'col-messages-full': !showRoomsList }"
5+
v-if="(isMobile && !showRoomsList) || !isMobile"
6+
>
37
<div class="room-header app-border-b">
48
<div class="svg-button toggle-button" @click="$emit('toggleRoomsList')">
59
<svg-icon name="toggle" />
@@ -213,6 +217,7 @@ export default {
213217
currentUserId: { type: String, required: true },
214218
textMessages: { type: Object, required: true },
215219
showRoomsList: { type: Boolean, required: true },
220+
isMobile: { type: Boolean, required: true },
216221
room: { type: Object, required: true },
217222
messages: { type: Array, required: true },
218223
messagesLoaded: { type: Boolean, required: true },
@@ -273,6 +278,8 @@ export default {
273278
},
274279
messages(newVal, oldVal) {
275280
const element = document.getElementsByClassName('container-scroll')[0]
281+
if (!element) return
282+
276283
const options = { top: element.scrollHeight }
277284
278285
if (oldVal && newVal && oldVal.length === newVal.length - 1) {
@@ -339,6 +346,7 @@ export default {
339346
this.focusTextarea()
340347
},
341348
resetTextareaSize() {
349+
if (!this.$refs['roomTextarea']) return
342350
this.$refs['roomTextarea'].style.height = '32px'
343351
},
344352
focusTextarea() {

src/ChatWindow/RoomsList.vue

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
<template>
2-
<div class="rooms-container app-border-r" v-if="showRoomsList">
2+
<div
3+
class="rooms-container app-border-r"
4+
:class="{ 'rooms-container-full': isMobile }"
5+
v-if="showRoomsList"
6+
>
37
<div class="box-search">
48
<div class="icon-search">
59
<svg-icon name="search" />
@@ -71,6 +75,7 @@ export default {
7175
props: {
7276
textMessages: { type: Object, required: true },
7377
showRoomsList: { type: Boolean, required: true },
78+
isMobile: { type: Boolean, required: true },
7479
rooms: { type: Array, required: true },
7580
loadingRooms: { type: Boolean, required: true },
7681
room: { type: Object, required: true }
@@ -99,7 +104,7 @@ export default {
99104
)
100105
},
101106
openRoom(room) {
102-
if (room.roomId === this.room.roomId) return
107+
if (room.roomId === this.room.roomId && !this.isMobile) return
103108
this.selectedRoomId = room.roomId
104109
this.$emit('fetchRoom', { room })
105110
},
@@ -113,9 +118,13 @@ export default {
113118
<style lang="scss" scoped>
114119
.rooms-container {
115120
flex: 0 0 25%;
116-
max-width: 25%;
117121
position: relative;
118122
background: var(--chat-sidemenu-bg-color);
123+
height: 100%;
124+
}
125+
126+
.rooms-container-full {
127+
flex: 0 0 100%;
119128
}
120129
121130
.box-search {

0 commit comments

Comments
 (0)