breadcrumbs for docs

This commit is contained in:
2019-02-08 14:42:45 +03:00
parent 684729fa54
commit cbf0c9d49d
6 changed files with 49 additions and 32 deletions

3
.gitignore vendored
View File

@@ -7,4 +7,5 @@ dist/
ormconfig.json ormconfig.json
ormconfig.test.json ormconfig.test.json
.env .env
.directory .directory
.history

3
frontend/.gitignore vendored
View File

@@ -8,4 +8,5 @@ ormconfig.json
ormconfig.test.json ormconfig.test.json
.env .env
.cache .cache
.directory .directory
.history

View File

@@ -28,7 +28,7 @@ export function AppComponent(props: IAppComponentProps) {
component={() => (loggedIn ? <Home /> : <Landing />)} component={() => (loggedIn ? <Home /> : <Landing />)}
/> />
<Route <Route
path="/files" path="/docs/:id"
component={() => component={() =>
loggedIn ? <Home /> : <Redirect to="/login" /> loggedIn ? <Home /> : <Redirect to="/login" />
} }

View File

@@ -1,12 +1,23 @@
import { Card, H4 } from "@blueprintjs/core"; import { Card, H4 } from "@blueprintjs/core";
import * as React from "react"; import * as React from "react";
import { RouteChildrenProps, withRouter } from "react-router";
import { IDocumentJSON } from "~../../src/entity/Document"; import { IDocumentJSON } from "~../../src/entity/Document";
export function DocumentCard({ doc }: { doc: IDocumentJSON }) { export interface IDocumentCardComponentProps extends RouteChildrenProps {
doc: IDocumentJSON;
}
export function DocumentCardComponent(props: IDocumentCardComponentProps) {
return ( return (
<Card className="card" interactive={true}> <Card
<H4>{doc.name}</H4> className="card"
<div className="textPreview">{doc.content}</div> interactive={true}
onClick={() => props.history.push(`/docs/${props.doc.id}`)}
>
<H4>{props.doc.name}</H4>
<div className="textPreview">{props.doc.content}</div>
</Card> </Card>
); );
} }
export const DocumentCard = withRouter(DocumentCardComponent);

View File

@@ -12,7 +12,7 @@ import { IAppState } from "~redux/reducers";
import { DocsList } from "./DocsList"; import { DocsList } from "./DocsList";
export interface IOverviewComponentProps { export interface IOverviewComponentProps {
all: { [key: number]: IDocumentJSON }; allDocs: { [key: number]: IDocumentJSON };
fetching: boolean; fetching: boolean;
spinner: boolean; spinner: boolean;
@@ -28,14 +28,14 @@ export class OverviewComponent extends React.PureComponent<
} }
public componentDidMount() { public componentDidMount() {
if (!this.props.all) { if (!this.props.allDocs) {
this.props.fetchDocs(); this.props.fetchDocs();
} }
} }
public render() { public render() {
if (this.props.all) { if (this.props.allDocs) {
const docs = Object.values(this.props.all); const docs = Object.values(this.props.allDocs);
const recent = [...docs]; const recent = [...docs];
recent.sort((a, b) => b.editedAt - a.editedAt); recent.sort((a, b) => b.editedAt - a.editedAt);
const recentCut = recent.splice(0, 4); const recentCut = recent.splice(0, 4);
@@ -60,7 +60,7 @@ export class OverviewComponent extends React.PureComponent<
function mapStateToProps(state: IAppState) { function mapStateToProps(state: IAppState) {
return { return {
all: state.docs.all, allDocs: state.docs.all,
fetching: state.docs.fetching, fetching: state.docs.fetching,
spinner: state.docs.spinner, spinner: state.docs.spinner,
}; };

View File

@@ -1,7 +1,8 @@
import { import {
Alignment, Alignment,
Breadcrumbs,
Button, Button,
Classes, IBreadcrumbProps,
Menu, Menu,
Navbar, Navbar,
Popover, Popover,
@@ -10,12 +11,14 @@ import * as React from "react";
import { connect } from "react-redux"; import { connect } from "react-redux";
import { Route, RouteComponentProps, Switch, withRouter } from "react-router"; import { Route, RouteComponentProps, Switch, withRouter } from "react-router";
import { Dispatch } from "redux"; import { Dispatch } from "redux";
import { IDocumentJSON } from "~../../src/entity/Document";
import { IUserJSON } from "~../../src/entity/User"; import { IUserJSON } from "~../../src/entity/User";
import { Overview } from "~Documents/Overview"; import { Overview } from "~Documents/Overview";
import { IAppState } from "~redux/reducers"; import { IAppState } from "~redux/reducers";
import { logoutUser } from "~redux/user/actions"; import { logoutUser } from "~redux/user/actions";
interface IHomeProps extends RouteComponentProps { interface IHomeProps extends RouteComponentProps {
allDocs: { [key: number]: IDocumentJSON };
user: IUserJSON | null; user: IUserJSON | null;
logout: () => void; logout: () => void;
} }
@@ -26,6 +29,23 @@ export class HomeComponent extends React.PureComponent<IHomeProps> {
} }
public render() { public render() {
const breadcrumbs: IBreadcrumbProps[] = [
{
icon: "home",
text: "Home",
onClick: () => this.props.history.push("/"),
},
];
if ((this.props.match.params as any).id && this.props.allDocs) {
const { id } = this.props.match.params as any;
breadcrumbs.push({
icon: "document",
text: this.props.allDocs[id].name,
onClick: () => this.props.history.push(`/docs/${id}`),
});
}
return ( return (
this.props.user && ( this.props.user && (
<> <>
@@ -33,24 +53,7 @@ export class HomeComponent extends React.PureComponent<IHomeProps> {
<Navbar.Group align={Alignment.LEFT}> <Navbar.Group align={Alignment.LEFT}>
<Navbar.Heading>Writer</Navbar.Heading> <Navbar.Heading>Writer</Navbar.Heading>
<Navbar.Divider /> <Navbar.Divider />
<Button <Breadcrumbs items={breadcrumbs} />
className={Classes.MINIMAL}
icon="home"
text="Home"
active={this.props.location.pathname === "/"}
onClick={() => this.props.history.push("/")}
/>
<Button
className={Classes.MINIMAL}
icon="document"
text="Files"
active={
this.props.location.pathname === "/files"
}
onClick={() =>
this.props.history.push("/files")
}
/>
</Navbar.Group> </Navbar.Group>
<Navbar.Group align={Alignment.RIGHT}> <Navbar.Group align={Alignment.RIGHT}>
<Popover <Popover
@@ -74,6 +77,7 @@ export class HomeComponent extends React.PureComponent<IHomeProps> {
<div id="MainScreen"> <div id="MainScreen">
<Switch> <Switch>
<Route exact={true} path="/" component={Overview} /> <Route exact={true} path="/" component={Overview} />
<Route path="/docs/:id" component={Overview} />
</Switch> </Switch>
</div> </div>
</> </>
@@ -83,7 +87,7 @@ export class HomeComponent extends React.PureComponent<IHomeProps> {
} }
function mapStateToProps(state: IAppState) { function mapStateToProps(state: IAppState) {
return { user: state.user.user }; return { allDocs: state.docs.all, user: state.user.user };
} }
function mapDispatchToProps(dispatch: Dispatch) { function mapDispatchToProps(dispatch: Dispatch) {