Skip to content

Commit

Permalink
Update selectionModeSelections data object to be reactive
Browse files Browse the repository at this point in the history
  • Loading branch information
kommunarr committed Sep 26, 2023
1 parent b0d40b7 commit d8bffc6
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 18 deletions.
7 changes: 7 additions & 0 deletions src/renderer/components/ft-list-video/ft-list-video.js
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,10 @@ export default defineComponent({
return this.$store.getters.getSelectAllInSelectionModeTriggered
},

getUnselectAllInSelectionModeTriggered: function () {
return this.$store.getters.getUnselectAllInSelectionModeTriggered
},

videoDropdownOptionArguments: function () {
const count = 1
const videoComponents = [this]
Expand Down Expand Up @@ -316,6 +320,9 @@ export default defineComponent({
if (this.selectionModeSelectionId === 0) {
this.addToOrRemoveFromSelectionModeSelections()
}
},
getUnselectAllInSelectionModeTriggered() {
this.selectionModeSelectionId = 0
}
},
created: function () {
Expand Down
8 changes: 6 additions & 2 deletions src/renderer/components/top-nav/top-nav.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,13 @@ export default defineComponent({
return this.$store.getters.getSelectionModeSelections
},

selectionModeSelectionValues: function() {
return Object.values(this.selectionModeSelections.selections)
},

videoDropdownOptionArguments: function() {
const count = this.selectionModeSelections.count
const videoComponents = Object.values(this.selectionModeSelections.selections)
const videoComponents = this.selectionModeSelectionValues
const count = videoComponents.length
const videosWithChannelIdsCount = videoComponents.filter((videoComponent) => videoComponent.channelId !== null).length

const watchedVideosCount = videoComponents.filter((videoComponent) => videoComponent.watched).length
Expand Down
2 changes: 1 addition & 1 deletion src/renderer/components/top-nav/top-nav.vue
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
<ft-icon-button
v-if="isSelectionModeEnabled"
class="navIcon selectionModeOptionsButton"
:class="{ navIconDisabled: selectionModeSelections.count === 0 }"
:class="{ navIconDisabled: selectionModeSelectionValues.length === 0 }"
:icon="['fas', 'ellipsis-v']"
:title="$t('More Options')"
theme="base-nav-icon"
Expand Down
28 changes: 13 additions & 15 deletions src/renderer/store/modules/utils.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import fs from 'fs/promises'
import path from 'path'
import i18n from '../../i18n/index'
import { set as vueSet } from 'vue'
import { set as vueSet, del as vueDel } from 'vue'

import { IpcChannels } from '../../../constants'
import { pathExists } from '../../helpers/filesystem'
Expand Down Expand Up @@ -46,9 +46,10 @@ const state = {
externalPlayerCmdArguments: {},
isSelectionModeEnabled: false,
selectAllVideosInSelectionModeKey: 0,
unselectAllVideosInSelectionModeKey: 0,
// Vuex doesn't support Maps, so we have to use an object here instead
// TODO: switch to a Map during the Pinia migration
selectionModeSelections: { count: 0, selections: {} },
selectionModeSelections: { index: 0, selections: {} },
}

const getters = {
Expand Down Expand Up @@ -128,6 +129,10 @@ const getters = {
return state.selectAllVideosInSelectionModeKey
},

getUnselectAllInSelectionModeTriggered () {
return state.unselectAllVideosInSelectionModeKey
},

getIsIndexSelectedInSelectionMode: (state) => (index) => {
return Object.hasOwn(state.selectionModeSelections.selections, index)
},
Expand Down Expand Up @@ -508,7 +513,7 @@ const actions = {
},

clearSelectionModeSelections ({ commit }) {
commit('setSelectionModeSelections', { count: 0, selections: {} })
commit('setSelectionModeSelections', { index: 0, selections: {} })
},

addToSelectionModeSelections ({ commit }, selection) {
Expand Down Expand Up @@ -790,25 +795,18 @@ const mutations = {
},

setSelectionModeSelections (state, selectionModeSelections) {
Object.values(state.selectionModeSelections.selections).forEach((videoComponent) => {
videoComponent.selectionModeSelectionId = 0
})

// clears up rare cases of Vue not removing selection styling
document.querySelectorAll('.selectedInSelectionMode')?.forEach((match) =>
match.classList.remove('selectedInSelectionMode'))

state.selectionModeSelections = selectionModeSelections
state.unselectAllVideosInSelectionModeKey++
},

addToSelectionModeSelections (state, { selection, callback }) {
state.selectionModeSelections.selections[++state.selectionModeSelections.count] = selection
callback(state.selectionModeSelections.count)
vueSet(state.selectionModeSelections.selections,
++state.selectionModeSelections.index, selection)
callback(state.selectionModeSelections.index)
},

removeFromSelectionModeSelections (state, { selectionIndex }) {
delete state.selectionModeSelections.selections[selectionIndex]
state.selectionModeSelections.count--
vueDel(state.selectionModeSelections.selections, selectionIndex)
},
}

Expand Down

0 comments on commit d8bffc6

Please sign in to comment.