summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormo khan <mo@mokhan.ca>2016-12-22 09:50:03 -0700
committermo khan <mo@mokhan.ca>2016-12-22 09:50:03 -0700
commitb6d9bef603bc789d085226bf66e4e943fd55e00e (patch)
treeaacb43889854bd56e8b8d66ea28c0a8dd77ef1d3
parent5604916a86d1da6cb127e466a0ae5c0bb52e4fd5 (diff)
extract logout command.
-rw-r--r--app/commands/index.js2
-rw-r--r--app/commands/logout-command.js13
-rw-r--r--app/screens/dashboard-screen.js6
3 files changed, 17 insertions, 4 deletions
diff --git a/app/commands/index.js b/app/commands/index.js
index 153ffbd..9560f09 100644
--- a/app/commands/index.js
+++ b/app/commands/index.js
@@ -1,5 +1,7 @@
import LoginCommand from './login-command';
+import LogoutCommand from './logout-command';
export {
LoginCommand,
+ LogoutCommand,
};
diff --git a/app/commands/logout-command.js b/app/commands/logout-command.js
new file mode 100644
index 0000000..0586997
--- /dev/null
+++ b/app/commands/logout-command.js
@@ -0,0 +1,13 @@
+export default class LogoutCommand {
+ constructor(applicationStorage) {
+ this.applicationStorage = applicationStorage;
+ }
+
+ subscribeTo(eventAggregator) {
+ eventAggregator.subscribe('LOGOUT', this);
+ }
+
+ notify(event) {
+ this.applicationStorage.delete('authentication_token');
+ }
+}
diff --git a/app/screens/dashboard-screen.js b/app/screens/dashboard-screen.js
index f67d209..efeda01 100644
--- a/app/screens/dashboard-screen.js
+++ b/app/screens/dashboard-screen.js
@@ -25,7 +25,7 @@ export default class DashboardScreen extends ApplicationComponent {
return (
<Container>
<Header>
- <Title>Stronglifters {this.props.username}</Title>
+ <Title>{this.props.username}</Title>
<Button transparent rounded>
<Image source={{uri: gravatarUri}} style={{width: 32, height: 32}} />
</Button>
@@ -70,9 +70,7 @@ export default class DashboardScreen extends ApplicationComponent {
}
onLogout() {
- const storage = new ApplicationStorage();
- storage.delete('authentication_token');
- storage.delete('username');
+ this.publish({event: 'LOGOUT'})
this.props.navigator.pop();
}