aboutsummaryrefslogtreecommitdiffstats
path: root/src/stores/NewsStore.js
diff options
context:
space:
mode:
authorLibravatar Markus Hatvan <markus_hatvan@aon.at>2021-10-14 18:20:26 +0200
committerLibravatar GitHub <noreply@github.com>2021-10-14 18:20:26 +0200
commitc27972c12b2d0dba2aee9e3dcffadcf7806a9afd (patch)
tree46fcfe261ae55e6faab604e9c75f94f6ffe326ee /src/stores/NewsStore.js
parentchore: upgrade 'electron-builder' to '22.14.5' to fix upstream issues. (#2068) (diff)
downloadferdium-app-c27972c12b2d0dba2aee9e3dcffadcf7806a9afd.tar.gz
ferdium-app-c27972c12b2d0dba2aee9e3dcffadcf7806a9afd.tar.zst
ferdium-app-c27972c12b2d0dba2aee9e3dcffadcf7806a9afd.zip
chore: remove all code related to news (#2069)
Diffstat (limited to 'src/stores/NewsStore.js')
-rw-r--r--src/stores/NewsStore.js55
1 files changed, 0 insertions, 55 deletions
diff --git a/src/stores/NewsStore.js b/src/stores/NewsStore.js
deleted file mode 100644
index 66a17cb29..000000000
--- a/src/stores/NewsStore.js
+++ /dev/null
@@ -1,55 +0,0 @@
1import { computed, observable } from 'mobx';
2import { remove } from 'lodash';
3
4import Store from './lib/Store';
5import CachedRequest from './lib/CachedRequest';
6import Request from './lib/Request';
7import { CHECK_INTERVAL } from '../config';
8
9export default class NewsStore extends Store {
10 @observable latestNewsRequest = new CachedRequest(this.api.news, 'latest');
11
12 @observable hideNewsRequest = new Request(this.api.news, 'hide');
13
14 constructor(...args) {
15 super(...args);
16
17 // Register action handlers
18 this.actions.news.hide.listen(this._hide.bind(this));
19 this.actions.user.logout.listen(this._resetNewsRequest.bind(this));
20 }
21
22 setup() {
23 // Check for news updates every couple of hours
24 setInterval(() => {
25 if (this.latestNewsRequest.wasExecuted && this.stores.user.isLoggedIn) {
26 this.latestNewsRequest.invalidate({ immediately: true });
27 }
28 }, CHECK_INTERVAL);
29 }
30
31 @computed get latest() {
32 return this.latestNewsRequest.execute().result || [];
33 }
34
35 // Actions
36 _hide({ newsId }) {
37 this.hideNewsRequest.execute(newsId);
38
39 this.latestNewsRequest.invalidate().patch((result) => {
40 // TODO: check if we can use mobx.array remove
41 remove(result, (n) => n.id === newsId);
42 });
43 }
44
45 /**
46 * Reset the news request when current user logs out so that when another user
47 * logs in again without an app restart, the request will be fetched again and
48 * the news will be shown to the user.
49 *
50 * @private
51 */
52 _resetNewsRequest() {
53 this.latestNewsRequest.reset();
54 }
55}