mirror of
https://github.com/IT4Change/Ocelot-Social.git
synced 2025-12-13 07:45:56 +00:00
The story of SearchInput.vue throws errors because of line 81, dateTime. What must be included to fix this? The search results shown by the frontend are sometimes differnt from the response of the backend. It shows no results found though there are results incoming. Tests are not implemented yet.
93 lines
2.1 KiB
JavaScript
93 lines
2.1 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 findResources($query: String!) {
|
|
findResources(query: $query, limit: 5) {
|
|
__typename
|
|
... on Post {
|
|
id
|
|
title
|
|
slug
|
|
commentsCount
|
|
shoutedCount
|
|
createdAt
|
|
author {
|
|
name
|
|
}
|
|
}
|
|
... on User {
|
|
id
|
|
name
|
|
slug
|
|
avatar
|
|
}
|
|
}
|
|
}
|
|
`,
|
|
variables: {
|
|
query: value,
|
|
},
|
|
})
|
|
.then(res => {
|
|
commit('SET_QUICK_RESULTS', res.data.findResources || [])
|
|
})
|
|
.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', '')
|
|
},
|
|
}
|