diff --git a/site/src/components/application/script.js b/site/src/components/application/script.js index 64403c8..dafe547 100644 --- a/site/src/components/application/script.js +++ b/site/src/components/application/script.js @@ -23,6 +23,11 @@ export default projects() { return this.$store.state.projects + }, + + project() + { + return this.$store.state.currentProject } }, diff --git a/site/src/components/application/template.html b/site/src/components/application/template.html index 47e512a..085c035 100644 --- a/site/src/components/application/template.html +++ b/site/src/components/application/template.html @@ -2,4 +2,7 @@ {{ counter }} +
+ {{ project.name }} +
\ No newline at end of file diff --git a/site/src/components/projects-hub/script.js b/site/src/components/projects-hub/script.js index 436d850..06fc99d 100644 --- a/site/src/components/projects-hub/script.js +++ b/site/src/components/projects-hub/script.js @@ -13,5 +13,13 @@ export default created() { + }, + + methods: + { + onProjectClick(projectSlug) + { + this.$store.commit('setCurrentProject', projectSlug) + } } } \ No newline at end of file diff --git a/site/src/components/projects-hub/template.html b/site/src/components/projects-hub/template.html index 777ef0b..badcf9f 100644 --- a/site/src/components/projects-hub/template.html +++ b/site/src/components/projects-hub/template.html @@ -1,5 +1,5 @@
- + {{ project.name }}
\ No newline at end of file diff --git a/site/src/store.js b/site/src/store.js index 0261170..471b758 100644 --- a/site/src/store.js +++ b/site/src/store.js @@ -5,7 +5,7 @@ Vue.use(Vuex) export default new Vuex.Store({ state: { - projects: [], + projects: {}, currentProject: null }, @@ -13,10 +13,28 @@ export default new Vuex.Store({ { updateProjects(state, data) { - for(const key in data) + state.projects = data + + // Has a current project + if(state.currentProject) { - const project = data[key] - state.projects.push(project) + // Current project has been removed + 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) }, - removeProject(state, data) + setCurrentProject(state, data) { - console.log(data) + // Test of project exist + if(typeof state.projects[data] !== 'undefined') + { + state.currentProject = state.projects[data] + } } } }) \ No newline at end of file