simple docs ui

This commit is contained in:
2019-02-07 22:19:39 +03:00
parent acaf29f0e5
commit 0713f41d72
15 changed files with 384 additions and 81 deletions

View File

@@ -0,0 +1,62 @@
import { H1 } from "@blueprintjs/core";
import * as React from "react";
import { connect } from "react-redux";
import { Dispatch } from "redux";
import { IDocumentJSON } from "~../../src/entity/Document";
import { fetchDocsStart } from "~redux/docs/actions";
import { IAppState } from "~redux/reducers";
export interface IOverviewComponentProps {
recent: IDocumentJSON[] | null;
all: IDocumentJSON[] | null;
fetching: boolean;
fetchDocs: () => void;
}
export class OverviewComponent extends React.PureComponent<
IOverviewComponentProps,
null
> {
constructor(props: IOverviewComponentProps) {
super(props);
}
public componentDidMount() {
if (!this.props.all) {
this.props.fetchDocs();
}
}
public render() {
let docsList;
if (this.props.all) {
docsList = this.props.all.map(doc => (
<div key={doc.id}>
<H1>{doc.name}</H1>
<p>{doc.content}</p>
</div>
));
}
return docsList || <div>Loading</div>;
}
}
function mapStateToProps(state: IAppState) {
return {
recent: state.docs.recent,
all: state.docs.all,
fetching: state.docs.fetching,
};
}
function mapDispatchToProps(dispatch: Dispatch) {
return {
fetchDocs: () => dispatch(fetchDocsStart()),
};
}
export const Overview = connect(
mapStateToProps,
mapDispatchToProps,
)(OverviewComponent);