Even less history passing, fix global styles warning in dev
This commit is contained in:
@ -2,8 +2,8 @@
|
|||||||
import * as React from 'react';
|
import * as React from 'react';
|
||||||
import { observable } from 'mobx';
|
import { observable } from 'mobx';
|
||||||
import { observer, inject } from 'mobx-react';
|
import { observer, inject } from 'mobx-react';
|
||||||
|
import { Redirect } from 'react-router-dom';
|
||||||
import { createGlobalStyle } from 'styled-components';
|
import { createGlobalStyle } from 'styled-components';
|
||||||
import { omit } from 'lodash';
|
|
||||||
import invariant from 'invariant';
|
import invariant from 'invariant';
|
||||||
import importFile from 'utils/importFile';
|
import importFile from 'utils/importFile';
|
||||||
import Dropzone from 'react-dropzone';
|
import Dropzone from 'react-dropzone';
|
||||||
@ -18,11 +18,11 @@ type Props = {
|
|||||||
rejectClassName?: string,
|
rejectClassName?: string,
|
||||||
documents: DocumentsStore,
|
documents: DocumentsStore,
|
||||||
disabled: boolean,
|
disabled: boolean,
|
||||||
history: Object,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const GlobalStyles = createGlobalStyle`
|
export const GlobalStyles = createGlobalStyle`
|
||||||
.activeDropZone {
|
.activeDropZone {
|
||||||
|
border-radius: 4px;
|
||||||
background: ${props => props.theme.slateDark};
|
background: ${props => props.theme.slateDark};
|
||||||
svg { fill: ${props => props.theme.white}; }
|
svg { fill: ${props => props.theme.white}; }
|
||||||
}
|
}
|
||||||
@ -35,6 +35,7 @@ const GlobalStyles = createGlobalStyle`
|
|||||||
@observer
|
@observer
|
||||||
class DropToImport extends React.Component<Props> {
|
class DropToImport extends React.Component<Props> {
|
||||||
@observable isImporting: boolean = false;
|
@observable isImporting: boolean = false;
|
||||||
|
@observable redirectTo: ?string;
|
||||||
|
|
||||||
onDropAccepted = async (files = []) => {
|
onDropAccepted = async (files = []) => {
|
||||||
this.isImporting = true;
|
this.isImporting = true;
|
||||||
@ -59,7 +60,7 @@ class DropToImport extends React.Component<Props> {
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (redirect) {
|
if (redirect) {
|
||||||
this.props.history.push(doc.url);
|
this.redirectTo = doc.url;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
@ -68,16 +69,15 @@ class DropToImport extends React.Component<Props> {
|
|||||||
};
|
};
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const props = omit(
|
const {
|
||||||
this.props,
|
documentId,
|
||||||
'history',
|
collectionId,
|
||||||
'documentId',
|
documents,
|
||||||
'collectionId',
|
disabled,
|
||||||
'documents',
|
...rest
|
||||||
'disabled',
|
} = this.props;
|
||||||
'menuOpen'
|
|
||||||
);
|
|
||||||
|
|
||||||
|
if (this.redirectTo) return <Redirect to={this.redirectTo} />;
|
||||||
if (this.props.disabled) return this.props.children;
|
if (this.props.disabled) return this.props.children;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@ -88,9 +88,8 @@ class DropToImport extends React.Component<Props> {
|
|||||||
disableClick
|
disableClick
|
||||||
disablePreview
|
disablePreview
|
||||||
multiple
|
multiple
|
||||||
{...props}
|
{...rest}
|
||||||
>
|
>
|
||||||
<GlobalStyles />
|
|
||||||
{this.isImporting && <LoadingIndicator />}
|
{this.isImporting && <LoadingIndicator />}
|
||||||
{this.props.children}
|
{this.props.children}
|
||||||
</Dropzone>
|
</Dropzone>
|
||||||
|
@ -12,6 +12,7 @@ import Flex from 'shared/components/Flex';
|
|||||||
import { documentEditUrl, homeUrl, searchUrl } from 'utils/routeHelpers';
|
import { documentEditUrl, homeUrl, searchUrl } from 'utils/routeHelpers';
|
||||||
|
|
||||||
import { LoadingIndicatorBar } from 'components/LoadingIndicator';
|
import { LoadingIndicatorBar } from 'components/LoadingIndicator';
|
||||||
|
import { GlobalStyles } from 'components/DropToImport';
|
||||||
import Sidebar from 'components/Sidebar';
|
import Sidebar from 'components/Sidebar';
|
||||||
import SettingsSidebar from 'components/Sidebar/Settings';
|
import SettingsSidebar from 'components/Sidebar/Settings';
|
||||||
import Modals from 'components/Modals';
|
import Modals from 'components/Modals';
|
||||||
@ -103,6 +104,7 @@ class Layout extends React.Component<Props> {
|
|||||||
</Content>
|
</Content>
|
||||||
</Flex>
|
</Flex>
|
||||||
<Modals ui={ui} />
|
<Modals ui={ui} />
|
||||||
|
<GlobalStyles />
|
||||||
</Container>
|
</Container>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -13,7 +13,6 @@ import DropToImport from 'components/DropToImport';
|
|||||||
import Flex from 'shared/components/Flex';
|
import Flex from 'shared/components/Flex';
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
history: Object,
|
|
||||||
collection: Collection,
|
collection: Collection,
|
||||||
ui: UiStore,
|
ui: UiStore,
|
||||||
activeDocument: ?Document,
|
activeDocument: ?Document,
|
||||||
@ -25,19 +24,12 @@ class CollectionLink extends React.Component<Props> {
|
|||||||
@observable menuOpen = false;
|
@observable menuOpen = false;
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const {
|
const { collection, activeDocument, prefetchDocument, ui } = this.props;
|
||||||
history,
|
|
||||||
collection,
|
|
||||||
activeDocument,
|
|
||||||
prefetchDocument,
|
|
||||||
ui,
|
|
||||||
} = this.props;
|
|
||||||
const expanded = collection.id === ui.activeCollectionId;
|
const expanded = collection.id === ui.activeCollectionId;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<DropToImport
|
<DropToImport
|
||||||
key={collection.id}
|
key={collection.id}
|
||||||
history={history}
|
|
||||||
collectionId={collection.id}
|
collectionId={collection.id}
|
||||||
activeClassName="activeDropZone"
|
activeClassName="activeDropZone"
|
||||||
>
|
>
|
||||||
@ -72,7 +64,6 @@ class CollectionLink extends React.Component<Props> {
|
|||||||
{collection.documents.map(document => (
|
{collection.documents.map(document => (
|
||||||
<DocumentLink
|
<DocumentLink
|
||||||
key={document.id}
|
key={document.id}
|
||||||
history={history}
|
|
||||||
document={document}
|
document={document}
|
||||||
activeDocument={activeDocument}
|
activeDocument={activeDocument}
|
||||||
prefetchDocument={prefetchDocument}
|
prefetchDocument={prefetchDocument}
|
||||||
|
@ -10,7 +10,6 @@ import { type NavigationNode } from 'types';
|
|||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
document: NavigationNode,
|
document: NavigationNode,
|
||||||
history: Object,
|
|
||||||
activeDocument: ?Document,
|
activeDocument: ?Document,
|
||||||
activeDocumentRef?: (?HTMLElement) => *,
|
activeDocumentRef?: (?HTMLElement) => *,
|
||||||
prefetchDocument: (documentId: string) => Promise<void>,
|
prefetchDocument: (documentId: string) => Promise<void>,
|
||||||
@ -34,7 +33,6 @@ class DocumentLink extends React.Component<Props> {
|
|||||||
activeDocumentRef,
|
activeDocumentRef,
|
||||||
prefetchDocument,
|
prefetchDocument,
|
||||||
depth,
|
depth,
|
||||||
history,
|
|
||||||
} = this.props;
|
} = this.props;
|
||||||
|
|
||||||
const isActiveDocument =
|
const isActiveDocument =
|
||||||
@ -55,11 +53,7 @@ class DocumentLink extends React.Component<Props> {
|
|||||||
ref={isActiveDocument ? activeDocumentRef : undefined}
|
ref={isActiveDocument ? activeDocumentRef : undefined}
|
||||||
onMouseEnter={this.handleMouseEnter}
|
onMouseEnter={this.handleMouseEnter}
|
||||||
>
|
>
|
||||||
<DropToImport
|
<DropToImport documentId={document.id} activeClassName="activeDropZone">
|
||||||
history={history}
|
|
||||||
documentId={document.id}
|
|
||||||
activeClassName="activeDropZone"
|
|
||||||
>
|
|
||||||
<SidebarLink
|
<SidebarLink
|
||||||
to={{
|
to={{
|
||||||
pathname: document.url,
|
pathname: document.url,
|
||||||
@ -74,7 +68,6 @@ class DocumentLink extends React.Component<Props> {
|
|||||||
{document.children.map(childDocument => (
|
{document.children.map(childDocument => (
|
||||||
<DocumentLink
|
<DocumentLink
|
||||||
key={childDocument.id}
|
key={childDocument.id}
|
||||||
history={history}
|
|
||||||
document={childDocument}
|
document={childDocument}
|
||||||
activeDocument={activeDocument}
|
activeDocument={activeDocument}
|
||||||
prefetchDocument={prefetchDocument}
|
prefetchDocument={prefetchDocument}
|
||||||
|
@ -357,7 +357,6 @@ class DocumentScene extends React.Component<Props> {
|
|||||||
isSaving={this.isSaving}
|
isSaving={this.isSaving}
|
||||||
isPublishing={this.isPublishing}
|
isPublishing={this.isPublishing}
|
||||||
savingIsDisabled={!document.allowSave}
|
savingIsDisabled={!document.allowSave}
|
||||||
history={this.props.history}
|
|
||||||
onDiscard={this.onDiscard}
|
onDiscard={this.onDiscard}
|
||||||
onSave={this.onSave}
|
onSave={this.onSave}
|
||||||
/>
|
/>
|
||||||
|
@ -3,6 +3,7 @@ import * as React from 'react';
|
|||||||
import { throttle } from 'lodash';
|
import { throttle } from 'lodash';
|
||||||
import { observable } from 'mobx';
|
import { observable } from 'mobx';
|
||||||
import { observer, inject } from 'mobx-react';
|
import { observer, inject } from 'mobx-react';
|
||||||
|
import { Redirect } from 'react-router-dom';
|
||||||
import styled from 'styled-components';
|
import styled from 'styled-components';
|
||||||
import breakpoint from 'styled-components-breakpoint';
|
import breakpoint from 'styled-components-breakpoint';
|
||||||
import { NewDocumentIcon } from 'outline-icons';
|
import { NewDocumentIcon } from 'outline-icons';
|
||||||
@ -33,7 +34,6 @@ type Props = {
|
|||||||
publish?: boolean,
|
publish?: boolean,
|
||||||
autosave?: boolean,
|
autosave?: boolean,
|
||||||
}) => *,
|
}) => *,
|
||||||
history: Object,
|
|
||||||
auth: AuthStore,
|
auth: AuthStore,
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -41,6 +41,7 @@ type Props = {
|
|||||||
class Header extends React.Component<Props> {
|
class Header extends React.Component<Props> {
|
||||||
@observable isScrolled = false;
|
@observable isScrolled = false;
|
||||||
@observable showShareModal = false;
|
@observable showShareModal = false;
|
||||||
|
@observable redirectTo: ?string;
|
||||||
|
|
||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
window.addEventListener('scroll', this.handleScroll);
|
window.addEventListener('scroll', this.handleScroll);
|
||||||
@ -57,7 +58,7 @@ class Header extends React.Component<Props> {
|
|||||||
handleScroll = throttle(this.updateIsScrolled, 50);
|
handleScroll = throttle(this.updateIsScrolled, 50);
|
||||||
|
|
||||||
handleEdit = () => {
|
handleEdit = () => {
|
||||||
this.props.history.push(documentEditUrl(this.props.document));
|
this.redirectTo = documentEditUrl(this.props.document);
|
||||||
};
|
};
|
||||||
|
|
||||||
handleSave = () => {
|
handleSave = () => {
|
||||||
@ -86,6 +87,8 @@ class Header extends React.Component<Props> {
|
|||||||
};
|
};
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
|
if (this.redirectTo) return <Redirect to={this.redirectTo} />;
|
||||||
|
|
||||||
const {
|
const {
|
||||||
document,
|
document,
|
||||||
isEditing,
|
isEditing,
|
||||||
|
Reference in New Issue
Block a user