2017-05-26 19:56:10 +00:00
|
|
|
|
// @flow
|
2020-06-20 20:59:15 +00:00
|
|
|
|
import * as React from "react";
|
|
|
|
|
import { observable } from "mobx";
|
|
|
|
|
import { observer, inject } from "mobx-react";
|
2020-08-08 22:58:24 +00:00
|
|
|
|
import { Redirect, Link, Switch, Route, type Match } from "react-router-dom";
|
2020-06-20 20:59:15 +00:00
|
|
|
|
|
|
|
|
|
import styled, { withTheme } from "styled-components";
|
|
|
|
|
import { NewDocumentIcon, PlusIcon, PinIcon } from "outline-icons";
|
|
|
|
|
import RichMarkdownEditor from "rich-markdown-editor";
|
|
|
|
|
|
|
|
|
|
import { newDocumentUrl, collectionUrl } from "utils/routeHelpers";
|
|
|
|
|
import CollectionsStore from "stores/CollectionsStore";
|
|
|
|
|
import DocumentsStore from "stores/DocumentsStore";
|
|
|
|
|
import PoliciesStore from "stores/PoliciesStore";
|
|
|
|
|
import UiStore from "stores/UiStore";
|
|
|
|
|
import Collection from "models/Collection";
|
|
|
|
|
|
|
|
|
|
import Search from "scenes/Search";
|
|
|
|
|
import CollectionEdit from "scenes/CollectionEdit";
|
|
|
|
|
import CollectionMenu from "menus/CollectionMenu";
|
|
|
|
|
import Actions, { Action, Separator } from "components/Actions";
|
|
|
|
|
import Heading from "components/Heading";
|
|
|
|
|
import Tooltip from "components/Tooltip";
|
|
|
|
|
import CenteredContent from "components/CenteredContent";
|
|
|
|
|
import { ListPlaceholder } from "components/LoadingPlaceholder";
|
|
|
|
|
import InputSearch from "components/InputSearch";
|
|
|
|
|
import Mask from "components/Mask";
|
|
|
|
|
import Button from "components/Button";
|
|
|
|
|
import HelpText from "components/HelpText";
|
|
|
|
|
import DocumentList from "components/DocumentList";
|
|
|
|
|
import Subheading from "components/Subheading";
|
|
|
|
|
import PageTitle from "components/PageTitle";
|
2020-07-10 05:33:07 +00:00
|
|
|
|
import Flex from "components/Flex";
|
2020-06-20 20:59:15 +00:00
|
|
|
|
import Modal from "components/Modal";
|
|
|
|
|
import CollectionMembers from "scenes/CollectionMembers";
|
|
|
|
|
import Tabs from "components/Tabs";
|
|
|
|
|
import Tab from "components/Tab";
|
|
|
|
|
import PaginatedDocumentList from "components/PaginatedDocumentList";
|
|
|
|
|
import CollectionIcon from "components/CollectionIcon";
|
2017-05-26 19:56:10 +00:00
|
|
|
|
|
|
|
|
|
type Props = {
|
2017-11-20 04:16:49 +00:00
|
|
|
|
ui: UiStore,
|
2017-11-20 05:32:18 +00:00
|
|
|
|
documents: DocumentsStore,
|
2017-05-26 19:56:10 +00:00
|
|
|
|
collections: CollectionsStore,
|
2019-10-06 01:42:03 +00:00
|
|
|
|
policies: PoliciesStore,
|
2020-08-08 22:58:24 +00:00
|
|
|
|
match: Match,
|
2019-03-13 04:35:35 +00:00
|
|
|
|
theme: Object,
|
2017-05-26 19:56:10 +00:00
|
|
|
|
};
|
|
|
|
|
|
2017-11-10 22:14:30 +00:00
|
|
|
|
@observer
|
2018-05-05 23:16:08 +00:00
|
|
|
|
class CollectionScene extends React.Component<Props> {
|
2017-10-31 07:03:17 +00:00
|
|
|
|
@observable collection: ?Collection;
|
2017-11-20 04:16:49 +00:00
|
|
|
|
@observable isFetching: boolean = true;
|
2019-01-05 21:37:33 +00:00
|
|
|
|
@observable permissionsModalOpen: boolean = false;
|
2019-10-06 01:42:03 +00:00
|
|
|
|
@observable editModalOpen: boolean = false;
|
2019-01-19 08:23:39 +00:00
|
|
|
|
@observable redirectTo: ?string;
|
2017-05-26 19:56:10 +00:00
|
|
|
|
|
2017-11-20 05:32:18 +00:00
|
|
|
|
componentDidMount() {
|
2020-08-08 22:58:24 +00:00
|
|
|
|
const { id } = this.props.match.params;
|
|
|
|
|
if (id) {
|
|
|
|
|
this.loadContent(id);
|
|
|
|
|
}
|
2017-11-20 05:32:18 +00:00
|
|
|
|
}
|
2017-07-18 06:30:16 +00:00
|
|
|
|
|
2017-09-18 06:45:40 +00:00
|
|
|
|
componentWillReceiveProps(nextProps) {
|
2020-08-08 22:58:24 +00:00
|
|
|
|
const { id } = nextProps.match.params;
|
|
|
|
|
|
|
|
|
|
if (id && id !== this.props.match.params.id) {
|
|
|
|
|
this.loadContent(id);
|
2017-09-18 06:45:40 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-05 08:15:34 +00:00
|
|
|
|
componentWillUnmount() {
|
|
|
|
|
this.props.ui.clearActiveCollection();
|
|
|
|
|
}
|
|
|
|
|
|
2017-11-20 05:32:18 +00:00
|
|
|
|
loadContent = async (id: string) => {
|
2018-12-05 06:24:30 +00:00
|
|
|
|
const collection = await this.props.collections.fetch(id);
|
2017-11-20 05:32:18 +00:00
|
|
|
|
|
2017-11-20 04:16:49 +00:00
|
|
|
|
if (collection) {
|
|
|
|
|
this.props.ui.setActiveCollection(collection);
|
|
|
|
|
this.collection = collection;
|
2018-03-01 07:28:36 +00:00
|
|
|
|
|
2019-01-08 07:14:43 +00:00
|
|
|
|
await this.props.documents.fetchPinned({
|
2019-10-06 01:42:03 +00:00
|
|
|
|
collectionId: id,
|
2019-01-08 07:14:43 +00:00
|
|
|
|
});
|
2017-07-18 06:30:16 +00:00
|
|
|
|
}
|
2017-11-20 04:16:49 +00:00
|
|
|
|
|
2017-07-18 06:30:16 +00:00
|
|
|
|
this.isFetching = false;
|
2017-05-26 19:56:10 +00:00
|
|
|
|
};
|
|
|
|
|
|
2019-08-09 06:09:09 +00:00
|
|
|
|
onNewDocument = (ev: SyntheticEvent<>) => {
|
2017-11-20 07:39:56 +00:00
|
|
|
|
ev.preventDefault();
|
|
|
|
|
|
|
|
|
|
if (this.collection) {
|
2019-04-18 02:11:23 +00:00
|
|
|
|
this.redirectTo = newDocumentUrl(this.collection.id);
|
2017-11-20 07:39:56 +00:00
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2019-08-09 06:09:09 +00:00
|
|
|
|
onPermissions = (ev: SyntheticEvent<>) => {
|
2019-01-05 21:37:33 +00:00
|
|
|
|
ev.preventDefault();
|
|
|
|
|
this.permissionsModalOpen = true;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
handlePermissionsModalClose = () => {
|
|
|
|
|
this.permissionsModalOpen = false;
|
|
|
|
|
};
|
|
|
|
|
|
2019-10-06 01:42:03 +00:00
|
|
|
|
handleEditModalOpen = () => {
|
|
|
|
|
this.editModalOpen = true;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
handleEditModalClose = () => {
|
|
|
|
|
this.editModalOpen = false;
|
|
|
|
|
};
|
|
|
|
|
|
2018-01-30 21:16:20 +00:00
|
|
|
|
renderActions() {
|
2020-01-10 03:14:34 +00:00
|
|
|
|
const { match, policies } = this.props;
|
2020-08-08 22:58:24 +00:00
|
|
|
|
const can = policies.abilities(match.params.id || "");
|
2019-10-06 01:42:03 +00:00
|
|
|
|
|
2018-01-30 21:16:20 +00:00
|
|
|
|
return (
|
|
|
|
|
<Actions align="center" justify="flex-end">
|
2019-10-06 01:42:03 +00:00
|
|
|
|
{can.update && (
|
|
|
|
|
<React.Fragment>
|
2020-01-10 03:14:34 +00:00
|
|
|
|
<Action>
|
|
|
|
|
<InputSearch
|
|
|
|
|
placeholder="Search in collection…"
|
|
|
|
|
collectionId={match.params.id}
|
|
|
|
|
/>
|
|
|
|
|
</Action>
|
2019-10-06 01:42:03 +00:00
|
|
|
|
<Action>
|
|
|
|
|
<Tooltip
|
|
|
|
|
tooltip="New document"
|
|
|
|
|
shortcut="n"
|
|
|
|
|
delay={500}
|
|
|
|
|
placement="bottom"
|
|
|
|
|
>
|
|
|
|
|
<Button onClick={this.onNewDocument} icon={<PlusIcon />}>
|
|
|
|
|
New doc
|
|
|
|
|
</Button>
|
|
|
|
|
</Tooltip>
|
|
|
|
|
</Action>
|
|
|
|
|
<Separator />
|
|
|
|
|
</React.Fragment>
|
|
|
|
|
)}
|
2018-01-30 21:16:20 +00:00
|
|
|
|
<Action>
|
2019-07-13 17:15:38 +00:00
|
|
|
|
<CollectionMenu collection={this.collection} />
|
2018-01-30 21:16:20 +00:00
|
|
|
|
</Action>
|
|
|
|
|
</Actions>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-26 19:56:10 +00:00
|
|
|
|
render() {
|
2019-03-13 04:35:35 +00:00
|
|
|
|
const { documents, theme } = this.props;
|
2019-01-08 07:14:43 +00:00
|
|
|
|
|
2019-01-26 13:01:33 +00:00
|
|
|
|
if (this.redirectTo) return <Redirect to={this.redirectTo} push />;
|
2019-01-19 08:23:39 +00:00
|
|
|
|
if (!this.isFetching && !this.collection) return <Search notFound />;
|
2017-10-31 07:03:17 +00:00
|
|
|
|
|
2018-03-01 07:28:36 +00:00
|
|
|
|
const pinnedDocuments = this.collection
|
2019-01-08 07:14:43 +00:00
|
|
|
|
? documents.pinnedInCollection(this.collection.id)
|
2018-03-01 07:28:36 +00:00
|
|
|
|
: [];
|
|
|
|
|
const hasPinnedDocuments = !!pinnedDocuments.length;
|
2019-01-05 21:37:33 +00:00
|
|
|
|
const collection = this.collection;
|
2018-03-01 07:28:36 +00:00
|
|
|
|
|
2017-07-18 06:30:16 +00:00
|
|
|
|
return (
|
|
|
|
|
<CenteredContent>
|
2019-01-05 21:37:33 +00:00
|
|
|
|
{collection ? (
|
2018-03-01 07:28:36 +00:00
|
|
|
|
<React.Fragment>
|
2019-01-05 21:37:33 +00:00
|
|
|
|
<PageTitle title={collection.name} />
|
|
|
|
|
{collection.isEmpty ? (
|
2019-01-06 02:23:57 +00:00
|
|
|
|
<Centered column>
|
2019-01-05 21:37:33 +00:00
|
|
|
|
<HelpText>
|
2019-01-06 02:23:57 +00:00
|
|
|
|
<strong>{collection.name}</strong> doesn’t contain any
|
2020-08-09 01:53:11 +00:00
|
|
|
|
documents yet.
|
|
|
|
|
<br />
|
|
|
|
|
Get started by creating a new one!
|
2019-01-05 21:37:33 +00:00
|
|
|
|
</HelpText>
|
|
|
|
|
<Wrapper>
|
2019-04-18 02:11:23 +00:00
|
|
|
|
<Link to={newDocumentUrl(collection.id)}>
|
2019-03-13 04:35:35 +00:00
|
|
|
|
<Button icon={<NewDocumentIcon color={theme.buttonText} />}>
|
2019-01-06 02:23:57 +00:00
|
|
|
|
Create a document
|
|
|
|
|
</Button>
|
2020-08-09 01:53:11 +00:00
|
|
|
|
</Link>
|
|
|
|
|
|
2019-01-05 21:37:33 +00:00
|
|
|
|
{collection.private && (
|
|
|
|
|
<Button onClick={this.onPermissions} neutral>
|
2019-10-06 01:42:03 +00:00
|
|
|
|
Manage members…
|
2019-01-05 21:37:33 +00:00
|
|
|
|
</Button>
|
|
|
|
|
)}
|
|
|
|
|
</Wrapper>
|
|
|
|
|
<Modal
|
2020-03-15 03:48:32 +00:00
|
|
|
|
title="Collection permissions"
|
2019-01-05 21:37:33 +00:00
|
|
|
|
onRequestClose={this.handlePermissionsModalClose}
|
|
|
|
|
isOpen={this.permissionsModalOpen}
|
|
|
|
|
>
|
2019-10-06 01:42:03 +00:00
|
|
|
|
<CollectionMembers
|
2019-01-05 21:37:33 +00:00
|
|
|
|
collection={this.collection}
|
|
|
|
|
onSubmit={this.handlePermissionsModalClose}
|
2019-10-06 01:42:03 +00:00
|
|
|
|
onEdit={this.handleEditModalOpen}
|
|
|
|
|
/>
|
|
|
|
|
</Modal>
|
|
|
|
|
<Modal
|
|
|
|
|
title="Edit collection"
|
|
|
|
|
onRequestClose={this.handleEditModalClose}
|
|
|
|
|
isOpen={this.editModalOpen}
|
|
|
|
|
>
|
|
|
|
|
<CollectionEdit
|
|
|
|
|
collection={this.collection}
|
|
|
|
|
onSubmit={this.handleEditModalClose}
|
2019-01-05 21:37:33 +00:00
|
|
|
|
/>
|
|
|
|
|
</Modal>
|
2019-01-06 02:23:57 +00:00
|
|
|
|
</Centered>
|
2019-01-05 21:37:33 +00:00
|
|
|
|
) : (
|
2018-03-01 07:28:36 +00:00
|
|
|
|
<React.Fragment>
|
2019-01-06 02:23:57 +00:00
|
|
|
|
<Heading>
|
2020-06-20 20:59:15 +00:00
|
|
|
|
<CollectionIcon collection={collection} size={40} expanded />{" "}
|
2019-01-06 02:23:57 +00:00
|
|
|
|
{collection.name}
|
|
|
|
|
</Heading>
|
|
|
|
|
|
2019-01-05 21:37:33 +00:00
|
|
|
|
{collection.description && (
|
|
|
|
|
<RichMarkdownEditor
|
2019-01-21 19:06:44 +00:00
|
|
|
|
id={collection.id}
|
2019-01-05 21:37:33 +00:00
|
|
|
|
key={collection.description}
|
|
|
|
|
defaultValue={collection.description}
|
2019-03-13 04:35:35 +00:00
|
|
|
|
theme={theme}
|
2019-01-05 21:37:33 +00:00
|
|
|
|
readOnly
|
|
|
|
|
/>
|
|
|
|
|
)}
|
|
|
|
|
|
|
|
|
|
{hasPinnedDocuments && (
|
|
|
|
|
<React.Fragment>
|
|
|
|
|
<Subheading>
|
|
|
|
|
<TinyPinIcon size={18} /> Pinned
|
|
|
|
|
</Subheading>
|
2019-04-09 04:47:27 +00:00
|
|
|
|
<DocumentList documents={pinnedDocuments} showPin />
|
2019-01-05 21:37:33 +00:00
|
|
|
|
</React.Fragment>
|
|
|
|
|
)}
|
|
|
|
|
|
2019-01-08 07:14:43 +00:00
|
|
|
|
<Tabs>
|
|
|
|
|
<Tab to={collectionUrl(collection.id)} exact>
|
|
|
|
|
Recently updated
|
|
|
|
|
</Tab>
|
2020-06-20 20:59:15 +00:00
|
|
|
|
<Tab to={collectionUrl(collection.id, "recent")} exact>
|
2019-01-08 07:14:43 +00:00
|
|
|
|
Recently published
|
|
|
|
|
</Tab>
|
2020-06-20 20:59:15 +00:00
|
|
|
|
<Tab to={collectionUrl(collection.id, "old")} exact>
|
2019-01-08 07:42:55 +00:00
|
|
|
|
Least recently updated
|
|
|
|
|
</Tab>
|
2020-06-20 20:59:15 +00:00
|
|
|
|
<Tab to={collectionUrl(collection.id, "alphabetical")} exact>
|
2019-01-08 07:42:55 +00:00
|
|
|
|
A–Z
|
|
|
|
|
</Tab>
|
2019-01-08 07:14:43 +00:00
|
|
|
|
</Tabs>
|
|
|
|
|
<Switch>
|
2020-06-20 20:59:15 +00:00
|
|
|
|
<Route path={collectionUrl(collection.id, "alphabetical")}>
|
2019-01-08 07:42:55 +00:00
|
|
|
|
<PaginatedDocumentList
|
|
|
|
|
key="alphabetical"
|
|
|
|
|
documents={documents.alphabeticalInCollection(
|
|
|
|
|
collection.id
|
|
|
|
|
)}
|
|
|
|
|
fetch={documents.fetchAlphabetical}
|
2020-06-17 03:56:17 +00:00
|
|
|
|
options={{ collectionId: collection.id }}
|
2019-04-09 04:47:27 +00:00
|
|
|
|
showPin
|
2019-01-08 07:42:55 +00:00
|
|
|
|
/>
|
|
|
|
|
</Route>
|
2020-06-20 20:59:15 +00:00
|
|
|
|
<Route path={collectionUrl(collection.id, "old")}>
|
2019-01-08 07:42:55 +00:00
|
|
|
|
<PaginatedDocumentList
|
|
|
|
|
key="old"
|
|
|
|
|
documents={documents.leastRecentlyUpdatedInCollection(
|
|
|
|
|
collection.id
|
|
|
|
|
)}
|
|
|
|
|
fetch={documents.fetchLeastRecentlyUpdated}
|
2020-06-17 03:56:17 +00:00
|
|
|
|
options={{ collectionId: collection.id }}
|
2019-04-09 04:47:27 +00:00
|
|
|
|
showPin
|
2019-01-08 07:42:55 +00:00
|
|
|
|
/>
|
|
|
|
|
</Route>
|
2020-06-20 20:59:15 +00:00
|
|
|
|
<Route path={collectionUrl(collection.id, "recent")}>
|
2019-01-08 07:14:43 +00:00
|
|
|
|
<PaginatedDocumentList
|
|
|
|
|
key="recent"
|
|
|
|
|
documents={documents.recentlyPublishedInCollection(
|
|
|
|
|
collection.id
|
|
|
|
|
)}
|
|
|
|
|
fetch={documents.fetchRecentlyPublished}
|
2020-06-17 03:56:17 +00:00
|
|
|
|
options={{ collectionId: collection.id }}
|
2019-01-08 07:14:43 +00:00
|
|
|
|
showPublished
|
2019-04-09 04:47:27 +00:00
|
|
|
|
showPin
|
2019-01-08 07:14:43 +00:00
|
|
|
|
/>
|
|
|
|
|
</Route>
|
|
|
|
|
<Route path={collectionUrl(collection.id)}>
|
|
|
|
|
<PaginatedDocumentList
|
|
|
|
|
documents={documents.recentlyUpdatedInCollection(
|
|
|
|
|
collection.id
|
|
|
|
|
)}
|
|
|
|
|
fetch={documents.fetchRecentlyUpdated}
|
2020-06-17 03:56:17 +00:00
|
|
|
|
options={{ collectionId: collection.id }}
|
2019-04-09 04:47:27 +00:00
|
|
|
|
showPin
|
2019-01-08 07:14:43 +00:00
|
|
|
|
/>
|
|
|
|
|
</Route>
|
|
|
|
|
</Switch>
|
2018-03-01 07:28:36 +00:00
|
|
|
|
</React.Fragment>
|
|
|
|
|
)}
|
|
|
|
|
|
2018-01-30 21:16:20 +00:00
|
|
|
|
{this.renderActions()}
|
2018-03-01 07:28:36 +00:00
|
|
|
|
</React.Fragment>
|
2017-11-20 05:50:42 +00:00
|
|
|
|
) : (
|
2019-01-05 21:37:33 +00:00
|
|
|
|
<React.Fragment>
|
|
|
|
|
<Heading>
|
|
|
|
|
<Mask height={35} />
|
|
|
|
|
</Heading>
|
|
|
|
|
<ListPlaceholder count={5} />
|
|
|
|
|
</React.Fragment>
|
2017-11-20 05:50:42 +00:00
|
|
|
|
)}
|
2017-07-18 06:30:16 +00:00
|
|
|
|
</CenteredContent>
|
|
|
|
|
);
|
2017-05-26 19:56:10 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2017-07-18 06:30:16 +00:00
|
|
|
|
|
2019-01-06 02:23:57 +00:00
|
|
|
|
const Centered = styled(Flex)`
|
|
|
|
|
text-align: center;
|
|
|
|
|
margin: 40vh auto 0;
|
|
|
|
|
max-width: 380px;
|
|
|
|
|
transform: translateY(-50%);
|
|
|
|
|
`;
|
|
|
|
|
|
2018-03-01 07:28:36 +00:00
|
|
|
|
const TinyPinIcon = styled(PinIcon)`
|
|
|
|
|
position: relative;
|
|
|
|
|
top: 4px;
|
|
|
|
|
opacity: 0.8;
|
|
|
|
|
`;
|
|
|
|
|
|
2017-11-20 07:39:56 +00:00
|
|
|
|
const Wrapper = styled(Flex)`
|
2019-01-06 02:23:57 +00:00
|
|
|
|
justify-content: center;
|
2017-10-31 07:03:17 +00:00
|
|
|
|
margin: 10px 0;
|
2017-07-18 06:30:16 +00:00
|
|
|
|
`;
|
|
|
|
|
|
2020-08-09 01:53:11 +00:00
|
|
|
|
export default inject(
|
|
|
|
|
"collections",
|
|
|
|
|
"policies",
|
|
|
|
|
"documents",
|
|
|
|
|
"ui"
|
|
|
|
|
)(withTheme(CollectionScene));
|