Skip to content

Commit

Permalink
Update edit view to show correct tags and clusters
Browse files Browse the repository at this point in the history
  • Loading branch information
mrchrisadams committed Jan 26, 2021
1 parent c690c04 commit a672649
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 11 deletions.
6 changes: 4 additions & 2 deletions frontend/src/components/profile/ProfileEdit.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand All @@ -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);
}
Expand Down
23 changes: 14 additions & 9 deletions frontend/src/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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')
Expand Down

0 comments on commit a672649

Please sign in to comment.