Skip to content

Commit

Permalink
feat(booru): improve and fix some actions
Browse files Browse the repository at this point in the history
  • Loading branch information
AlejandroAkbal committed Jul 21, 2020
1 parent 01edbb0 commit 31b613d
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 12 deletions.
3 changes: 1 addition & 2 deletions components/pages/posts/domain/Selector.vue
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,8 @@ export default {
'fetchPosts',
]),
// Changes that we have to do when changing domain so request is not malformed
async changeDomain(domain) {
await this.activeBooruManager(domain)
await this.activeBooruManager({ operation: 'search', value: domain })
await this.pidManager({ operation: 'reset' })
Expand Down
32 changes: 22 additions & 10 deletions store/booru/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,17 +92,29 @@ export const mutations = {
}

export const actions = {
activeBooruManager({ state, commit }, domain) {
// Search for the domain
const booruData = findBoorusWithValueByKey(
domain,
'domain',
state.booru.list
)[0]
activeBooruManager({ state, commit, getters }, { operation, value }) {
switch (operation) {
case 'search': {
// Search for the domain
const booruData = findBoorusWithValueByKey(
value,
'domain',
getters.getBooruList
)[0]

const booruIndex = getters.getBooruList.indexOf(booruData) // findIndex could be used

commit('setActiveBooru', booruIndex)
break
}

const booruIndex = state.booru.list.indexOf(booruData) // findIndex could be used
case 'reset':
commit('setActiveBooru', 0)
break

commit('setActiveBooru', booruIndex)
default:
throw new Error('No operation specified')
}
},

postsManager({ state, commit }, { operation, value }) {
Expand All @@ -112,7 +124,7 @@ export const actions = {
break

case 'concat':
commit('setPostsData', [...new Set(state.posts.data.concat(value))])
commit('setPostsData', [...new Set([...state.posts.data, ...value])])
break

default:
Expand Down

0 comments on commit 31b613d

Please sign in to comment.