Skip to content

Commit

Permalink
feat(Todos): Add option to disable todos
Browse files Browse the repository at this point in the history
  • Loading branch information
adlk committed Sep 6, 2019
1 parent 024fb39 commit 5d03b91
Show file tree
Hide file tree
Showing 8 changed files with 177 additions and 54 deletions.
5 changes: 5 additions & 0 deletions src/components/settings/settings/EditSettingsForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ export default @observer class EditSettingsForm extends Component {
onClearAllCache: PropTypes.func.isRequired,
cacheSize: PropTypes.string.isRequired,
isSpellcheckerIncludedInCurrentPlan: PropTypes.bool.isRequired,
isTodosEnabled: PropTypes.bool.isRequired,
};

static contextTypes = {
Expand Down Expand Up @@ -131,6 +132,7 @@ export default @observer class EditSettingsForm extends Component {
onClearAllCache,
cacheSize,
isSpellcheckerIncludedInCurrentPlan,
isTodosEnabled,
} = this.props;
const { intl } = this.context;

Expand Down Expand Up @@ -162,6 +164,9 @@ export default @observer class EditSettingsForm extends Component {
{process.platform === 'win32' && (
<Toggle field={form.$('minimizeToSystemTray')} />
)}
{isTodosEnabled && (
<Toggle field={form.$('enableTodos')} />
)}

{/* Appearance */}
<h2 id="apperance">{intl.formatMessage(messages.headlineAppearance)}</h2>
Expand Down
41 changes: 38 additions & 3 deletions src/containers/settings/EditSettingsScreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { defineMessages, intlShape } from 'react-intl';
import AppStore from '../../stores/AppStore';
import SettingsStore from '../../stores/SettingsStore';
import UserStore from '../../stores/UserStore';
import TodosStore from '../../features/todos/store';
import Form from '../../lib/Form';
import { APP_LOCALES, SPELLCHECKER_LOCALES } from '../../i18n/languages';
import { DEFAULT_APP_SETTINGS } from '../../config';
Expand All @@ -17,6 +18,7 @@ import EditSettingsForm from '../../components/settings/settings/EditSettingsFor
import ErrorBoundary from '../../components/util/ErrorBoundary';

import globalMessages from '../../i18n/globalMessages';
import { DEFAULT_IS_FEATURE_ENABLED_BY_USER } from '../../features/todos';

const messages = defineMessages({
autoLaunchOnStart: {
Expand Down Expand Up @@ -67,6 +69,10 @@ const messages = defineMessages({
id: 'settings.app.form.beta',
defaultMessage: '!!!Include beta versions',
},
enableTodos: {
id: 'settings.app.form.enableTodos',
defaultMessage: '!!!Enable Franz Todos',
},
});

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

onSubmit(settingsData) {
const { app, settings, user } = this.props.actions;
const { todos } = this.props.stores;
const {
app,
settings,
user,
todos: todosActions,
} = this.props.actions;

app.launchOnStartup({
enable: settingsData.autoLaunchOnStart,
Expand Down Expand Up @@ -105,10 +117,16 @@ export default @inject('stores', 'actions') @observer class EditSettingsScreen e
locale: settingsData.locale,
},
});

if (todos.isFeatureActive) {
todosActions.toggleTodosFeatureVisibility();
}
}

prepareForm() {
const { app, settings, user } = this.props.stores;
const {
app, settings, user, todos,
} = this.props.stores;
const { intl } = this.context;

const locales = getSelectOptions({
Expand Down Expand Up @@ -192,16 +210,28 @@ export default @inject('stores', 'actions') @observer class EditSettingsScreen e
},
};

if (todos.isFeatureActive) {
config.fields.enableTodos = {
label: intl.formatMessage(messages.enableTodos),
value: todos.settings.isFeatureEnabledByUser,
default: DEFAULT_IS_FEATURE_ENABLED_BY_USER,
};
}

return new Form(config);
}

render() {
const {
app,
todos,
} = this.props.stores;
const {
updateStatus,
cacheSize,
updateStatusTypes,
isClearingAllCache,
} = this.props.stores.app;
} = app;
const {
checkForUpdates,
installUpdate,
Expand All @@ -224,6 +254,7 @@ export default @inject('stores', 'actions') @observer class EditSettingsScreen e
isClearingAllCache={isClearingAllCache}
onClearAllCache={clearAllCache}
isSpellcheckerIncludedInCurrentPlan={spellcheckerConfig.isIncludedInCurrentPlan}
isTodosEnabled={todos.isFeatureActive}
/>
</ErrorBoundary>
);
Expand All @@ -235,6 +266,7 @@ EditSettingsScreen.wrappedComponent.propTypes = {
app: PropTypes.instanceOf(AppStore).isRequired,
user: PropTypes.instanceOf(UserStore).isRequired,
settings: PropTypes.instanceOf(SettingsStore).isRequired,
todos: PropTypes.instanceOf(TodosStore).isRequired,
}).isRequired,
actions: PropTypes.shape({
app: PropTypes.shape({
Expand All @@ -249,5 +281,8 @@ EditSettingsScreen.wrappedComponent.propTypes = {
user: PropTypes.shape({
update: PropTypes.func.isRequired,
}).isRequired,
todos: PropTypes.shape({
toggleTodosFeatureVisibility: PropTypes.func.isRequired,
}).isRequired,
}).isRequired,
};
1 change: 1 addition & 0 deletions src/features/todos/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export const todoActions = createActionsFromDefinitions({
width: PropTypes.number.isRequired,
},
toggleTodosPanel: {},
toggleTodosFeatureVisibility: {},
setTodosWebview: {
webview: PropTypes.instanceOf(Element).isRequired,
},
Expand Down
1 change: 1 addition & 0 deletions src/features/todos/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export const GA_CATEGORY_TODOS = 'Todos';
export const DEFAULT_TODOS_WIDTH = 300;
export const TODOS_MIN_WIDTH = 200;
export const DEFAULT_TODOS_VISIBLE = true;
export const DEFAULT_IS_FEATURE_ENABLED_BY_USER = true;

export const TODOS_ROUTES = {
TARGET: '/todos',
Expand Down
19 changes: 17 additions & 2 deletions src/features/todos/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { FeatureStore } from '../utils/FeatureStore';
import { createReactions } from '../../stores/lib/Reaction';
import { createActionBindings } from '../utils/ActionBinding';
import {
DEFAULT_TODOS_WIDTH, TODOS_MIN_WIDTH, DEFAULT_TODOS_VISIBLE, TODOS_ROUTES,
DEFAULT_TODOS_WIDTH, TODOS_MIN_WIDTH, DEFAULT_TODOS_VISIBLE, TODOS_ROUTES, DEFAULT_IS_FEATURE_ENABLED_BY_USER,
} from '.';
import { IPC } from './constants';
import { state as delayAppState } from '../delayApp';
Expand All @@ -33,7 +33,7 @@ export default class TodoStore extends FeatureStore {

@computed get isTodosPanelForceHidden() {
const { isAnnouncementShown } = this.stores.announcements;
return delayAppState.isDelayAppScreenVisible || isAnnouncementShown;
return delayAppState.isDelayAppScreenVisible || !this.settings.isFeatureEnabledByUser || isAnnouncementShown;
}

@computed get isTodosPanelVisible() {
Expand All @@ -60,6 +60,7 @@ export default class TodoStore extends FeatureStore {
[todoActions.setTodosWebview, this._setTodosWebview],
[todoActions.handleHostMessage, this._handleHostMessage],
[todoActions.handleClientMessage, this._handleClientMessage],
[todoActions.toggleTodosFeatureVisibility, this._toggleTodosFeatureVisibility],
]));

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

this.isFeatureActive = true;

if (this.settings.isFeatureEnabledByUser === undefined) {
this._updateSettings({
isFeatureEnabledByUser: DEFAULT_IS_FEATURE_ENABLED_BY_USER,
});
}
}

@action stop() {
Expand Down Expand Up @@ -128,6 +135,14 @@ export default class TodoStore extends FeatureStore {
}
};

@action _toggleTodosFeatureVisibility = () => {
debug('_toggleTodosFeatureVisibility');

this._updateSettings({
isFeatureEnabledByUser: !this.settings.isFeatureEnabledByUser,
});
};

// Todos client message handlers

_onTodosClientInitialized = () => {
Expand Down
Loading

0 comments on commit 5d03b91

Please sign in to comment.