Skip to content

Commit 5d03b91

Browse files
committed
feat(Todos): Add option to disable todos
1 parent 024fb39 commit 5d03b91

File tree

8 files changed

+177
-54
lines changed

8 files changed

+177
-54
lines changed

src/components/settings/settings/EditSettingsForm.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ export default @observer class EditSettingsForm extends Component {
101101
onClearAllCache: PropTypes.func.isRequired,
102102
cacheSize: PropTypes.string.isRequired,
103103
isSpellcheckerIncludedInCurrentPlan: PropTypes.bool.isRequired,
104+
isTodosEnabled: PropTypes.bool.isRequired,
104105
};
105106

106107
static contextTypes = {
@@ -131,6 +132,7 @@ export default @observer class EditSettingsForm extends Component {
131132
onClearAllCache,
132133
cacheSize,
133134
isSpellcheckerIncludedInCurrentPlan,
135+
isTodosEnabled,
134136
} = this.props;
135137
const { intl } = this.context;
136138

@@ -162,6 +164,9 @@ export default @observer class EditSettingsForm extends Component {
162164
{process.platform === 'win32' && (
163165
<Toggle field={form.$('minimizeToSystemTray')} />
164166
)}
167+
{isTodosEnabled && (
168+
<Toggle field={form.$('enableTodos')} />
169+
)}
165170

166171
{/* Appearance */}
167172
<h2 id="apperance">{intl.formatMessage(messages.headlineAppearance)}</h2>

src/containers/settings/EditSettingsScreen.js

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { defineMessages, intlShape } from 'react-intl';
66
import AppStore from '../../stores/AppStore';
77
import SettingsStore from '../../stores/SettingsStore';
88
import UserStore from '../../stores/UserStore';
9+
import TodosStore from '../../features/todos/store';
910
import Form from '../../lib/Form';
1011
import { APP_LOCALES, SPELLCHECKER_LOCALES } from '../../i18n/languages';
1112
import { DEFAULT_APP_SETTINGS } from '../../config';
@@ -17,6 +18,7 @@ import EditSettingsForm from '../../components/settings/settings/EditSettingsFor
1718
import ErrorBoundary from '../../components/util/ErrorBoundary';
1819

1920
import globalMessages from '../../i18n/globalMessages';
21+
import { DEFAULT_IS_FEATURE_ENABLED_BY_USER } from '../../features/todos';
2022

2123
const messages = defineMessages({
2224
autoLaunchOnStart: {
@@ -67,6 +69,10 @@ const messages = defineMessages({
6769
id: 'settings.app.form.beta',
6870
defaultMessage: '!!!Include beta versions',
6971
},
72+
enableTodos: {
73+
id: 'settings.app.form.enableTodos',
74+
defaultMessage: '!!!Enable Franz Todos',
75+
},
7076
});
7177

7278
export default @inject('stores', 'actions') @observer class EditSettingsScreen extends Component {
@@ -75,7 +81,13 @@ export default @inject('stores', 'actions') @observer class EditSettingsScreen e
7581
};
7682

7783
onSubmit(settingsData) {
78-
const { app, settings, user } = this.props.actions;
84+
const { todos } = this.props.stores;
85+
const {
86+
app,
87+
settings,
88+
user,
89+
todos: todosActions,
90+
} = this.props.actions;
7991

8092
app.launchOnStartup({
8193
enable: settingsData.autoLaunchOnStart,
@@ -105,10 +117,16 @@ export default @inject('stores', 'actions') @observer class EditSettingsScreen e
105117
locale: settingsData.locale,
106118
},
107119
});
120+
121+
if (todos.isFeatureActive) {
122+
todosActions.toggleTodosFeatureVisibility();
123+
}
108124
}
109125

110126
prepareForm() {
111-
const { app, settings, user } = this.props.stores;
127+
const {
128+
app, settings, user, todos,
129+
} = this.props.stores;
112130
const { intl } = this.context;
113131

114132
const locales = getSelectOptions({
@@ -192,16 +210,28 @@ export default @inject('stores', 'actions') @observer class EditSettingsScreen e
192210
},
193211
};
194212

213+
if (todos.isFeatureActive) {
214+
config.fields.enableTodos = {
215+
label: intl.formatMessage(messages.enableTodos),
216+
value: todos.settings.isFeatureEnabledByUser,
217+
default: DEFAULT_IS_FEATURE_ENABLED_BY_USER,
218+
};
219+
}
220+
195221
return new Form(config);
196222
}
197223

198224
render() {
225+
const {
226+
app,
227+
todos,
228+
} = this.props.stores;
199229
const {
200230
updateStatus,
201231
cacheSize,
202232
updateStatusTypes,
203233
isClearingAllCache,
204-
} = this.props.stores.app;
234+
} = app;
205235
const {
206236
checkForUpdates,
207237
installUpdate,
@@ -224,6 +254,7 @@ export default @inject('stores', 'actions') @observer class EditSettingsScreen e
224254
isClearingAllCache={isClearingAllCache}
225255
onClearAllCache={clearAllCache}
226256
isSpellcheckerIncludedInCurrentPlan={spellcheckerConfig.isIncludedInCurrentPlan}
257+
isTodosEnabled={todos.isFeatureActive}
227258
/>
228259
</ErrorBoundary>
229260
);
@@ -235,6 +266,7 @@ EditSettingsScreen.wrappedComponent.propTypes = {
235266
app: PropTypes.instanceOf(AppStore).isRequired,
236267
user: PropTypes.instanceOf(UserStore).isRequired,
237268
settings: PropTypes.instanceOf(SettingsStore).isRequired,
269+
todos: PropTypes.instanceOf(TodosStore).isRequired,
238270
}).isRequired,
239271
actions: PropTypes.shape({
240272
app: PropTypes.shape({
@@ -249,5 +281,8 @@ EditSettingsScreen.wrappedComponent.propTypes = {
249281
user: PropTypes.shape({
250282
update: PropTypes.func.isRequired,
251283
}).isRequired,
284+
todos: PropTypes.shape({
285+
toggleTodosFeatureVisibility: PropTypes.func.isRequired,
286+
}).isRequired,
252287
}).isRequired,
253288
};

src/features/todos/actions.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ export const todoActions = createActionsFromDefinitions({
66
width: PropTypes.number.isRequired,
77
},
88
toggleTodosPanel: {},
9+
toggleTodosFeatureVisibility: {},
910
setTodosWebview: {
1011
webview: PropTypes.instanceOf(Element).isRequired,
1112
},

src/features/todos/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ export const GA_CATEGORY_TODOS = 'Todos';
88
export const DEFAULT_TODOS_WIDTH = 300;
99
export const TODOS_MIN_WIDTH = 200;
1010
export const DEFAULT_TODOS_VISIBLE = true;
11+
export const DEFAULT_IS_FEATURE_ENABLED_BY_USER = true;
1112

1213
export const TODOS_ROUTES = {
1314
TARGET: '/todos',

src/features/todos/store.js

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { FeatureStore } from '../utils/FeatureStore';
1111
import { createReactions } from '../../stores/lib/Reaction';
1212
import { createActionBindings } from '../utils/ActionBinding';
1313
import {
14-
DEFAULT_TODOS_WIDTH, TODOS_MIN_WIDTH, DEFAULT_TODOS_VISIBLE, TODOS_ROUTES,
14+
DEFAULT_TODOS_WIDTH, TODOS_MIN_WIDTH, DEFAULT_TODOS_VISIBLE, TODOS_ROUTES, DEFAULT_IS_FEATURE_ENABLED_BY_USER,
1515
} from '.';
1616
import { IPC } from './constants';
1717
import { state as delayAppState } from '../delayApp';
@@ -33,7 +33,7 @@ export default class TodoStore extends FeatureStore {
3333

3434
@computed get isTodosPanelForceHidden() {
3535
const { isAnnouncementShown } = this.stores.announcements;
36-
return delayAppState.isDelayAppScreenVisible || isAnnouncementShown;
36+
return delayAppState.isDelayAppScreenVisible || !this.settings.isFeatureEnabledByUser || isAnnouncementShown;
3737
}
3838

3939
@computed get isTodosPanelVisible() {
@@ -60,6 +60,7 @@ export default class TodoStore extends FeatureStore {
6060
[todoActions.setTodosWebview, this._setTodosWebview],
6161
[todoActions.handleHostMessage, this._handleHostMessage],
6262
[todoActions.handleClientMessage, this._handleClientMessage],
63+
[todoActions.toggleTodosFeatureVisibility, this._toggleTodosFeatureVisibility],
6364
]));
6465

6566
// REACTIONS
@@ -74,6 +75,12 @@ export default class TodoStore extends FeatureStore {
7475
this._registerReactions(this._allReactions);
7576

7677
this.isFeatureActive = true;
78+
79+
if (this.settings.isFeatureEnabledByUser === undefined) {
80+
this._updateSettings({
81+
isFeatureEnabledByUser: DEFAULT_IS_FEATURE_ENABLED_BY_USER,
82+
});
83+
}
7784
}
7885

7986
@action stop() {
@@ -128,6 +135,14 @@ export default class TodoStore extends FeatureStore {
128135
}
129136
};
130137

138+
@action _toggleTodosFeatureVisibility = () => {
139+
debug('_toggleTodosFeatureVisibility');
140+
141+
this._updateSettings({
142+
isFeatureEnabledByUser: !this.settings.isFeatureEnabledByUser,
143+
});
144+
};
145+
131146
// Todos client message handlers
132147

133148
_onTodosClientInitialized = () => {

0 commit comments

Comments
 (0)