Site > Add projects selection

This commit is contained in:
brunosimon
2017-08-04 21:30:53 +02:00
parent eec6f8a796
commit 02a59ba5be
5 changed files with 45 additions and 7 deletions
@@ -23,6 +23,11 @@ export default
projects() projects()
{ {
return this.$store.state.projects return this.$store.state.projects
},
project()
{
return this.$store.state.currentProject
} }
}, },
@@ -2,4 +2,7 @@
{{ counter }} {{ counter }}
<connexion></connexion> <connexion></connexion>
<projects-hub></projects-hub> <projects-hub></projects-hub>
<div v-if="project">
{{ project.name }}
</div>
</div> </div>
@@ -13,5 +13,13 @@ export default
created() created()
{ {
},
methods:
{
onProjectClick(projectSlug)
{
this.$store.commit('setCurrentProject', projectSlug)
}
} }
} }
@@ -1,5 +1,5 @@
<div> <div>
<a :href="project.slug" v-for="project in projects"> <a href="#" v-for="project in projects" @click.prevent="onProjectClick(project.slug)">
{{ project.name }} {{ project.name }}
</a> </a>
</div> </div>
+28 -6
View File
@@ -5,7 +5,7 @@ Vue.use(Vuex)
export default new Vuex.Store({ export default new Vuex.Store({
state: state:
{ {
projects: [], projects: {},
currentProject: null currentProject: null
}, },
@@ -13,10 +13,28 @@ export default new Vuex.Store({
{ {
updateProjects(state, data) updateProjects(state, data)
{ {
for(const key in data) state.projects = data
// Has a current project
if(state.currentProject)
{ {
const project = data[key] // Current project has been removed
state.projects.push(project) if(typeof state.projects[data] === 'undefined')
{
state.currentProject = null
}
}
// No current project
else
{
const projectKeys = Object.keys(state.projects)
// If only one project, set has current
if(projectKeys.length === 1)
{
state.currentProject = state.projects[projectKeys[0]]
}
} }
}, },
@@ -25,9 +43,13 @@ export default new Vuex.Store({
state.projects.push(data) state.projects.push(data)
}, },
removeProject(state, data) setCurrentProject(state, data)
{ {
console.log(data) // Test of project exist
if(typeof state.projects[data] !== 'undefined')
{
state.currentProject = state.projects[data]
}
} }
} }
}) })