[MM-22494] Fixed misuse of config.set (#1191)

This commit is contained in:
Devin Binnie
2020-02-14 15:21:09 -05:00
committed by GitHub
parent c895535449
commit 4f7782fb88
2 changed files with 12 additions and 15 deletions

View File

@@ -769,13 +769,13 @@ export default class MainPage extends React.Component {
});
}}
onSave={(newTeam) => {
this.props.teams.push(newTeam);
this.setState({
showNewTeamModal: false,
key: this.props.teams.length - 1,
this.props.localTeams.push(newTeam);
this.props.onTeamConfigChange(this.props.localTeams, () => {
self.setState({
showNewTeamModal: false,
key: this.props.teams.length - 1,
});
});
this.render();
this.props.onTeamConfigChange(this.props.teams);
}}
/>
);
@@ -834,6 +834,7 @@ export default class MainPage extends React.Component {
MainPage.propTypes = {
onBadgeChange: PropTypes.func.isRequired,
teams: PropTypes.array.isRequired,
localTeams: PropTypes.array.isRequired,
onTeamConfigChange: PropTypes.func.isRequired,
initialIndex: PropTypes.number.isRequired,
useSpellChecker: PropTypes.bool.isRequired,

View File

@@ -26,14 +26,6 @@ const config = new Config(remote.app.getPath('userData') + '/config.json', remot
const teams = config.teams;
// Make sure teams have an order
if (teams.every((team) => !team.order)) {
teams.forEach((team, index) => {
team.order = index;
});
teamConfigChange(teams);
}
remote.getCurrentWindow().removeAllListeners('focus');
if (teams.length === 0) {
@@ -140,8 +132,11 @@ function showBadge(sessionExpired, unreadCount, mentionCount) {
}
}
function teamConfigChange(updatedTeams) {
function teamConfigChange(updatedTeams, callback) {
config.set('teams', updatedTeams);
if (callback) {
config.once('update', callback);
}
}
function handleSelectSpellCheckerLocale(locale) {
@@ -196,6 +191,7 @@ function openMenu() {
ReactDOM.render(
<MainPage
teams={teams}
localTeams={config.localTeams}
initialIndex={initialIndex}
onBadgeChange={showBadge}
onTeamConfigChange={teamConfigChange}