Skip to content

Commit

Permalink
feat(Workspaces): Setting to keep all workspaces loaded
Browse files Browse the repository at this point in the history
  • Loading branch information
DominikGuzei committed Sep 11, 2019
1 parent f309aaf commit ddab3a8
Show file tree
Hide file tree
Showing 7 changed files with 87 additions and 31 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 @@ -102,6 +102,7 @@ export default @observer class EditSettingsForm extends Component {
cacheSize: PropTypes.string.isRequired,
isSpellcheckerIncludedInCurrentPlan: PropTypes.bool.isRequired,
isTodosEnabled: PropTypes.bool.isRequired,
isWorkspaceEnabled: PropTypes.bool.isRequired,
};

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

Expand Down Expand Up @@ -164,6 +166,9 @@ export default @observer class EditSettingsForm extends Component {
{process.platform === 'win32' && (
<Toggle field={form.$('minimizeToSystemTray')} />
)}
{isWorkspaceEnabled && (
<Toggle field={form.$('keepAllWorkspacesLoaded')} />
)}
{isTodosEnabled && (
<Toggle field={form.$('enableTodos')} />
)}
Expand Down
37 changes: 34 additions & 3 deletions src/containers/settings/EditSettingsScreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import ErrorBoundary from '../../components/util/ErrorBoundary';

import globalMessages from '../../i18n/globalMessages';
import { DEFAULT_IS_FEATURE_ENABLED_BY_USER } from '../../features/todos';
import WorkspacesStore from '../../features/workspaces/store';
import { DEFAULT_SETTING_KEEP_ALL_WORKSPACES_LOADED } from '../../features/workspaces';

const messages = defineMessages({
autoLaunchOnStart: {
Expand Down Expand Up @@ -73,6 +75,10 @@ const messages = defineMessages({
id: 'settings.app.form.enableTodos',
defaultMessage: '!!!Enable Franz Todos',
},
keepAllWorkspacesLoaded: {
id: 'settings.app.form.keepAllWorkspacesLoaded',
defaultMessage: '!!!Keep all workspaces loaded',
},
});

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

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

app.launchOnStartup({
Expand Down Expand Up @@ -118,14 +125,24 @@ export default @inject('stores', 'actions') @observer class EditSettingsScreen e
},
});

if (workspaces.isFeatureActive) {
const { keepAllWorkspacesLoaded } = workspaces.settings;
if (keepAllWorkspacesLoaded !== settingsData.keepAllWorkspacesLoaded) {
workspaceActions.toggleKeepAllWorkspacesLoadedSetting();
}
}

if (todos.isFeatureActive) {
todosActions.toggleTodosFeatureVisibility();
const { isFeatureEnabledByUser } = todos.settings;
if (isFeatureEnabledByUser !== settingsData.enableTodos) {
todosActions.toggleTodosFeatureVisibility();
}
}
}

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

Expand Down Expand Up @@ -210,6 +227,14 @@ export default @inject('stores', 'actions') @observer class EditSettingsScreen e
},
};

if (workspaces.isFeatureActive) {
config.fields.keepAllWorkspacesLoaded = {
label: intl.formatMessage(messages.keepAllWorkspacesLoaded),
value: workspaces.settings.keepAllWorkspacesLoaded,
default: DEFAULT_SETTING_KEEP_ALL_WORKSPACES_LOADED,
};
}

