From a6726493ae1fad8cab86980e1bb26f6d3923290f Mon Sep 17 00:00:00 2001 From: Chris Adams Date: Tue, 26 Jan 2021 21:52:45 +0100 Subject: [PATCH] Update edit view to show correct tags and clusters --- .../src/components/profile/ProfileEdit.vue | 6 +++-- frontend/src/store.js | 23 +++++++++++-------- 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/frontend/src/components/profile/ProfileEdit.vue b/frontend/src/components/profile/ProfileEdit.vue index 1b46dc42..c519f546 100644 --- a/frontend/src/components/profile/ProfileEdit.vue +++ b/frontend/src/components/profile/ProfileEdit.vue @@ -161,7 +161,7 @@ import { includes } from "lodash"; import debugLib from "debug"; import { fetchCurrentUser, hasPhoto } from "@/utils"; -import { store } from "@/store"; +import store from "@/store"; const debug = debugLib("cl8.ProfileEdit"); Vue.use(Vuex); @@ -192,7 +192,7 @@ export default { return this.profile.tags; }, fullTagList: function () { - return this.$store.getters.tagList; + return this.$store.getters.fullTagList; }, profileClusters: function () { return this.profile.clusters; @@ -207,6 +207,8 @@ export default { const currentUser = await fetchCurrentUser(VueStore); debug({ currentUser }); await VueStore.dispatch("fetchProfile", { id: currentUser.id }); + await VueStore.dispatch("fetchTags"); + await VueStore.dispatch("fetchClusters"); } catch (error) { debug("Error fetching current user", error); } diff --git a/frontend/src/store.js b/frontend/src/store.js index 5cad0011..3590ff9d 100644 --- a/frontend/src/store.js +++ b/frontend/src/store.js @@ -77,8 +77,13 @@ const getters = { fullTagList: function (state) { // check for unsaved tags on the profile, and include // them if they are there + debug("getters:fullTagList") + debug({searchTags: state.searchTags}) + // debug({fullTags: state.fullTagList}) if (state.profile) { + debug({searchTags: state.searchTags}) const combined = state.fullTagList.concat(state.profile.tags) + debug({combined}) return dedupedTagList(combined) } else { @@ -386,31 +391,31 @@ const actions = { updateProfile: async function (context, payload) { debug('sending update to API', payload) - // doing this round trip returns a JSON object we - // can save back to the realtime database more easily, - // and strips out properties we wouldn't want to save into it - payload.tags = payload.tags.map(function (obj) { + // make a copy, so when we mutate it to send along, + // we don't affect the state that the page is relying on + const profilePayload = JSON.parse(JSON.stringify(payload)) + + profilePayload.tags = profilePayload.tags.map(function (obj) { return obj.name }) - payload.clusters = payload.clusters.map(function (obj) { + profilePayload.clusters = profilePayload.clusters.map(function (obj) { return obj.name }) // add the http(s) if missing if (payload.website) { - payload.website = linkify(payload.website) + profilePayload.website = linkify(profilePayload.website) } - const token = context.getters.token const profileId = payload.id - const profile = await instance.put(`/api/profiles/${profileId}/`, payload, { + const profile = await instance.put(`/api/profiles/${profileId}/`, profilePayload, { headers: { Authorization: `Token ${token}` } }) - + debug({profile}) if (profile) { context.commit('SET_PROFILE', profile.data) context.dispatch('fetchprofileList')