Skip to content

Commit

Permalink
fix(slimbar): logic to show only friends with unread messages
Browse files Browse the repository at this point in the history
  • Loading branch information
josephmcg authored and stavares843 committed Jun 2, 2022
1 parent c3a7913 commit 4bec4ec
Show file tree
Hide file tree
Showing 9 changed files with 24 additions and 40 deletions.
34 changes: 11 additions & 23 deletions components/ui/Unread/Unread.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,14 @@
import Vue, { PropType } from 'vue'
import { User } from '~/types/ui/user'
import ContextMenu from '~/components/mixins/UI/ContextMenu'
declare module 'vue/types/vue' {
interface Vue {
testFunc: () => void
navigateToUser: () => void
handleShowProfile: () => void
removeUser: () => void
}
}
import { ContextMenuItem } from '~/store/ui/types'
export default Vue.extend({
name: 'Unread',
mixins: [ContextMenu],
props: {
user: {
type: Object as PropType<User>,
default: () => ({
name: '',
address: '',
profilePicture: '',
unreadCount: 0,
}),
required: true,
},
active: {
Expand All @@ -35,13 +21,6 @@ export default Vue.extend({
},
data() {
return {
contextMenuValues: [
{ text: this.$t('context.send'), func: this.navigateToUser },
{ text: this.$t('context.voice'), func: this.testFunc },
{ text: this.$t('context.video'), func: this.testFunc },
{ text: this.$t('context.profile'), func: this.handleShowProfile },
{ text: this.$t('context.remove'), func: this.removeUser },
],
isLoading: false,
}
},
Expand All @@ -50,6 +29,15 @@ export default Vue.extend({
const hash = this.user?.profilePicture
return hash ? `${this.$Config.textile.browser}/ipfs/${hash}` : ''
},
contextMenuValues(): ContextMenuItem[] {
return [
{ text: this.$t('context.send'), func: this.navigateToUser },
{ text: this.$t('context.voice'), func: this.testFunc },
{ text: this.$t('context.video'), func: this.testFunc },
{ text: this.$t('context.profile'), func: this.handleShowProfile },
{ text: this.$t('context.remove'), func: this.removeUser },
]
},
},
methods: {
testFunc() {
Expand All @@ -60,7 +48,7 @@ export default Vue.extend({
try {
await this.$store.dispatch('friends/removeFriend', this.user)
} catch (e) {
this.$toast.success(
this.$toast.error(
this.$t('errors.friends.friend_not_removed') as string,
)
} finally {
Expand Down
1 change: 0 additions & 1 deletion components/views/navigation/sidebar/Sidebar.html
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@
<Slimbar
v-if="$device.isMobile"
:servers="$mock.servers"
:unreads="users"
:open-modal="toggleModal"
horizontal
/>
Expand Down
6 changes: 3 additions & 3 deletions components/views/navigation/slimbar/Slimbar.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
<UiLoadersSpinner :spinning="true" />
</div>
<div id="list-container" v-else>
<UiHorizontalRule v-if="unreads.length > 0" />
<div class="unreads" v-for="user in unreads">
<UiHorizontalRule v-if="friendsWithUnreadMessages.length" />
<div class="unreads" v-for="user in friendsWithUnreadMessages">
<Unread
:key="user.address"
:user="user"
Expand All @@ -46,7 +46,7 @@
</div>
</UiScroll>
<div id="list-container" v-else>
<div class="unreads" v-for="user in unreads">
<div class="unreads" v-for="user in friendsWithUnreadMessages">
<Unread
:key="user.address"
:user="user"
Expand Down
15 changes: 6 additions & 9 deletions components/views/navigation/slimbar/Slimbar.vue
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
<template src="./Slimbar.html" />
<template src="./Slimbar.html"></template>

<script lang="ts">
import Vue, { PropType } from 'vue'
import { mapState } from 'vuex'
import Vue from 'vue'
import { mapState, mapGetters } from 'vuex'
import { SettingsIcon, PlusIcon, SatelliteIcon } from 'satellite-lucide-icons'
import { ModalWindows } from '~/store/ui/types'
import { User } from '~/types/ui/user'
import Unread from '~/components/ui/Unread/Unread.vue'
import { Sounds } from '~/libraries/SoundManager/SoundManager'
import { DataStateType } from '~/store/dataState/types'
import { RootState } from '~/types/store/store'
declare module 'vue/types/vue' {
interface Vue {
Expand All @@ -29,10 +29,6 @@ export default Vue.extend({
type: Boolean,
default: false,
},
unreads: {
type: Array as PropType<Array<User>>,
default: () => [],
},
servers: {
type: Array,
default() {
Expand All @@ -49,8 +45,9 @@ export default Vue.extend({
DataStateType: () => DataStateType,
...mapState(['ui']),
...mapState({
friendsDS: (state) => state.dataState.friends,
friendsDS: (state) => (state as RootState).dataState.friends,
}),
...mapGetters('friends', ['friendsWithUnreadMessages']),
ModalWindows: () => ModalWindows,
},
created() {
Expand Down
1 change: 0 additions & 1 deletion layouts/chat.vue
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
<Slimbar
v-if="!$device.isMobile"
:servers="$mock.servers"
:unreads="friends.all"
:open-modal="toggleModal"
/>
<MobileSidebar
Expand Down
1 change: 0 additions & 1 deletion layouts/files.vue
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
<Slimbar
v-if="!$device.isMobile"
:servers="$mock.servers"
:unreads="friends.all"
:open-modal="toggleModal"
/>
<MobileSidebar
Expand Down
1 change: 0 additions & 1 deletion layouts/friends.vue
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
<Slimbar
v-if="!$device.isMobile"
:servers="$mock.servers"
:unreads="friends.all"
:open-modal="toggleModal"
/>
<MobileSidebar
Expand Down
1 change: 0 additions & 1 deletion layouts/server.vue
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
<Slimbar
v-if="!$device.isMobile"
:servers="$mock.servers"
:unreads="friends.all"
:open-modal="toggleModal"
/>
<ServerSidebar
Expand Down
4 changes: 4 additions & 0 deletions store/friends/getters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export interface FriendsGetters {
): boolean
alphaSortedFriends(state: FriendsState): Dictionary<Friend[]>
alphaSortedOutgoing(state: FriendsState): OutgoingRequest[]
friendsWithUnreadMessages(state: FriendsState): Friend[]
}

const getters: GetterTree<FriendsState, RootState> & FriendsGetters = {
Expand Down Expand Up @@ -127,6 +128,9 @@ const getters: GetterTree<FriendsState, RootState> & FriendsGetters = {
(a.userInfo?.name ?? '').localeCompare(b.userInfo?.name ?? ''),
)
},
friendsWithUnreadMessages: (state: FriendsState): Friend[] => {
return state.all.filter((friend) => friend.unreadCount)
},
}

export default getters

0 comments on commit 4bec4ec

Please sign in to comment.