Skip to content

Commit

Permalink
Finish implementing logout and refresh
Browse files Browse the repository at this point in the history
  • Loading branch information
IAmPicard committed Oct 20, 2017
1 parent 6f77c4a commit b732683
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 9 deletions.
2 changes: 1 addition & 1 deletion STTApi
1 change: 1 addition & 0 deletions src/assets/css/App.css
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@
text-align: center;
font-family: LCARS, "Helvetica Neue", Helvetica, Arial, sans-serif;
font-size: 28px;
line-height: 40px;
}

.image-disabled {
Expand Down
19 changes: 17 additions & 2 deletions src/components/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ class App extends React.Component {
this._captainButtonElement = null;
this._onAccessToken = this._onAccessToken.bind(this);
this._onLogout = this._onLogout.bind(this);
this._onRefresh = this._onRefresh.bind(this);
this._getCommandItems = this._getCommandItems.bind(this);
this._onShare = this._onShare.bind(this);
this._onCaptainClicked = this._onCaptainClicked.bind(this);
Expand All @@ -96,6 +97,11 @@ class App extends React.Component {
}

_onCaptainClicked() {
if (!STTApi.loggedIn) {
this._onLogout();
return;
}

if (!this.state.showSpinner)
this.setState({ isCaptainCalloutVisible: !this.state.isCaptainCalloutVisible });
}
Expand Down Expand Up @@ -140,7 +146,7 @@ class App extends React.Component {
onDismiss={this._onCaptainCalloutDismiss}
setInitialFocus={true}
>
<CaptainCard captainAvatarBodyUrl={this.state.captainAvatarBodyUrl} onLogout={this._onLogout} />
<CaptainCard captainAvatarBodyUrl={this.state.captainAvatarBodyUrl} onLogout={this._onLogout} onRefresh={this._onRefresh} />
</Callout>
)}
</div>
Expand Down Expand Up @@ -317,8 +323,17 @@ class App extends React.Component {
}

_onLogout() {
// TODO: Implement a logout in STTApi itself to clear out any old data before proceeding
this.setState({ isCaptainCalloutVisible: false });
STTApi.refreshEverything(true);
this.setState({ showLoginDialog: true, dataLoaded: false, captainName: 'Welcome!', spinnerLabel: 'Loading...', secondLine: ''});
this.refs.loginDialog._showDialog('');
}

_onRefresh() {
this.setState({ isCaptainCalloutVisible: false });
STTApi.refreshEverything(false);
this.setState({ dataLoaded: false, spinnerLabel: 'Refreshing...'});
this._onAccessToken();
}

_onDataError(reason) {
Expand Down
10 changes: 5 additions & 5 deletions src/components/CaptainCard.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ import { CONFIG } from 'sttapi';

export class CaptainCard extends React.Component {
render() {
if (!STTApi.loggedIn) {
return <span/>;
}

return (<div className="ui inverted segment">
<div className="ui two column grid">
<div className="row">
Expand Down Expand Up @@ -57,11 +61,7 @@ export class CaptainCard extends React.Component {
</div>
</div>
<button className="ui primary button" onClick={() => this.props.onLogout()}><i className="icon sign out"></i>Logout</button>
<button className="ui primary button" onClick={() => this.setState({ loggedIn: false })}><i className="icon refresh"></i>Refresh inventory</button>
<br />
<div className="ui">
<i>Note:</i> refershing the inventory will <b>not</b> recalculate crew recommendations. Please restart the app for that!
</div>
<button className="ui primary button" onClick={() => this.props.onRefresh()}><i className="icon refresh"></i>Refresh everything</button>
</div>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion src/components/GauntletHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ export class GauntletHelper extends React.Component {
<Label>Crew refeshes in {Math.floor(this.state.gauntlet.seconds_to_next_crew_refresh / 60)} minutes and the gauntlet ends in {Math.floor(this.state.gauntlet.seconds_to_end / 60)} minutes</Label>
<Label>Your rank is {this.state.roundOdds.rank} and you have {this.state.roundOdds.consecutive_wins} consecutive wins</Label>
<span><h3>Your crew stats <DefaultButton onClick={this._reloadGauntletData} text='Reload data' iconProps={{ iconName: 'Refresh' }} /></h3></span>
<div style={{ display: 'flex' }} >
<div style={{ display: 'flex', width: '95%' }} >
{this.state.gauntlet.contest_data.selected_crew.map(function (crew) {
return <GauntletCrew key={crew.crew_id} crew={crew} />;
})}
Expand Down

0 comments on commit b732683

Please sign in to comment.