diff --git a/package-lock.json b/package-lock.json index 71c2633..b6926a5 100644 --- a/package-lock.json +++ b/package-lock.json @@ -7507,6 +7507,11 @@ "integrity": "sha512-j3TBDtjqz7pC9XUzeSeqF5oekqPahxyUHsdG+kZKDH/V/DTexq5inYdLGstnqCUljoLC9LTj3H/5hmyToeSd1A==", "dev": true }, + "vuex": { + "version": "2.3.1", + "resolved": "https://registry.npmjs.org/vuex/-/vuex-2.3.1.tgz", + "integrity": "sha1-zejpl8H5lXcZvH3qFU+appHZgaY=" + }, "watchpack": { "version": "1.4.0", "resolved": "https://registry.npmjs.org/watchpack/-/watchpack-1.4.0.tgz", diff --git a/package.json b/package.json index 80e1ee5..d849a41 100644 --- a/package.json +++ b/package.json @@ -38,8 +38,9 @@ "slug": "^0.9.1", "socket.io": "^2.0.3", "socket.io-client": "^2.0.3", - "yargs": "^8.0.2", - "vue": "^2.3.3" + "vue": "^2.3.3", + "vuex": "^2.3.1", + "yargs": "^8.0.2" }, "devDependencies": { "babel-core": "^6.22.1", diff --git a/site/src/components/application/script.js b/site/src/components/application/script.js index e2ec9b7..64403c8 100644 --- a/site/src/components/application/script.js +++ b/site/src/components/application/script.js @@ -1,32 +1,33 @@ -import socketIoClient from 'socket.io-client' +import Connexion from '@/components/connexion' +import ProjectsHub from '@/components/projects-hub' export default { name: 'application', + components: + { + Connexion, + ProjectsHub + }, + data() { return { - counter: 0, - projects: { type: Object, value: {} } + counter: 0 + } + }, + + computed: + { + projects() + { + return this.$store.state.projects } }, mounted() { - const socketUrl = `${process.env.NODE_ENV === 'production' ? '' : 'http://localhost:1571'}/projects` - const socket = socketIoClient(socketUrl) - - socket.on('connect', () => - { - console.log('connected') - }) - - socket.on('update_projects', (data) => - { - this.projects = data.all - }) - window.setInterval(() => { this.counter++ diff --git a/site/src/components/application/style.styl b/site/src/components/application/style.styl index 9c7742e..e69de29 100644 --- a/site/src/components/application/style.styl +++ b/site/src/components/application/style.styl @@ -1,2 +0,0 @@ -#application - background #f0f \ No newline at end of file diff --git a/site/src/components/application/template.html b/site/src/components/application/template.html index 619ad97..47e512a 100644 --- a/site/src/components/application/template.html +++ b/site/src/components/application/template.html @@ -1,6 +1,5 @@
{{ counter }} -
- {{ project.name }} -
+ +
\ No newline at end of file diff --git a/site/src/components/connexion/index.vue b/site/src/components/connexion/index.vue new file mode 100644 index 0000000..a6fe49a --- /dev/null +++ b/site/src/components/connexion/index.vue @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/site/src/components/connexion/script.js b/site/src/components/connexion/script.js new file mode 100644 index 0000000..689f432 --- /dev/null +++ b/site/src/components/connexion/script.js @@ -0,0 +1,22 @@ +import socketIoClient from 'socket.io-client' + +export default +{ + name: 'connexion', + + created() + { + this.url = `${process.env.NODE_ENV === 'production' ? '' : 'http://localhost:1571'}/projects` + this.socket = socketIoClient(this.url) + + this.socket.on('connect', () => + { + console.log('connected') + }) + + this.socket.on('update_projects', (data) => + { + this.$store.commit('updateProjects', data.all) + }) + } +} \ No newline at end of file diff --git a/site/src/components/connexion/style.styl b/site/src/components/connexion/style.styl new file mode 100644 index 0000000..e69de29 diff --git a/site/src/components/connexion/template.html b/site/src/components/connexion/template.html new file mode 100644 index 0000000..094418b --- /dev/null +++ b/site/src/components/connexion/template.html @@ -0,0 +1,2 @@ +
+
\ No newline at end of file diff --git a/site/src/components/projects-hub/index.vue b/site/src/components/projects-hub/index.vue new file mode 100644 index 0000000..a6fe49a --- /dev/null +++ b/site/src/components/projects-hub/index.vue @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/site/src/components/projects-hub/script.js b/site/src/components/projects-hub/script.js new file mode 100644 index 0000000..436d850 --- /dev/null +++ b/site/src/components/projects-hub/script.js @@ -0,0 +1,17 @@ +export default +{ + name: 'projects-hub', + + computed: + { + projects() + { + return this.$store.state.projects + } + }, + + created() + { + + } +} \ No newline at end of file diff --git a/site/src/components/projects-hub/style.styl b/site/src/components/projects-hub/style.styl new file mode 100644 index 0000000..e69de29 diff --git a/site/src/components/projects-hub/template.html b/site/src/components/projects-hub/template.html new file mode 100644 index 0000000..777ef0b --- /dev/null +++ b/site/src/components/projects-hub/template.html @@ -0,0 +1,5 @@ +
+ + {{ project.name }} + +
\ No newline at end of file diff --git a/site/src/main.js b/site/src/main.js index a6efff0..6f3d431 100644 --- a/site/src/main.js +++ b/site/src/main.js @@ -2,12 +2,14 @@ // (runtime-only or standalone) has been set in webpack.base.conf with an alias. import Vue from 'vue' import App from '@/components/application/' +import store from '@/store.js' Vue.config.productionTip = false /* eslint-disable no-new */ new Vue({ el: '#app', + store, template: '', components: { App } }) diff --git a/site/src/store.js b/site/src/store.js new file mode 100644 index 0000000..0261170 --- /dev/null +++ b/site/src/store.js @@ -0,0 +1,33 @@ +import Vue from 'vue' +import Vuex from 'vuex' +Vue.use(Vuex) + +export default new Vuex.Store({ + state: + { + projects: [], + currentProject: null + }, + + mutations: + { + updateProjects(state, data) + { + for(const key in data) + { + const project = data[key] + state.projects.push(project) + } + }, + + addProject(state, data) + { + state.projects.push(data) + }, + + removeProject(state, data) + { + console.log(data) + } + } +}) \ No newline at end of file