Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/backend/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,12 @@
export const updateSetting = async (setting, payload) => axios.post(`/wiki/setting/${setting}/update`, { ...payload, setting })
export const updateSkin = async payload => updateSetting('wgDefaultSkin', payload)
export const wikiDetails = async payload => (await axios.post('/wiki/details', payload)).data.data
export const updateProfile = async payload => axios.post('/wiki/profile', payload)
export const updateProfile = async payload => (await axios.post('/wiki/profile', payload)).data.data
export const wikiDiscovery = async ({ sort, direction, active, currentPage, resultsPerPage }) => {
return (await axios.get('/wiki', {
params: {
sort: sort,

Check warning on line 84 in src/backend/api.js

View workflow job for this annotation

GitHub Actions / build (22)

Expected property shorthand
direction: direction,

Check warning on line 85 in src/backend/api.js

View workflow job for this annotation

GitHub Actions / build (22)

Expected property shorthand
is_active: active,
page: currentPage,
per_page: resultsPerPage
Expand Down
39 changes: 16 additions & 23 deletions src/components/Pages/ManageWiki/Cards/Profile.vue
Original file line number Diff line number Diff line change
Expand Up @@ -137,30 +137,32 @@ export default {
},
computed: {
hasProfile: function () {
return !!this.profile.updated_at
return !!this.profile?.updated_at
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

},
hasAudience: function () {
return !!this.profile.audience
return !!this.profile?.audience
},
isWikiTemporary: function () {
return this.profile.temporality === 'temporary'
return this.profile?.temporality === 'temporary'
},
updatedAt: function () {
if (this.profile.updated_at) {
if (this.profile?.updated_at) {
return `Last updated on ${new Date(this.profile.updated_at).toLocaleString()}`
}
return false
}
},
methods: {
getQuestionResponse (question) {
const customResponse = this.profile[question + '_other']
if (customResponse) {
return `Other: ${customResponse}`
}
const providedResponse = this.profile[question]
if (providedResponse) {
return providedResponses[question][providedResponse]
if (this.profile) {
const customResponse = this.profile[question + '_other']
if (customResponse) {
return `Other: ${customResponse}`
}
const providedResponse = this.profile[question]
if (providedResponse) {
return providedResponses[question][providedResponse]
}
}
return 'No answer selected.'
},
Expand All @@ -184,11 +186,8 @@ export default {
temporality: this.dialog.data.stepTwo.temporality,
...(this.dialog.data.stepTwo.otherTemporality && { temporality_other: this.dialog.data.stepTwo.otherTemporality })
}

this.profile = (await this.$store.dispatch('updateProfile', {
wiki: this.wikiId, profile: JSON.stringify(profile)
})).data.data ?? {}

await this.$store.dispatch('updateProfile', { wiki: this.wikiId, profile: JSON.stringify(profile) })
this.profile = this.$store.state.wikis.currentWikiProfile
this.$refs.message.show('success', 'Intended use has been updated.')
this.dialog.show = false
} catch (error) {
Expand All @@ -200,13 +199,7 @@ export default {
}
},
async created () {
try {
const details = await this.$api.wikiDetails({ wiki: this.wikiId })
this.profile = details.wiki_latest_profile ?? {}
} catch (error) {
console.log(error)
this.$refs.message.show('error', 'Something went wrong with fetching your intended use.')
}
this.profile = this.$store.state.wikis.currentWikiProfile
}
}
</script>
Expand Down
13 changes: 10 additions & 3 deletions src/store/wikis.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,9 @@ const mutations = {
},
set_current_wiki_entityImportError (state, error) {
state.currentWikiEntityImportError = error
},
set_current_wiki_profile (state, value) {
state.currentWikiProfile = value
}
}

Expand All @@ -166,7 +169,10 @@ const actions = {
})
.catch(err => commit('set_current_wiki_entityImportError', err))
api.wikiDetails({ wiki: wikiId })
.then(details => commit('set_current_wiki_settings', details))
.then(details => {
commit('set_current_wiki_settings', details)
commit('set_current_wiki_profile', details.wiki_latest_profile)
})
},
resetWikisState ({ commit }) {
commit('wikis_resetState')
Expand Down Expand Up @@ -197,8 +203,9 @@ const actions = {
updateSetting ({ commit }, payload) {
return api.updateSetting(payload.setting, payload)
},
updateProfile ({ commit }, payload) {
return api.updateProfile(payload)
async updateProfile ({ commit }, payload) {
const response = await api.updateProfile(payload)
commit('set_current_wiki_profile', response)
},
triggerEntityImport ({ commit }, wikiId) {
return api.importEntities({ wikiId })
Expand Down
Loading