Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable refresh button while API call is in progress #154

Merged
merged 3 commits into from
Nov 11, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions securedrop_client/gui/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ def setup(self, window, controller):
self.window = window
self.controller = controller

self.controller.sync_events.connect(self._on_sync_event)

def set_logged_in_as(self, username):
"""
Update the UI to reflect that the user is logged in as "username".
Expand Down Expand Up @@ -103,6 +105,12 @@ def on_refresh_clicked(self):
"""
self.controller.sync_api()

def _on_sync_event(self, data):
"""
Called when the refresh call completes
"""
self.refresh.setEnabled(data != 'syncing')


class MainView(QWidget):
"""
Expand Down
4 changes: 4 additions & 0 deletions securedrop_client/logic.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ class Client(QObject):
application, this is the controller.
"""

sync_events = pyqtSignal(str)

def __init__(self, hostname, gui, session,
home: str, proxy: bool = True) -> None:
"""
Expand Down Expand Up @@ -345,6 +347,7 @@ def sync_api(self):
"""
logger.debug("In sync_api on thread {}".format(
self.thread().currentThreadId()))
self.sync_events.emit('syncing')

if self.authenticated():
logger.debug("You are authenticated, going to make your call")
Expand All @@ -367,6 +370,7 @@ def on_synced(self, result):
"""
Called when syncronisation of data via the API is complete.
"""
self.sync_events.emit('synced')
if isinstance(result, tuple):
remote_sources, remote_submissions, remote_replies = \
result
Expand Down
11 changes: 11 additions & 0 deletions tests/gui/test_widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,17 @@ def test_ToolBar_on_refresh_clicked():
tb.controller.sync_api.assert_called_once_with()


def test_ToolBar_sync_event():
"""Toggles refresh button when syncing
"""
tb = ToolBar(None)
tb._on_sync_event('syncing')
assert not tb.refresh.isEnabled()

tb._on_sync_event('synced')
assert tb.refresh.isEnabled()


def test_MainView_init():
"""
Ensure the MainView instance is correctly set up.
Expand Down