Skip to content

Commit

Permalink
fixup! Refactoring and add empty content for empty filter output
Browse files Browse the repository at this point in the history
  • Loading branch information
DorraJaouad committed Oct 17, 2023
1 parent 98c799d commit 407deb0
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 19 deletions.
33 changes: 18 additions & 15 deletions src/components/LeftSidebar/LeftSidebar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@
<template v-if="!isSearching">
<NcAppNavigationCaption v-if="isFiltered && filteredConversationsList.length > 0" :name="getFilterCaption" />
<NcEmptyContent v-else-if="initialisedConversations && filteredConversationsList.length === 0"
class="scroller"
:name="t('spreed', 'No matches found')"
:description="messageDisplay">
<template #icon>
Expand All @@ -144,9 +145,6 @@
class="scroller h-100"
@scroll.native="debounceHandleScroll" />
</li>
<Hint v-if="initialisedConversations && filteredConversationsList.length === 0"
:hint="t('spreed', 'No matches found')" />

<NcButton v-if="!preventFindingUnread && lastUnreadMentionBelowViewportIndex !== null"
class="unread-mention-button"
type="primary"
Expand Down Expand Up @@ -385,6 +383,7 @@ export default {
isCurrentTabLeader: false,
isFocused: false,
isFiltered: null,
previousFilter: null,
}
},

Expand Down Expand Up @@ -427,19 +426,17 @@ export default {
}
// applying filters
if (this.isFiltered) {
const filteredConversations = this.conversationsList.filter(function(conversation) {
return this.filterFunction(conversation)
|| conversation.hasCall
|| conversation.token === this.token
}.bind(this))
const filteredConversations = this.conversationsList.filter((conversation) => this.filterFunction(conversation)
|| conversation.hasCall
|| conversation.token === this.token)

// return empty if it only includes the current conversation without any flags
const includesCurrentConversationOnly = filteredConversations.length === 1
&& filteredConversations.filter(function(conversation) {
return !this.filterFunction(conversation) && conversation.token === this.token
}.bind(this)).length
const isNewFilter = this.isPreviousFilter() !== this.isFiltered
const hasCurrentConversationOnly = filteredConversations.length === 1
&& filteredConversations.filter((conversation) => !this.filterFunction(conversation)
&& conversation.token === this.token).length

return includesCurrentConversationOnly ? [] : filteredConversations
return hasCurrentConversationOnly && isNewFilter ? [] : filteredConversations
}

return this.conversationsList
Expand Down Expand Up @@ -561,18 +558,24 @@ export default {
this.$refs.openConversationsList.showModal()
},

isPreviousFilter() {
const cachedPreviousFilter = this.previousFilter
this.previousFilter = this.isFiltered
return cachedPreviousFilter
},

handleFilter(filter) {
this.isFiltered = filter

// Store the active filter
if (filter) {
BrowserStorage.setItem('filterEnabled', filter)
} else {
BrowserStorage.removeItem('filterEnabled')
}

// Clear the search input once a filter is active
this.searchText = ''
// Initiate the previous filter
this.previousFilter = null
},

filterFunction(conversation) {
Expand Down
6 changes: 2 additions & 4 deletions src/utils/conversation.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* @copyright Copyright (c) 2023
* @copyright Copyright (c) 2023 <dorra.jaoued7@gmail.com>
*
* @author Dorra Jaouad <dorra.jaoued7@gmail.com>
*
Expand All @@ -19,9 +19,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
import {
CONVERSATION,
} from '../constants.js'
import { CONVERSATION } from '../constants.js'

/**
* check if the conversation has unread messages
Expand Down

0 comments on commit 407deb0

Please sign in to comment.