From daa674c54f63a2f9661d2856399363a007bb5512 Mon Sep 17 00:00:00 2001 From: Max G Date: Fri, 14 Feb 2020 01:08:46 +0000 Subject: [PATCH] Added some realtime events to the app * When a user gets a new shared message, it will popup instantly * When a new website is scraped, it will update in real time * Various other little bug fixes and improvements * Sharing displays correct notes and handles shared notes correctly * Tags were not displaying on notes, they do now. They better. --- client/src/App.vue | 19 ++- .../components/AnimatedCounterComponent.vue | 113 ++++++++++++++++++ client/src/components/GlobalSiteMenu.vue | 7 +- .../src/components/NoteTitleDisplayCard.vue | 4 + client/src/pages/NotesPage.vue | 36 ++++-- server/index.js | 12 ++ server/models/Attachment.js | 11 +- server/models/Note.js | 25 +++- server/models/QuickNote.js | 2 +- server/models/ShareNote.js | 42 +++++-- server/models/Tag.js | 6 +- server/models/User.js | 2 +- server/routes/attachmentController.js | 2 +- server/routes/noteController.js | 12 +- 14 files changed, 247 insertions(+), 46 deletions(-) create mode 100644 client/src/components/AnimatedCounterComponent.vue diff --git a/client/src/App.vue b/client/src/App.vue index 4c6b7a8..ac34488 100644 --- a/client/src/App.vue +++ b/client/src/App.vue @@ -27,10 +27,17 @@ export default { }, beforeCreate: function(){ + //Puts token into state on page load + let token = localStorage.getItem('loginToken') + let username = localStorage.getItem('username') + // const socket = io({ path:'/socket' }); const socket = this.$io socket.on('connect', () => { + this.$store.commit('setSocketIoSocket', socket.id) + + this.$io.emit('user_connect', token) }) //Detect if user is on a mobile browser and set a flag in store @@ -41,16 +48,20 @@ export default { this.$store.commit('toggleNightMode') } - //Puts token into state on page load - let token = localStorage.getItem('loginToken') - let username = localStorage.getItem('username') - + //Put user data into global store on load if(token){ this.$store.commit('setLoginToken', {token, username}) } }, mounted: function(){ + + //Update totals for entire app on event + this.$io.on('update_counts', () => { + console.log('Got event, update totals') + this.$store.dispatch('fetchAndUpdateUserTotals') + }) + }, computed: { loggedIn () { diff --git a/client/src/components/AnimatedCounterComponent.vue b/client/src/components/AnimatedCounterComponent.vue new file mode 100644 index 0000000..276bd99 --- /dev/null +++ b/client/src/components/AnimatedCounterComponent.vue @@ -0,0 +1,113 @@ + + + + + diff --git a/client/src/components/GlobalSiteMenu.vue b/client/src/components/GlobalSiteMenu.vue index 63c998f..6028eea 100644 --- a/client/src/components/GlobalSiteMenu.vue +++ b/client/src/components/GlobalSiteMenu.vue @@ -21,7 +21,7 @@ .menu-item { color: #fff; - padding: 0.8em 0px 0.8em 10px; + padding: 0.8em 10px 0.8em 10px; display: inline-block; width: 100%; font-size: 1.15em; @@ -154,7 +154,7 @@