Base model refactor (#810)

* Big upgrades

* WIP: Stash

* Stash, 30 flow errors left

* Downgrade mobx

* WIP

* When I understand the difference between class and instance methods

* 💚

* Fixes: File import
Model saving edge cases
pinning and starring docs
Collection editing
Upgrade mobx devtools

* Notification settings saving works

* Disabled settings

* Document mailer

* Working notifications

* Colletion created notification
Ensure not notified for own actions

* Tidy up

* Document updated event only for document creation
Add indexes
Notification setting on user creation

* Commentary

* Fixed: Notification setting on signup

* Fix document move / duplicate stale data
Add BaseModel.refresh method

* Fixes: Title in sidebar not updated after editing document

* 💚

* Improve / restore error handling
Better handle offline errors

* 👕
This commit is contained in:
Tom Moor
2018-12-04 22:24:30 -08:00
committed by GitHub
parent 67cd250316
commit 8cbcb77486
222 changed files with 2273 additions and 2361 deletions

View File

@@ -0,0 +1,93 @@
// @flow
import * as React from 'react';
import { debounce } from 'lodash';
import { observer, inject } from 'mobx-react';
import CenteredContent from 'components/CenteredContent';
import PageTitle from 'components/PageTitle';
import HelpText from 'components/HelpText';
import NotificationListItem from './components/NotificationListItem';
import UiStore from 'stores/UiStore';
import NotificationSettingsStore from 'stores/NotificationSettingsStore';
type Props = {
ui: UiStore,
notificationSettings: NotificationSettingsStore,
};
const options = [
{
event: 'documents.publish',
title: 'Document published',
description: 'Receive a notification whenever a new document is published',
},
{
event: 'documents.update',
title: 'Document updated',
description: 'Receive a notification when a document you created is edited',
},
{
event: 'collections.create',
title: 'Collection created',
description: 'Receive a notification whenever a new collection is created',
},
];
@observer
class Notifications extends React.Component<Props> {
componentDidMount() {
this.props.notificationSettings.fetchPage();
}
handleChange = async (ev: SyntheticInputEvent<*>) => {
const { notificationSettings } = this.props;
const setting = notificationSettings.getByEvent(ev.target.name);
if (ev.target.checked) {
await notificationSettings.save({
event: ev.target.name,
});
} else if (setting) {
await notificationSettings.delete(setting);
}
this.showSuccessMessage();
};
showSuccessMessage = debounce(() => {
this.props.ui.showToast('Notifications updated');
}, 500);
render() {
const { notificationSettings } = this.props;
return (
<CenteredContent>
<PageTitle title="Notifications" />
<h1>Notifications</h1>
<HelpText>
Manage when you receive email notifications from Outline.
</HelpText>
{options.map(option => {
const setting = notificationSettings.getByEvent(option.event);
return (
<NotificationListItem
key={option.event}
onChange={this.handleChange}
setting={setting}
disabled={
(setting && setting.isSaving) || notificationSettings.isFetching
}
{...option}
/>
);
})}
</CenteredContent>
);
}
}
export default inject('notificationSettings', 'ui')(Notifications);