Skip to content

Commit

Permalink
Save profile data to localStorage using get & set
Browse files Browse the repository at this point in the history
Saving all the profile data like, name, email and image to the localStorage.
  • Loading branch information
mittalyashu committed Apr 18, 2019
1 parent 5ebc7e3 commit 809748d
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 0 deletions.
36 changes: 36 additions & 0 deletions src/renderer/pages/settings/profile.vue
Expand Up @@ -13,18 +13,21 @@
/>
</div>
<inputTextLabel
v-model="authorName"
label="Name"
placeholder="Enter your name"
name="profile_name"
class="profile__field"
/>
<inputTextLabel
v-model="authorEmail"
label="Email"
placeholder="Enter your email address"
name="profile_email"
class="profile__field"
/>
<inputTextLabel
v-model="authorImage"
label="Image"
placeholder="Paste your image"
name="profile_image"
Expand All @@ -46,6 +49,39 @@ export default {
computed: {
profileData() {
return this.$store.getters["settings/getProfile"];
},
authorName: {
get: function() {
return this.profileData.author.name;
},
set: function(value) {
this.$store.dispatch({
type: "settings/updateAuthorName",
name: value
});
}
},
authorEmail: {
get: function() {
return this.profileData.author.email;
},
set: function(value) {
this.$store.dispatch({
type: "settings/updateAuthorEmail",
email: value
});
}
},
authorImage: {
get: function() {
return this.profileData.author.imageUrl;
},
set: function(value) {
this.$store.dispatch({
type: "settings/updateAuthorImage",
image: value
});
}
}
}
};
Expand Down
39 changes: 39 additions & 0 deletions src/renderer/store/modules/settings.js
Expand Up @@ -23,12 +23,51 @@ const mutations = {
state.experimental = JSON.parse(localStorage.getItem("settings")).experimental;
}
},
setSettings(state) {
localStorage.setItem("settings", JSON.stringify(state));
},
authorName(state, payload) {
state.profile.author.name = payload.name;
},
authorEmail(state, payload) {
state.profile.author.email = payload.email;
},
authorImage(state, payload) {
state.profile.author.imageUrl = payload.image;
},
toggleFileChanges(state, payload) {
state.experimental.fileChanges = payload.fileChanges;
}
};

const actions = {
updateAuthorName: ({ commit }, payload) => {
commit({
type: "authorName",
name: payload.name
});
commit({
type: "setSettings"
});
},
updateAuthorEmail: ({ commit }, payload) => {
commit({
type: "authorEmail",
email: payload.email
});
commit({
type: "setSettings"
});
},
updateAuthorImage: ({ commit }, payload) => {
commit({
type: "authorImage",
image: payload.image
});
commit({
type: "setSettings"
});
},
updateFileChanges: ({ commit }, payload) => {
commit({
type: "toggleFileChanges",
Expand Down

0 comments on commit 809748d

Please sign in to comment.