mirror of
https://github.com/vuejs/vue-cli.git
synced 2026-01-26 09:09:05 -06:00
fix(ui): Suggestions API fixes
This commit is contained in:
@@ -5,12 +5,18 @@
|
||||
>
|
||||
<ApolloSubscribeToMore
|
||||
:document="require('../graphql/suggestionAdded.gql')"
|
||||
:updateQuery="(previousResult, { subscriptionData }) => ({
|
||||
suggestions: [
|
||||
...previousResult.suggestions,
|
||||
subscriptionData.data.suggestionAdded
|
||||
]
|
||||
})"
|
||||
:updateQuery="(previousResult, { subscriptionData }) => {
|
||||
const newSuggestion = subscriptionData.data.suggestionAdded
|
||||
if (previousResult.suggestions.find(s => s.id === newSuggestion.id)) {
|
||||
return previousResult
|
||||
}
|
||||
return {
|
||||
suggestions: [
|
||||
...previousResult.suggestions,
|
||||
newSuggestion
|
||||
]
|
||||
}
|
||||
}"
|
||||
/>
|
||||
|
||||
<ApolloSubscribeToMore
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
// Subs
|
||||
const channels = require('../channels')
|
||||
// Connectors
|
||||
const { log } = require('../utils/logger')
|
||||
|
||||
const suggestions = []
|
||||
|
||||
@@ -25,11 +27,14 @@ function add (suggestion, context) {
|
||||
suggestionAdded: suggestion
|
||||
})
|
||||
|
||||
log('Suggestion added', suggestion.id)
|
||||
|
||||
return suggestion
|
||||
}
|
||||
|
||||
function remove (id, context) {
|
||||
const suggestion = findOne(id)
|
||||
if (!suggestion) return
|
||||
const index = suggestions.indexOf(suggestion)
|
||||
suggestions.splice(index, 1)
|
||||
|
||||
@@ -37,6 +42,8 @@ function remove (id, context) {
|
||||
suggestionRemoved: suggestion
|
||||
})
|
||||
|
||||
log('Suggestion removed', suggestion.id)
|
||||
|
||||
return suggestion
|
||||
}
|
||||
|
||||
@@ -55,6 +62,8 @@ function update (data, context) {
|
||||
suggestionUpdated: suggestion
|
||||
})
|
||||
|
||||
log('Suggestion updated', suggestion.id)
|
||||
|
||||
return suggestion
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user