Setup for unauthenticated doc viewing
This commit is contained in:
parent
3005da78e2
commit
dded458582
|
@ -4,7 +4,6 @@ import { Provider } from 'mobx-react';
|
|||
import stores from 'stores';
|
||||
import ApiKeysStore from 'stores/ApiKeysStore';
|
||||
import UsersStore from 'stores/UsersStore';
|
||||
import DocumentsStore from 'stores/DocumentsStore';
|
||||
import CollectionsStore from 'stores/CollectionsStore';
|
||||
import IntegrationsStore from 'stores/IntegrationsStore';
|
||||
import CacheStore from 'stores/CacheStore';
|
||||
|
@ -27,10 +26,6 @@ const Auth = ({ children }: Props) => {
|
|||
integrations: new IntegrationsStore(),
|
||||
apiKeys: new ApiKeysStore(),
|
||||
users: new UsersStore(),
|
||||
documents: new DocumentsStore({
|
||||
ui: stores.ui,
|
||||
cache,
|
||||
}),
|
||||
collections: new CollectionsStore({
|
||||
ui: stores.ui,
|
||||
teamId: team.id,
|
||||
|
|
|
@ -112,7 +112,14 @@ class DocumentPreview extends React.Component<Props> {
|
|||
} = this.props;
|
||||
|
||||
return (
|
||||
<DocumentLink to={document.url} innerRef={innerRef} {...rest}>
|
||||
<DocumentLink
|
||||
to={{
|
||||
pathname: document.url,
|
||||
state: { title: document.title },
|
||||
}}
|
||||
innerRef={innerRef}
|
||||
{...rest}
|
||||
>
|
||||
<Heading>
|
||||
<Highlight text={document.title} highlight={highlight} />
|
||||
{document.publishedAt && (
|
||||
|
|
|
@ -60,7 +60,10 @@ class DocumentLink extends React.Component<Props> {
|
|||
activeClassName="activeDropZone"
|
||||
>
|
||||
<SidebarLink
|
||||
to={document.url}
|
||||
to={{
|
||||
pathname: document.url,
|
||||
state: { title: document.title },
|
||||
}}
|
||||
expand={showChildren}
|
||||
expandedContent={
|
||||
document.children.length ? (
|
||||
|
|
|
@ -46,7 +46,7 @@ const StyledNavLink = styled(NavLink)`
|
|||
const StyledDiv = StyledNavLink.withComponent('div');
|
||||
|
||||
type Props = {
|
||||
to?: string,
|
||||
to?: string | Object,
|
||||
onClick?: (SyntheticEvent<*>) => *,
|
||||
children?: React.Node,
|
||||
icon?: React.Node,
|
||||
|
@ -59,7 +59,6 @@ type Props = {
|
|||
active?: boolean,
|
||||
};
|
||||
|
||||
@withRouter
|
||||
@observer
|
||||
class SidebarLink extends React.Component<Props> {
|
||||
@observable expanded: boolean = false;
|
||||
|
@ -158,4 +157,4 @@ const Content = styled.div`
|
|||
width: 100%;
|
||||
`;
|
||||
|
||||
export default SidebarLink;
|
||||
export default withRouter(SidebarLink);
|
||||
|
|
|
@ -68,6 +68,11 @@ if (element) {
|
|||
/>
|
||||
<Route exact path="/auth/slack/post" component={SlackAuth} />
|
||||
<Route exact path="/auth/error" component={ErrorAuth} />
|
||||
<Route
|
||||
exact
|
||||
path={`/share/${matchDocumentSlug}`}
|
||||
component={Document}
|
||||
/>
|
||||
<Auth>
|
||||
<Layout>
|
||||
<Switch>
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
// @flow
|
||||
import * as React from 'react';
|
||||
import get from 'lodash/get';
|
||||
import debounce from 'lodash/debounce';
|
||||
import styled from 'styled-components';
|
||||
import breakpoint from 'styled-components-breakpoint';
|
||||
|
@ -26,7 +25,6 @@ import Actions from './components/Actions';
|
|||
import DocumentMove from './components/DocumentMove';
|
||||
import UiStore from 'stores/UiStore';
|
||||
import DocumentsStore from 'stores/DocumentsStore';
|
||||
import CollectionsStore from 'stores/CollectionsStore';
|
||||
import LoadingPlaceholder from 'components/LoadingPlaceholder';
|
||||
import LoadingIndicator from 'components/LoadingIndicator';
|
||||
import CenteredContent from 'components/CenteredContent';
|
||||
|
@ -44,7 +42,6 @@ type Props = {
|
|||
history: Object,
|
||||
location: Location,
|
||||
documents: DocumentsStore,
|
||||
collections: CollectionsStore,
|
||||
newDocument?: boolean,
|
||||
ui: UiStore,
|
||||
};
|
||||
|
@ -237,19 +234,19 @@ class DocumentScene extends React.Component<Props> {
|
|||
};
|
||||
|
||||
render() {
|
||||
const { location, match } = this.props;
|
||||
const Editor = this.editorComponent;
|
||||
const isMoving = this.props.match.path === matchDocumentMove;
|
||||
const isMoving = match.path === matchDocumentMove;
|
||||
const document = this.document;
|
||||
const titleText =
|
||||
get(document, 'title', '') ||
|
||||
this.props.collections.titleForDocument(this.props.location.pathname);
|
||||
const titleFromState = location.state ? location.state.title : '';
|
||||
const titleText = document ? document.title : titleFromState;
|
||||
|
||||
if (this.notFound) {
|
||||
return <Search notFound />;
|
||||
}
|
||||
|
||||
return (
|
||||
<Container key={this.props.location.pathname} column auto>
|
||||
<Container key={location.pathname} column auto>
|
||||
{isMoving && document && <DocumentMove document={document} />}
|
||||
{titleText && <PageTitle title={titleText} />}
|
||||
{(this.isLoading || this.isSaving) && <LoadingIndicator />}
|
||||
|
@ -322,6 +319,4 @@ const LoadingState = styled(LoadingPlaceholder)`
|
|||
margin: 90px 0;
|
||||
`;
|
||||
|
||||
export default withRouter(
|
||||
inject('ui', 'user', 'documents', 'collections')(DocumentScene)
|
||||
);
|
||||
export default withRouter(inject('ui', 'user', 'documents')(DocumentScene));
|
||||
|
|
|
@ -1,29 +1,18 @@
|
|||
// @flow
|
||||
import {
|
||||
observable,
|
||||
action,
|
||||
computed,
|
||||
ObservableMap,
|
||||
runInAction,
|
||||
autorunAsync,
|
||||
} from 'mobx';
|
||||
import { observable, action, computed, ObservableMap, runInAction } from 'mobx';
|
||||
import { client } from 'utils/ApiClient';
|
||||
import _ from 'lodash';
|
||||
import invariant from 'invariant';
|
||||
|
||||
import BaseStore from 'stores/BaseStore';
|
||||
import stores from 'stores';
|
||||
import Document from 'models/Document';
|
||||
import ErrorsStore from 'stores/ErrorsStore';
|
||||
import CacheStore from 'stores/CacheStore';
|
||||
import UiStore from 'stores/UiStore';
|
||||
import type { PaginationParams } from 'types';
|
||||
|
||||
const DOCUMENTS_CACHE_KEY = 'DOCUMENTS_CACHE_KEY';
|
||||
export const DEFAULT_PAGINATION_LIMIT = 25;
|
||||
|
||||
type Options = {
|
||||
cache: CacheStore,
|
||||
ui: UiStore,
|
||||
};
|
||||
|
||||
|
@ -35,7 +24,6 @@ class DocumentsStore extends BaseStore {
|
|||
@observable isFetching: boolean = false;
|
||||
|
||||
errors: ErrorsStore;
|
||||
cache: CacheStore;
|
||||
ui: UiStore;
|
||||
|
||||
/* Computed */
|
||||
|
@ -228,16 +216,9 @@ class DocumentsStore extends BaseStore {
|
|||
constructor(options: Options) {
|
||||
super();
|
||||
|
||||
this.errors = stores.errors;
|
||||
this.cache = options.cache;
|
||||
this.errors = options.errors;
|
||||
this.ui = options.ui;
|
||||
|
||||
this.cache.getItem(DOCUMENTS_CACHE_KEY).then(data => {
|
||||
if (data) {
|
||||
data.forEach(document => this.add(new Document(document)));
|
||||
}
|
||||
});
|
||||
|
||||
this.on('documents.delete', (data: { id: string }) => {
|
||||
this.remove(data.id);
|
||||
});
|
||||
|
@ -254,15 +235,6 @@ class DocumentsStore extends BaseStore {
|
|||
this.fetchRecentlyModified();
|
||||
this.fetchRecentlyViewed();
|
||||
});
|
||||
|
||||
autorunAsync('DocumentsStore.persists', () => {
|
||||
if (this.data.size) {
|
||||
this.cache.setItem(
|
||||
DOCUMENTS_CACHE_KEY,
|
||||
Array.from(this.data.values()).map(collection => collection.data)
|
||||
);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -2,13 +2,16 @@
|
|||
import AuthStore from './AuthStore';
|
||||
import UiStore from './UiStore';
|
||||
import ErrorsStore from './ErrorsStore';
|
||||
import DocumentsStore from './DocumentsStore';
|
||||
|
||||
const ui = new UiStore();
|
||||
const errors = new ErrorsStore();
|
||||
const stores = {
|
||||
user: null, // Including for Layout
|
||||
auth: new AuthStore(),
|
||||
ui: new UiStore(),
|
||||
errors: new ErrorsStore(),
|
||||
ui,
|
||||
errors,
|
||||
documents: new DocumentsStore({ ui, errors }),
|
||||
};
|
||||
window.stores = stores;
|
||||
|
||||
export default stores;
|
||||
|
|
Reference in New Issue