mirror of
https://github.com/IT4Change/Ocelot-Social.git
synced 2026-01-20 20:01:22 +00:00
- was throwing an error when trying to update commentsCount because of new implementation by @roschaefer which uses countResolver, but there was no related for commentsCount, it was r... also commentsCount is no longer needed anywhere in the code base, it is commentedCount now
87 lines
2.0 KiB
JavaScript
87 lines
2.0 KiB
JavaScript
import gql from 'graphql-tag'
|
|
import isString from 'lodash/isString'
|
|
|
|
export const state = () => {
|
|
return {
|
|
quickResults: [],
|
|
quickPending: false,
|
|
quickValue: '',
|
|
}
|
|
}
|
|
|
|
export const mutations = {
|
|
SET_QUICK_RESULTS(state, results) {
|
|
state.quickResults = results || []
|
|
state.quickPending = false
|
|
},
|
|
SET_QUICK_PENDING(state, pending) {
|
|
state.quickPending = pending
|
|
},
|
|
SET_QUICK_VALUE(state, value) {
|
|
state.quickValue = value
|
|
},
|
|
}
|
|
|
|
export const getters = {
|
|
quickResults(state) {
|
|
return state.quickResults
|
|
},
|
|
quickPending(state) {
|
|
return state.quickPending
|
|
},
|
|
quickValue(state) {
|
|
return state.quickValue
|
|
},
|
|
}
|
|
|
|
export const actions = {
|
|
async quickSearch({ commit, getters }, { value }) {
|
|
value = isString(value) ? value.trim() : ''
|
|
const lastVal = getters.quickValue
|
|
if (value.length < 3 || lastVal.toLowerCase() === value.toLowerCase()) {
|
|
return
|
|
}
|
|
commit('SET_QUICK_VALUE', value)
|
|
commit('SET_QUICK_PENDING', true)
|
|
await this.app.apolloProvider.defaultClient
|
|
.query({
|
|
query: gql(`
|
|
query findPosts($query: String!) {
|
|
findPosts(query: $query, limit: 10) {
|
|
id
|
|
slug
|
|
label: title
|
|
value: title,
|
|
shoutedCount
|
|
commentedCount
|
|
createdAt
|
|
author {
|
|
id
|
|
name
|
|
slug
|
|
}
|
|
}
|
|
}
|
|
`),
|
|
variables: {
|
|
query: value.replace(/\s/g, '~ ') + '~',
|
|
},
|
|
})
|
|
.then(res => {
|
|
commit('SET_QUICK_RESULTS', res.data.findPosts || [])
|
|
})
|
|
.catch(() => {
|
|
commit('SET_QUICK_RESULTS', [])
|
|
})
|
|
.finally(() => {
|
|
commit('SET_QUICK_PENDING', false)
|
|
})
|
|
return getters.quickResults
|
|
},
|
|
async quickClear({ commit }) {
|
|
commit('SET_QUICK_PENDING', false)
|
|
commit('SET_QUICK_RESULTS', [])
|
|
commit('SET_QUICK_VALUE', '')
|
|
},
|
|
}
|