From 7c6446a9dea2a221da643414e87a97d17336215f Mon Sep 17 00:00:00 2001 From: dave Date: Wed, 27 Feb 2019 14:38:10 -0500 Subject: #388: get follow request on a real-time basis --- src/components/nav_panel/nav_panel.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'src/components/nav_panel/nav_panel.js') diff --git a/src/components/nav_panel/nav_panel.js b/src/components/nav_panel/nav_panel.js index ea5d7ea4..c4034417 100644 --- a/src/components/nav_panel/nav_panel.js +++ b/src/components/nav_panel/nav_panel.js @@ -1,10 +1,23 @@ +import requestFetcher from '../../services/notifications_fetcher/request_fetcher.service.js' + const NavPanel = { + created () { + if (this.currentUser && this.currentUser.locked) { + const store = this.$store + const credentials = store.state.users.currentUser.credentials + + requestFetcher.startFetching({ store, credentials }) + } + }, computed: { currentUser () { return this.$store.state.users.currentUser }, chat () { return this.$store.state.chat.channel + }, + followRequestCount () { + return this.$store.state.api.followRequests.length } } } -- cgit v1.2.3-70-g09d2 From cccf33d6ddc48038e643e651bd4cddc3355dbf18 Mon Sep 17 00:00:00 2001 From: dave Date: Thu, 28 Feb 2019 12:53:37 -0500 Subject: #388: update naming properly --- src/components/nav_panel/nav_panel.js | 4 ++-- .../follow_request_fetcher.service.js | 21 +++++++++++++++++++++ .../request_fetcher.service.js | 21 --------------------- 3 files changed, 23 insertions(+), 23 deletions(-) create mode 100644 src/services/follow_request_fetcher/follow_request_fetcher.service.js delete mode 100644 src/services/notifications_fetcher/request_fetcher.service.js (limited to 'src/components/nav_panel/nav_panel.js') diff --git a/src/components/nav_panel/nav_panel.js b/src/components/nav_panel/nav_panel.js index c4034417..aa3f7605 100644 --- a/src/components/nav_panel/nav_panel.js +++ b/src/components/nav_panel/nav_panel.js @@ -1,4 +1,4 @@ -import requestFetcher from '../../services/notifications_fetcher/request_fetcher.service.js' +import followRequestFetcher from '../../services/follow_request_fetcher/follow_request_fetcher.service' const NavPanel = { created () { @@ -6,7 +6,7 @@ const NavPanel = { const store = this.$store const credentials = store.state.users.currentUser.credentials - requestFetcher.startFetching({ store, credentials }) + followRequestFetcher.startFetching({ store, credentials }) } }, computed: { diff --git a/src/services/follow_request_fetcher/follow_request_fetcher.service.js b/src/services/follow_request_fetcher/follow_request_fetcher.service.js new file mode 100644 index 00000000..125ff3e1 --- /dev/null +++ b/src/services/follow_request_fetcher/follow_request_fetcher.service.js @@ -0,0 +1,21 @@ +import apiService from '../api/api.service.js' + +const fetchAndUpdate = ({ store, credentials }) => { + return apiService.fetchFollowRequests({ credentials }) + .then((requests) => { + store.commit('setFollowRequests', requests) + }, () => {}) + .catch(() => {}) +} + +const startFetching = ({credentials, store}) => { + fetchAndUpdate({ credentials, store }) + const boundFetchAndUpdate = () => fetchAndUpdate({ credentials, store }) + return setInterval(boundFetchAndUpdate, 10000) +} + +const followRequestFetcher = { + startFetching +} + +export default followRequestFetcher diff --git a/src/services/notifications_fetcher/request_fetcher.service.js b/src/services/notifications_fetcher/request_fetcher.service.js deleted file mode 100644 index beb6c320..00000000 --- a/src/services/notifications_fetcher/request_fetcher.service.js +++ /dev/null @@ -1,21 +0,0 @@ -import apiService from '../api/api.service.js' - -const fetchAndUpdate = ({ store, credentials }) => { - return apiService.fetchFollowRequests({ credentials }) - .then((requests) => { - store.commit('setFollowRequests', requests) - }, () => {}) - .catch(() => {}) -} - -const startFetching = ({credentials, store}) => { - fetchAndUpdate({ credentials, store }) - const boundFetchAndUpdate = () => fetchAndUpdate({ credentials, store }) - return setInterval(boundFetchAndUpdate, 10000) -} - -const requestFetcher = { - startFetching -} - -export default requestFetcher -- cgit v1.2.3-70-g09d2