diff --git a/app/components/CenteredContent/CenteredContent.js b/app/components/CenteredContent/CenteredContent.js index 85ca677d1..578d00556 100644 --- a/app/components/CenteredContent/CenteredContent.js +++ b/app/components/CenteredContent/CenteredContent.js @@ -8,7 +8,7 @@ type Props = { const Container = styled.div` width: 100%; - margin: 60px 20px; + margin: 60px; `; const Content = styled.div` diff --git a/app/components/Layout/Layout.js b/app/components/Layout/Layout.js index 226aea4bb..34e7a94b8 100644 --- a/app/components/Layout/Layout.js +++ b/app/components/Layout/Layout.js @@ -8,32 +8,21 @@ import { observer, inject } from 'mobx-react'; import keydown from 'react-keydown'; import Analytics from 'shared/components/Analytics'; import Flex from 'shared/components/Flex'; -import { color, layout } from 'shared/styles/constants'; +import { layout } from 'shared/styles/constants'; import { documentEditUrl, homeUrl, searchUrl } from 'utils/routeHelpers'; -import Avatar from 'components/Avatar'; import { LoadingIndicatorBar } from 'components/LoadingIndicator'; -import Scrollable from 'components/Scrollable'; -import HomeIcon from 'components/Icon/HomeIcon'; -import SearchIcon from 'components/Icon/SearchIcon'; -import StarredIcon from 'components/Icon/StarredIcon'; +import Sidebar from 'components/Sidebar'; +import Modals from 'components/Modals'; import Toasts from 'components/Toasts'; -import AccountMenu from 'menus/AccountMenu'; - -import SidebarCollections from './components/SidebarCollections'; -import SidebarLink from './components/SidebarLink'; -import HeaderBlock from './components/HeaderBlock'; -import Modals from './components/Modals'; import AuthStore from 'stores/AuthStore'; import UiStore from 'stores/UiStore'; -import CollectionsStore from 'stores/CollectionsStore'; import DocumentsStore from 'stores/DocumentsStore'; type Props = { history: Object, location: Location, - collections: CollectionsStore, documents: DocumentsStore, children?: ?React.Element, actions?: ?React.Element, @@ -75,31 +64,10 @@ class Layout extends React.Component { this.props.ui.setActiveModal('keyboard-shortcuts'); } - handleCreateCollection = () => { - this.props.ui.setActiveModal('collection-new'); - }; - - handleEditCollection = () => { - this.props.ui.setActiveModal('collection-edit'); - }; - - setScrollableRef = ref => { - this.scrollable = ref; - }; - - scrollToActiveDocument = ref => { - const scrollable = this.scrollable; - if (!ref || !scrollable) return; - - const container = scrollable.getBoundingClientRect(); - const bounds = ref.getBoundingClientRect(); - const scrollTop = bounds.top + container.top; - scrollable.scrollTop = scrollTop; - }; - render() { - const { auth, documents, ui } = this.props; + const { auth, ui } = this.props; const { user, team } = auth; + const showSidebar = auth.authenticated && user && team; return ( @@ -116,44 +84,7 @@ class Layout extends React.Component { {this.props.notifications} - {auth.authenticated && - user && - team && ( - - - - - } - /> - - - - - }> - Home - - }> - Search - - }> - Starred - - - - - - - - - )} + {showSidebar && } {this.props.children} @@ -177,23 +108,4 @@ const Content = styled(Flex)` transition: margin-left 200ms ease-in-out; `; -const Sidebar = styled(Flex)` - position: fixed; - top: 0; - bottom: 0; - left: ${props => (props.editMode ? `-${layout.sidebarWidth}` : 0)}; - width: ${layout.sidebarWidth}; - background: ${color.smoke}; - transition: left 200ms ease-in-out; -`; - -const LinkSection = styled(Flex)` - flex-direction: column; - margin: 24px 0; - padding: 0 24px; - position: relative; -`; - -export default withRouter( - inject('user', 'auth', 'ui', 'documents', 'collections')(Layout) -); +export default withRouter(inject('user', 'auth', 'ui', 'documents')(Layout)); diff --git a/app/components/Layout/components/Title.js b/app/components/Layout/components/Title.js deleted file mode 100644 index 532fe0e4e..000000000 --- a/app/components/Layout/components/Title.js +++ /dev/null @@ -1,44 +0,0 @@ -// @flow -import React from 'react'; -import _ from 'lodash'; -import styled from 'styled-components'; - -type Props = { - content: string, - truncate?: number, - placeholder?: ?string, -}; - -class Title extends React.Component { - props: Props; - - render() { - let title; - if (this.props.truncate) { - title = _.truncate(this.props.content, { length: this.props.truncate }); - } else { - title = this.props.content; - } - - let usePlaceholder; - if (this.props.children === null && this.props.placeholder) { - title = this.props.placeholder; - usePlaceholder = true; - } - - return ( - - {title &&  / } - - {title} - - - ); - } -} - -const TitleText = styled.span` - opacity: ${props => (props.untitled ? 0.5 : 1)}; -`; - -export default Title; diff --git a/app/components/Layout/index.js b/app/components/Layout/index.js index fb7b105d1..62fb061d0 100644 --- a/app/components/Layout/index.js +++ b/app/components/Layout/index.js @@ -1,7 +1,3 @@ // @flow import Layout from './Layout'; -import Title from './components/Title'; - export default Layout; - -export { Title }; diff --git a/app/components/Layout/components/Modals.js b/app/components/Modals/Modals.js similarity index 100% rename from app/components/Layout/components/Modals.js rename to app/components/Modals/Modals.js diff --git a/app/components/Modals/index.js b/app/components/Modals/index.js new file mode 100644 index 000000000..df1b93027 --- /dev/null +++ b/app/components/Modals/index.js @@ -0,0 +1,3 @@ +// @flow +import Modals from './Modals'; +export default Modals; diff --git a/app/components/Sidebar/Sidebar.js b/app/components/Sidebar/Sidebar.js new file mode 100644 index 000000000..1242e6638 --- /dev/null +++ b/app/components/Sidebar/Sidebar.js @@ -0,0 +1,117 @@ +// @flow +import React, { Component } from 'react'; +import { withRouter } from 'react-router-dom'; +import type { Location } from 'react-router-dom'; +import styled from 'styled-components'; +import { observer, inject } from 'mobx-react'; +import Flex from 'shared/components/Flex'; +import { color, layout } from 'shared/styles/constants'; + +import AccountMenu from 'menus/AccountMenu'; +import Avatar from 'components/Avatar'; +import Scrollable from 'components/Scrollable'; +import HomeIcon from 'components/Icon/HomeIcon'; +import SearchIcon from 'components/Icon/SearchIcon'; +import StarredIcon from 'components/Icon/StarredIcon'; +import Collections from './components/Collections'; +import SidebarLink from './components/SidebarLink'; +import HeaderBlock from './components/HeaderBlock'; + +import AuthStore from 'stores/AuthStore'; +import UiStore from 'stores/UiStore'; + +type Props = { + history: Object, + location: Location, + auth: AuthStore, + ui: UiStore, +}; + +@observer +class Sidebar extends Component { + props: Props; + scrollable: ?HTMLDivElement; + + handleCreateCollection = () => { + this.props.ui.setActiveModal('collection-new'); + }; + + handleEditCollection = () => { + this.props.ui.setActiveModal('collection-edit'); + }; + + setScrollableRef = ref => { + this.scrollable = ref; + }; + + scrollToActiveDocument = ref => { + const scrollable = this.scrollable; + if (!ref || !scrollable) return; + + const container = scrollable.getBoundingClientRect(); + const bounds = ref.getBoundingClientRect(); + const scrollTop = bounds.top + container.top; + scrollable.scrollTop = scrollTop; + }; + + render() { + const { auth, ui } = this.props; + const { user, team } = auth; + if (!user || !team) return; + + return ( + + + + + } + /> + + + +
+ }> + Home + + }> + Search + + }> + Starred + +
+
+ +
+
+
+
+ ); + } +} + +const Container = styled(Flex)` + position: fixed; + top: 0; + bottom: 0; + left: ${props => (props.editMode ? `-${layout.sidebarWidth}` : 0)}; + width: ${layout.sidebarWidth}; + background: ${color.smoke}; + transition: left 200ms ease-in-out; +`; + +const Section = styled(Flex)` + flex-direction: column; + margin: 24px 0; + padding: 0 24px; + position: relative; +`; + +export default withRouter(inject('user', 'auth', 'ui')(Sidebar)); diff --git a/app/components/Layout/components/SidebarCollections.js b/app/components/Sidebar/components/Collections.js similarity index 96% rename from app/components/Layout/components/SidebarCollections.js rename to app/components/Sidebar/components/Collections.js index e68f6f7f7..157c410fe 100644 --- a/app/components/Layout/components/SidebarCollections.js +++ b/app/components/Sidebar/components/Collections.js @@ -25,14 +25,13 @@ type Props = { location: Location, collections: CollectionsStore, documents: DocumentsStore, - activeDocument: ?Document, onCreateCollection: () => void, activeDocumentRef: HTMLElement => void, ui: UiStore, }; @observer -class SidebarCollections extends Component { +class Collections extends Component { props: Props; render() { @@ -40,7 +39,6 @@ class SidebarCollections extends Component { history, location, collections, - activeDocument, ui, activeDocumentRef, documents, @@ -55,7 +53,7 @@ class SidebarCollections extends Component { history={history} location={location} collection={collection} - activeDocument={activeDocument} + activeDocument={documents.active} activeDocumentRef={activeDocumentRef} prefetchDocument={documents.prefetchDocument} ui={ui} @@ -276,4 +274,4 @@ const Children = styled(Flex)` margin-left: 12px; `; -export default inject('collections', 'ui', 'documents')(SidebarCollections); +export default inject('collections', 'ui', 'documents')(Collections); diff --git a/app/components/Layout/components/HeaderBlock.js b/app/components/Sidebar/components/HeaderBlock.js similarity index 100% rename from app/components/Layout/components/HeaderBlock.js rename to app/components/Sidebar/components/HeaderBlock.js diff --git a/app/components/Layout/components/SidebarLink.js b/app/components/Sidebar/components/SidebarLink.js similarity index 100% rename from app/components/Layout/components/SidebarLink.js rename to app/components/Sidebar/components/SidebarLink.js diff --git a/app/components/Sidebar/index.js b/app/components/Sidebar/index.js new file mode 100644 index 000000000..c1b441c21 --- /dev/null +++ b/app/components/Sidebar/index.js @@ -0,0 +1,3 @@ +// @flow +import Sidebar from './Sidebar'; +export default Sidebar;