Tidying, possible fix for excessive view count
This commit is contained in:
@@ -36,7 +36,8 @@ import Search from 'scenes/Search';
|
|||||||
import Error404 from 'scenes/Error404';
|
import Error404 from 'scenes/Error404';
|
||||||
import ErrorOffline from 'scenes/ErrorOffline';
|
import ErrorOffline from 'scenes/ErrorOffline';
|
||||||
|
|
||||||
const AUTOSAVE_INTERVAL = 3000;
|
const AUTOSAVE_DELAY = 3000;
|
||||||
|
const IS_DIRTY_DELAY = 500;
|
||||||
const MARK_AS_VIEWED_AFTER = 3000;
|
const MARK_AS_VIEWED_AFTER = 3000;
|
||||||
const DISCARD_CHANGES = `
|
const DISCARD_CHANGES = `
|
||||||
You have unsaved changes.
|
You have unsaved changes.
|
||||||
@@ -59,7 +60,6 @@ type Props = {
|
|||||||
|
|
||||||
@observer
|
@observer
|
||||||
class DocumentScene extends React.Component<Props> {
|
class DocumentScene extends React.Component<Props> {
|
||||||
savedTimeout: TimeoutID;
|
|
||||||
viewTimeout: TimeoutID;
|
viewTimeout: TimeoutID;
|
||||||
getEditorText: () => string;
|
getEditorText: () => string;
|
||||||
|
|
||||||
@@ -85,14 +85,13 @@ class DocumentScene extends React.Component<Props> {
|
|||||||
this.props.match.params.documentSlug
|
this.props.match.params.documentSlug
|
||||||
) {
|
) {
|
||||||
this.notFound = false;
|
this.notFound = false;
|
||||||
|
clearTimeout(this.viewTimeout);
|
||||||
this.loadDocument(nextProps);
|
this.loadDocument(nextProps);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
componentWillUnmount() {
|
componentWillUnmount() {
|
||||||
clearTimeout(this.savedTimeout);
|
|
||||||
clearTimeout(this.viewTimeout);
|
clearTimeout(this.viewTimeout);
|
||||||
|
|
||||||
this.props.ui.clearActiveDocument();
|
this.props.ui.clearActiveDocument();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -200,11 +199,11 @@ class DocumentScene extends React.Component<Props> {
|
|||||||
|
|
||||||
autosave = debounce(() => {
|
autosave = debounce(() => {
|
||||||
this.onSave({ done: false, autosave: true });
|
this.onSave({ done: false, autosave: true });
|
||||||
}, AUTOSAVE_INTERVAL);
|
}, AUTOSAVE_DELAY);
|
||||||
|
|
||||||
updateIsDirty = debounce(() => {
|
updateIsDirty = debounce(() => {
|
||||||
this.isDirty = this.getEditorText().trim() !== this.document.text.trim();
|
this.isDirty = this.getEditorText().trim() !== this.document.text.trim();
|
||||||
}, 500);
|
}, IS_DIRTY_DELAY);
|
||||||
|
|
||||||
onImageUploadStart = () => {
|
onImageUploadStart = () => {
|
||||||
this.isUploading = true;
|
this.isUploading = true;
|
||||||
@@ -319,10 +318,7 @@ class DocumentScene extends React.Component<Props> {
|
|||||||
<Container justify="center" column auto>
|
<Container justify="center" column auto>
|
||||||
{this.isEditing && (
|
{this.isEditing && (
|
||||||
<React.Fragment>
|
<React.Fragment>
|
||||||
<Prompt
|
<Prompt when={this.isDirty} message={DISCARD_CHANGES} />
|
||||||
when={this.isDirty}
|
|
||||||
message={DISCARD_CHANGES}
|
|
||||||
/>
|
|
||||||
<Prompt when={this.isUploading} message={UPLOADING_WARNING} />
|
<Prompt when={this.isUploading} message={UPLOADING_WARNING} />
|
||||||
</React.Fragment>
|
</React.Fragment>
|
||||||
)}
|
)}
|
||||||
@@ -330,7 +326,6 @@ class DocumentScene extends React.Component<Props> {
|
|||||||
<Header
|
<Header
|
||||||
document={document}
|
document={document}
|
||||||
isDraft={document.isDraft}
|
isDraft={document.isDraft}
|
||||||
isDirty={this.isDirty}
|
|
||||||
isEditing={this.isEditing}
|
isEditing={this.isEditing}
|
||||||
isSaving={this.isSaving}
|
isSaving={this.isSaving}
|
||||||
isPublishing={this.isPublishing}
|
isPublishing={this.isPublishing}
|
||||||
|
|||||||
@@ -20,7 +20,6 @@ import { Action, Separator } from 'components/Actions';
|
|||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
document: Document,
|
document: Document,
|
||||||
isDirty: boolean,
|
|
||||||
isDraft: boolean,
|
isDraft: boolean,
|
||||||
isEditing: boolean,
|
isEditing: boolean,
|
||||||
isSaving: boolean,
|
isSaving: boolean,
|
||||||
@@ -88,7 +87,6 @@ class Header extends React.Component<Props> {
|
|||||||
document,
|
document,
|
||||||
isEditing,
|
isEditing,
|
||||||
isDraft,
|
isDraft,
|
||||||
isDirty,
|
|
||||||
isPublishing,
|
isPublishing,
|
||||||
isSaving,
|
isSaving,
|
||||||
savingIsDisabled,
|
savingIsDisabled,
|
||||||
|
|||||||
Reference in New Issue
Block a user