Skip to content

Commit 316164c

Browse files
authored
Use state for wiki profile card (#982)
1 parent 5322836 commit 316164c

3 files changed

Lines changed: 27 additions & 27 deletions

File tree

src/backend/api.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ export const updateLogo = async ({ file, fileName, wikiId }) => {
7777
export const updateSetting = async (setting, payload) => axios.post(`/wiki/setting/${setting}/update`, { ...payload, setting })
7878
export const updateSkin = async payload => updateSetting('wgDefaultSkin', payload)
7979
export const wikiDetails = async payload => (await axios.post('/wiki/details', payload)).data.data
80-
export const updateProfile = async payload => axios.post('/wiki/profile', payload)
80+
export const updateProfile = async payload => (await axios.post('/wiki/profile', payload)).data.data
8181
export const wikiDiscovery = async ({ sort, direction, active, currentPage, resultsPerPage }) => {
8282
return (await axios.get('/wiki', {
8383
params: {

src/components/Pages/ManageWiki/Cards/Profile.vue

Lines changed: 16 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -137,30 +137,32 @@ export default {
137137
},
138138
computed: {
139139
hasProfile: function () {
140-
return !!this.profile.updated_at
140+
return !!this.profile?.updated_at
141141
},
142142
hasAudience: function () {
143-
return !!this.profile.audience
143+
return !!this.profile?.audience
144144
},
145145
isWikiTemporary: function () {
146-
return this.profile.temporality === 'temporary'
146+
return this.profile?.temporality === 'temporary'
147147
},
148148
updatedAt: function () {
149-
if (this.profile.updated_at) {
149+
if (this.profile?.updated_at) {
150150
return `Last updated on ${new Date(this.profile.updated_at).toLocaleString()}`
151151
}
152152
return false
153153
}
154154
},
155155
methods: {
156156
getQuestionResponse (question) {
157-
const customResponse = this.profile[question + '_other']
158-
if (customResponse) {
159-
return `Other: ${customResponse}`
160-
}
161-
const providedResponse = this.profile[question]
162-
if (providedResponse) {
163-
return providedResponses[question][providedResponse]
157+
if (this.profile) {
158+
const customResponse = this.profile[question + '_other']
159+
if (customResponse) {
160+
return `Other: ${customResponse}`
161+
}
162+
const providedResponse = this.profile[question]
163+
if (providedResponse) {
164+
return providedResponses[question][providedResponse]
165+
}
164166
}
165167
return 'No answer selected.'
166168
},
@@ -184,11 +186,8 @@ export default {
184186
temporality: this.dialog.data.stepTwo.temporality,
185187
...(this.dialog.data.stepTwo.otherTemporality && { temporality_other: this.dialog.data.stepTwo.otherTemporality })
186188
}
187-
188-
this.profile = (await this.$store.dispatch('updateProfile', {
189-
wiki: this.wikiId, profile: JSON.stringify(profile)
190-
})).data.data ?? {}
191-
189+
await this.$store.dispatch('updateProfile', { wiki: this.wikiId, profile: JSON.stringify(profile) })
190+
this.profile = this.$store.state.wikis.currentWikiProfile
192191
this.$refs.message.show('success', 'Intended use has been updated.')
193192
this.dialog.show = false
194193
} catch (error) {
@@ -200,13 +199,7 @@ export default {
200199
}
201200
},
202201
async created () {
203-
try {
204-
const details = await this.$api.wikiDetails({ wiki: this.wikiId })
205-
this.profile = details.wiki_latest_profile ?? {}
206-
} catch (error) {
207-
console.log(error)
208-
this.$refs.message.show('error', 'Something went wrong with fetching your intended use.')
209-
}
202+
this.profile = this.$store.state.wikis.currentWikiProfile
210203
}
211204
}
212205
</script>

src/store/wikis.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,9 @@ const mutations = {
153153
},
154154
set_current_wiki_entityImportError (state, error) {
155155
state.currentWikiEntityImportError = error
156+
},
157+
set_current_wiki_profile (state, value) {
158+
state.currentWikiProfile = value
156159
}
157160
}
158161

@@ -166,7 +169,10 @@ const actions = {
166169
})
167170
.catch(err => commit('set_current_wiki_entityImportError', err))
168171
api.wikiDetails({ wiki: wikiId })
169-
.then(details => commit('set_current_wiki_settings', details))
172+
.then(details => {
173+
commit('set_current_wiki_settings', details)
174+
commit('set_current_wiki_profile', details.wiki_latest_profile)
175+
})
170176
},
171177
resetWikisState ({ commit }) {
172178
commit('wikis_resetState')
@@ -197,8 +203,9 @@ const actions = {
197203
updateSetting ({ commit }, payload) {
198204
return api.updateSetting(payload.setting, payload)
199205
},
200-
updateProfile ({ commit }, payload) {
201-
return api.updateProfile(payload)
206+
async updateProfile ({ commit }, payload) {
207+
const response = await api.updateProfile(payload)
208+
commit('set_current_wiki_profile', response)
202209
},
203210
triggerEntityImport ({ commit }, wikiId) {
204211
return api.importEntities({ wikiId })

0 commit comments

Comments
 (0)