if (todos.isFeatureActive) {
config.fields.enableTodos = {
label: intl.formatMessage(messages.enableTodos),
Expand All @@ -225,6 +250,7 @@ export default @inject('stores', 'actions') @observer class EditSettingsScreen e
const {
app,
todos,
workspaces,
} = this.props.stores;
const {
updateStatus,
Expand Down Expand Up @@ -255,6 +281,7 @@ export default @inject('stores', 'actions') @observer class EditSettingsScreen e
onClearAllCache={clearAllCache}
isSpellcheckerIncludedInCurrentPlan={spellcheckerConfig.isIncludedInCurrentPlan}
isTodosEnabled={todos.isFeatureActive}
isWorkspaceEnabled={workspaces.isFeatureActive}
/>
</ErrorBoundary>
);
Expand All @@ -267,6 +294,7 @@ EditSettingsScreen.wrappedComponent.propTypes = {
user: PropTypes.instanceOf(UserStore).isRequired,
settings: PropTypes.instanceOf(SettingsStore).isRequired,
todos: PropTypes.instanceOf(TodosStore).isRequired,
workspaces: PropTypes.instanceOf(WorkspacesStore).isRequired,
}).isRequired,
actions: PropTypes.shape({
app: PropTypes.shape({
Expand All @@ -284,5 +312,8 @@ EditSettingsScreen.wrappedComponent.propTypes = {
todos: PropTypes.shape({
toggleTodosFeatureVisibility: PropTypes.func.isRequired,
}).isRequired,
workspaces: PropTypes.shape({
toggleAllWorkspacesLoadedSetting: PropTypes.func.isRequired,
}).isRequired,
}).isRequired,
};
1 change: 1 addition & 0 deletions src/features/workspaces/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export const workspaceActions = createActionsFromDefinitions({
deactivate: {},
toggleWorkspaceDrawer: {},
openWorkspaceSettings: {},
toggleKeepAllWorkspacesLoadedSetting: {},
}, PropTypes.checkPropTypes);

export default workspaceActions;
1 change: 1 addition & 0 deletions src/features/workspaces/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { resetApiRequests } from './api';
const debug = require('debug')('Franz:feature:workspaces');

export const GA_CATEGORY_WORKSPACES = 'Workspaces';
export const DEFAULT_SETTING_KEEP_ALL_WORKSPACES_LOADED = false;

export const workspaceStore = new WorkspacesStore();

Expand Down
5 changes: 5 additions & 0 deletions src/features/workspaces/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ export default class WorkspacesStore extends FeatureStore {
[workspaceActions.update, this._update],
[workspaceActions.activate, this._setActiveWorkspace],
[workspaceActions.deactivate, this._deactivateActiveWorkspace],
[workspaceActions.toggleKeepAllWorkspacesLoadedSetting, this._toggleKeepAllWorkspacesLoadedSetting],
]);
this._allActions = this._freeUserActions.concat(this._premiumUserActions);
this._registerActions(this._allActions);
Expand Down Expand Up @@ -245,6 +246,10 @@ export default class WorkspacesStore extends FeatureStore {
await updateWorkspaceRequest.execute(activeWorkspace);
};

_toggleKeepAllWorkspacesLoadedSetting = async () => {
this._updateSettings({ keepAllWorkspacesLoaded: !this.settings.keepAllWorkspacesLoaded });
};

// Reactions

_setFeatureEnabledReaction = () => {
Expand Down
65 changes: 39 additions & 26 deletions src/i18n/messages/src/containers/settings/EditSettingsScreen.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
"defaultMessage": "!!!Launch Franz on start",
"file": "src/containers/settings/EditSettingsScreen.js",
"start": {
"line": 24,
"line": 26,
"column": 21
},
"end": {
"line": 27,
"line": 29,
"column": 3
}
},
Expand All @@ -17,11 +17,11 @@
"defaultMessage": "!!!Open in background",
"file": "src/containers/settings/EditSettingsScreen.js",
"start": {
"line": 28,
"line": 30,
"column": 26
},
"end": {
"line": 31,
"line": 33,
"column": 3
}
},
Expand All @@ -30,11 +30,11 @@
"defaultMessage": "!!!Keep Franz in background when closing the window",
"file": "src/containers/settings/EditSettingsScreen.js",
"start": {
"line": 32,
"line": 34,
"column": 19
},
"end": {
"line": 35,
"line": 37,
"column": 3
}
},
Expand All @@ -43,11 +43,11 @@
"defaultMessage": "!!!Show Franz in system tray",
"file": "src/containers/settings/EditSettingsScreen.js",
"start": {
"line": 36,
"line": 38,
"column": 20
},
"end": {
"line": 39,
"line": 41,
"column": 3
}
},
Expand All @@ -56,11 +56,11 @@
"defaultMessage": "!!!Minimize Franz to system tray",
"file": "src/containers/settings/EditSettingsScreen.js",
"start": {
"line": 40,
"line": 42,
"column": 24
},
"end": {
"line": 43,
"line": 45,
"column": 3
}
},
Expand All @@ -69,11 +69,11 @@
"defaultMessage": "!!!Language",
"file": "src/containers/settings/EditSettingsScreen.js",
"start": {
"line": 44,
"line": 46,
"column": 12
},
"end": {
"line": 47,
"line": 49,
"column": 3
}
},
Expand All @@ -82,11 +82,11 @@
"defaultMessage": "!!!Dark Mode",
"file": "src/containers/settings/EditSettingsScreen.js",
"start": {
"line": 48,
"line": 50,
"column": 12
},
"end": {
"line": 51,
"line": 53,
"column": 3
}
},
Expand All @@ -95,11 +95,11 @@
"defaultMessage": "!!!Display disabled services tabs",
"file": "src/containers/settings/EditSettingsScreen.js",
"start": {
"line": 52,
"line": 54,
"column": 24
},
"end": {
"line": 55,
"line": 57,
"column": 3
}
},
Expand All @@ -108,11 +108,11 @@
"defaultMessage": "!!!Show unread message badge when notifications are disabled",
"file": "src/containers/settings/EditSettingsScreen.js",
"start": {
"line": 56,
"line": 58,
"column": 29
},
"end": {
"line": 59,
"line": 61,
"column": 3
}
},
Expand All @@ -121,11 +121,11 @@
"defaultMessage": "!!!Enable spell checking",
"file": "src/containers/settings/EditSettingsScreen.js",
"start": {
"line": 60,
"line": 62,
"column": 23
},
"end": {
"line": 63,
"line": 65,
"column": 3
}
},
Expand All @@ -134,11 +134,11 @@
"defaultMessage": "!!!Enable GPU Acceleration",
"file": "src/containers/settings/EditSettingsScreen.js",
"start": {
"line": 64,
"line": 66,
"column": 25
},
"end": {
"line": 67,
"line": 69,
"column": 3
}
},
Expand All @@ -147,11 +147,11 @@
"defaultMessage": "!!!Include beta versions",
"file": "src/containers/settings/EditSettingsScreen.js",
"start": {
"line": 68,
"line": 70,
"column": 8
},
"end": {
"line": 71,
"line": 73,
"column": 3
}
},
Expand All @@ -160,11 +160,24 @@
"defaultMessage": "!!!Enable Franz Todos",
"file": "src/containers/settings/EditSettingsScreen.js",
"start": {
"line": 72,
"line": 74,
"column": 15
},
"end": {
"line": 75,
"line": 77,
"column": 3
}
},
{
"id": "settings.app.form.keepAllWorkspacesLoaded",
"defaultMessage": "!!!Keep all workspaces loaded",
"file": "src/containers/settings/EditSettingsScreen.js",
"start": {
"line": 78,
"column": 27
},
"end": {
"line": 81,
"column": 3
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/stores/ServicesStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,10 @@ export default class ServicesStore extends Store {
// This is just used to avoid unnecessary rerendering of resource-heavy webviews
@computed get allDisplayedUnordered() {
const { showDisabledServices } = this.stores.settings.all.app;
const { showDisabledServices, keepAllWorkspacesLoaded } = this.stores.settings.all.app;
const services = this.allServicesRequest.execute().result || [];
const filteredServices = showDisabledServices ? services : services.filter(service => service.isEnabled);
return workspaceStore.filterServicesByActiveWorkspace(filteredServices);
return keepAllWorkspacesLoaded ? filteredServices : workspaceStore.filterServicesByActiveWorkspace(filteredServices);
}
@computed get filtered() {
Expand Down

1 comment on commit ddab3a8

@Stanzilla
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@DominikGuzei the toggle does not seem to work

Please sign in to comment.