From 898516a7fffced74a9b2fe9d5c19665d897591e4 Mon Sep 17 00:00:00 2001 From: Kochin Chang Date: Wed, 24 Mar 2021 10:49:11 -0400 Subject: [PATCH] Added update blocklist feature. --- .../PreferencesDialog/PeersTabPanel/index.js | 24 +++++++++++++++---- src/stores/session-store.js | 13 +++++++++- 2 files changed, 32 insertions(+), 5 deletions(-) diff --git a/src/components/dialogs/PreferencesDialog/PeersTabPanel/index.js b/src/components/dialogs/PreferencesDialog/PeersTabPanel/index.js index cb1f807..d8fd481 100644 --- a/src/components/dialogs/PreferencesDialog/PeersTabPanel/index.js +++ b/src/components/dialogs/PreferencesDialog/PeersTabPanel/index.js @@ -1,6 +1,9 @@ import React, { Component} from 'react'; import CSSModules from 'react-css-modules'; import { inject, observer } from 'mobx-react'; +import autobind from 'autobind-decorator'; + +import { Button } from 'react-toolbox/lib/button' import styles from '../styles/index.css'; @@ -9,10 +12,23 @@ import CheckRow from '../fields/CheckRow'; import CheckValueRow from '../fields/CheckValueRow'; import SelectRow from '../fields/SelectRow'; -@inject('view_store') +@inject('view_store', 'session_store') @observer @CSSModules(styles) class PeersTabPanel extends Component { + constructor(props) { + super(props); + this.state = { + blocklistSize: (this.props.session_store.blocklistSize == -1) ? '?' : this.props.session_store.blocklistSize, + }; + } + + @autobind updateBlocklist() { + this.props.session_store.updateBlocklist().then((size) => { + this.setState({ blocklistSize: size }); + }); + } + render() { const encryption = { tolerated: 'Allow encryption', @@ -36,11 +52,11 @@ class PeersTabPanel extends Component {

Blocklist

- +
-
Blocklist has ? rules
-
+
Blocklist has {this.state.blocklistSize} rules
+
); diff --git a/src/stores/session-store.js b/src/stores/session-store.js index cbe0aaf..b9ab602 100644 --- a/src/stores/session-store.js +++ b/src/stores/session-store.js @@ -4,7 +4,8 @@ class SessionStore { @observable sessionId = null; @observable settings = {}; @observable freeSpace = -1; // TODO: Decide if this should be in TorrentUpload - + @observable blocklistSize = -1; + constructor(rpc) { this.rpc = rpc; } @@ -82,6 +83,16 @@ class SessionStore { @action togglePreference(id) { return this.setPreference(id, !this.settings[id]); } + + @action updateBlocklist() { + return this.rpc.sendRequest('blocklist-update') + .then(action((response) => { + return response.json().then(action((result) => { + this.blocklistSize = result.arguments['blocklist-size']; + return this.blocklistSize; + })); + })); + } } export default SessionStore;