forked from binxhealth/force-vue-awakens
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
binxhealth#3 added person profile page. Still need to add links to re…
…lated resources
Showing
3 changed files
with
99 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,64 +1,81 @@ | ||
<template> | ||
<div> | ||
<h1 @change="updatePersonAttributes">{{ attributes.name }} </h1> | ||
<div class="container"> | ||
<h1>{{results.name}}</h1> | ||
|
||
<ul class="list-group"> | ||
<li class="list-group-item">Birth year: {{ results.birth_year }}</li> | ||
<li class="list-group-item">Height: {{ results.height }}</li> | ||
<li class="list-group-item">Mass: {{ results.mass }}</li> | ||
<li class="list-group-item">Eye color: {{ results.eye_color }}</li> | ||
<li class="list-group-item">Skin color: {{ results.skin_color }}</li> | ||
</ul> | ||
<div class="row pt-3 pl-3"> | ||
<router-link | ||
:to="`/`"> | ||
<button>Return home</button> | ||
</router-link> | ||
</div> | ||
</div> | ||
</template> | ||
|
||
<script> | ||
import { mapGetters, mapActions } from 'vuex' | ||
import { mapGetters, mapActions, mapState } from 'vuex' | ||
import store from '@/store' | ||
export default { | ||
async beforeRouteEnter (to, from, next) { | ||
const action = await store.dispatch('people/getPerson', to.params.id) | ||
const json = await action.json() | ||
if(action.ok) { | ||
console.log(json.name) | ||
//attributes.name = json.name | ||
next(vm => vm.updatePersonAttributes(json)) | ||
} else { | ||
// If the response from the API is not ok, then we redirect to 404 page | ||
next ( | ||
{ | ||
path: '404' | ||
} | ||
) | ||
} | ||
await store.dispatch('people/getPerson', to.params.id) | ||
next() | ||
// if(action.ok) { | ||
// // const person = getResults | ||
// // attributes.name = json.name | ||
// // (vm => vm.updatePersonAttributes(action)) | ||
// next() | ||
// } else { | ||
// // If the response from the API is not ok, then we redirect to 404 page | ||
// next ( | ||
// { | ||
// path: '404' | ||
// } | ||
// ) | ||
// } | ||
}, | ||
async beforeRouteUpdate (to, from, next) { | ||
const action = await store.dispatch('people/getPerson', to.params.id) | ||
const json = await action.json() | ||
if(action.ok) { | ||
console.log('Name of person: ' + json.name) | ||
//attributes.name = json.name | ||
next(vm => vm.updatePersonAttributes(json)) | ||
} else { | ||
next({ | ||
path: '/' | ||
}) | ||
this.$notify({ | ||
group: 'notifs', | ||
title: 'Error', | ||
type: 'warn', | ||
text: 'Person ' + to.params.id + ' not found.' | ||
}) | ||
} | ||
}, | ||
data: function() { | ||
return { | ||
attributes: { | ||
name: '' | ||
} | ||
} | ||
}, | ||
methods: { | ||
...mapActions('getPerson', ['people/getPerson']), | ||
updatePersonAttributes(json) { | ||
this.attributes.name = json.name | ||
}, | ||
await store.dispatch('people/getPerson', to.params.id) | ||
next() | ||
// console.log(action) | ||
// console.log("Store.state: " + store.state.people.results) | ||
// if(action.ok) { | ||
// // const person = getResults() | ||
// // console.log(person) | ||
// //attributes.name = json.name | ||
// //next(vm => vm.updatePersonAttributes(action)) | ||
// next() | ||
// } else { | ||
// next({ | ||
// path: '/' | ||
// }) | ||
// this.$notify({ | ||
// group: 'notifs', | ||
// title: 'Error', | ||
// type: 'warn', | ||
// text: 'Person ' + to.params.id + ' not found.' | ||
// }) | ||
// } | ||
}, | ||
// data: function() { | ||
// return { | ||
// attributes: { | ||
// name: '' | ||
// } | ||
// } | ||
// }, | ||
// methods: { | ||
// ...mapActions('attributes'), | ||
// }, | ||
computed: { | ||
...mapGetters('people', ['person']) | ||
...mapState('people', ['results']) | ||
} | ||
} | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters