diff --git a/.gitignore b/.gitignore index d0f2ab4..b2b4665 100644 --- a/.gitignore +++ b/.gitignore @@ -7,4 +7,5 @@ dist/ ormconfig.json ormconfig.test.json .env -.directory \ No newline at end of file +.directory +.history \ No newline at end of file diff --git a/frontend/.gitignore b/frontend/.gitignore index 0e119c1..f6d0d68 100644 --- a/frontend/.gitignore +++ b/frontend/.gitignore @@ -8,4 +8,5 @@ ormconfig.json ormconfig.test.json .env .cache -.directory \ No newline at end of file +.directory +.history \ No newline at end of file diff --git a/frontend/src/App.tsx b/frontend/src/App.tsx index a137dac..ab6db2d 100644 --- a/frontend/src/App.tsx +++ b/frontend/src/App.tsx @@ -28,7 +28,7 @@ export function AppComponent(props: IAppComponentProps) { component={() => (loggedIn ? : )} /> loggedIn ? : } diff --git a/frontend/src/Documents/DocumentCard.tsx b/frontend/src/Documents/DocumentCard.tsx index cc2a1ee..3e16f72 100644 --- a/frontend/src/Documents/DocumentCard.tsx +++ b/frontend/src/Documents/DocumentCard.tsx @@ -1,12 +1,23 @@ import { Card, H4 } from "@blueprintjs/core"; import * as React from "react"; +import { RouteChildrenProps, withRouter } from "react-router"; 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 ( - -

{doc.name}

-
{doc.content}
+ props.history.push(`/docs/${props.doc.id}`)} + > +

{props.doc.name}

+
{props.doc.content}
); } + +export const DocumentCard = withRouter(DocumentCardComponent); diff --git a/frontend/src/Documents/Overview.tsx b/frontend/src/Documents/Overview.tsx index 1b66fe5..5f9d4cf 100644 --- a/frontend/src/Documents/Overview.tsx +++ b/frontend/src/Documents/Overview.tsx @@ -12,7 +12,7 @@ import { IAppState } from "~redux/reducers"; import { DocsList } from "./DocsList"; export interface IOverviewComponentProps { - all: { [key: number]: IDocumentJSON }; + allDocs: { [key: number]: IDocumentJSON }; fetching: boolean; spinner: boolean; @@ -28,14 +28,14 @@ export class OverviewComponent extends React.PureComponent< } public componentDidMount() { - if (!this.props.all) { + if (!this.props.allDocs) { this.props.fetchDocs(); } } public render() { - if (this.props.all) { - const docs = Object.values(this.props.all); + if (this.props.allDocs) { + const docs = Object.values(this.props.allDocs); const recent = [...docs]; recent.sort((a, b) => b.editedAt - a.editedAt); const recentCut = recent.splice(0, 4); @@ -60,7 +60,7 @@ export class OverviewComponent extends React.PureComponent< function mapStateToProps(state: IAppState) { return { - all: state.docs.all, + allDocs: state.docs.all, fetching: state.docs.fetching, spinner: state.docs.spinner, }; diff --git a/frontend/src/Home/Home.tsx b/frontend/src/Home/Home.tsx index 1ee152e..05cea07 100644 --- a/frontend/src/Home/Home.tsx +++ b/frontend/src/Home/Home.tsx @@ -1,7 +1,8 @@ import { Alignment, + Breadcrumbs, Button, - Classes, + IBreadcrumbProps, Menu, Navbar, Popover, @@ -10,12 +11,14 @@ import * as React from "react"; import { connect } from "react-redux"; import { Route, RouteComponentProps, Switch, withRouter } from "react-router"; import { Dispatch } from "redux"; +import { IDocumentJSON } from "~../../src/entity/Document"; import { IUserJSON } from "~../../src/entity/User"; import { Overview } from "~Documents/Overview"; import { IAppState } from "~redux/reducers"; import { logoutUser } from "~redux/user/actions"; interface IHomeProps extends RouteComponentProps { + allDocs: { [key: number]: IDocumentJSON }; user: IUserJSON | null; logout: () => void; } @@ -26,6 +29,23 @@ export class HomeComponent extends React.PureComponent { } 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 ( this.props.user && ( <> @@ -33,24 +53,7 @@ export class HomeComponent extends React.PureComponent { Writer -