Skip to content

Commit

Permalink
Merge pull request #154 from timruffles/refresh-disable
Browse files Browse the repository at this point in the history
Disable refresh button while API call is in progress
  • Loading branch information
redshiftzero authored Nov 11, 2018
2 parents 17f055b + 2d756ec commit aa91eeb
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
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

0 comments on commit aa91eeb

Please sign in to comment.