mirror of
https://github.com/usatiuk/writer.git
synced 2025-10-29 00:17:48 +01:00
redirect to normal view if user owns the document
This commit is contained in:
@@ -4,7 +4,7 @@ import { Button, H1 } from "@blueprintjs/core";
|
|||||||
import * as React from "react";
|
import * as React from "react";
|
||||||
import Markdown from "react-markdown";
|
import Markdown from "react-markdown";
|
||||||
import { connect } from "react-redux";
|
import { connect } from "react-redux";
|
||||||
import { RouteComponentProps, withRouter } from "react-router";
|
import { Redirect, RouteComponentProps, withRouter } from "react-router";
|
||||||
import { Dispatch } from "redux";
|
import { Dispatch } from "redux";
|
||||||
import { IDocumentJSON } from "~../../src/entity/Document";
|
import { IDocumentJSON } from "~../../src/entity/Document";
|
||||||
import { LoadingStub } from "~LoadingStub";
|
import { LoadingStub } from "~LoadingStub";
|
||||||
@@ -12,11 +12,12 @@ import { NotFound } from "~NotFound";
|
|||||||
import { fetchSharedDoc } from "~redux/api/docs";
|
import { fetchSharedDoc } from "~redux/api/docs";
|
||||||
import { fetchDocsStart } from "~redux/docs/actions";
|
import { fetchDocsStart } from "~redux/docs/actions";
|
||||||
import { IAppState } from "~redux/reducers";
|
import { IAppState } from "~redux/reducers";
|
||||||
|
import { IUserJSON } from "../../../src/entity/User";
|
||||||
import { CodeBlock } from "./CodeBlock";
|
import { CodeBlock } from "./CodeBlock";
|
||||||
|
|
||||||
export interface ISharedViewComponentProps extends RouteComponentProps {
|
export interface ISharedViewComponentProps extends RouteComponentProps {
|
||||||
loggedIn: boolean;
|
loggedIn: boolean;
|
||||||
username: string | undefined;
|
user: IUserJSON | undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ISharedViewComponentState {
|
export interface ISharedViewComponentState {
|
||||||
@@ -51,7 +52,11 @@ export class SharedViewComponent extends React.PureComponent<
|
|||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
const { loggedIn, user } = this.props;
|
||||||
const { doc } = this.state;
|
const { doc } = this.state;
|
||||||
|
if (loggedIn && user.id === doc.user) {
|
||||||
|
return <Redirect to={`/docs/${doc.id}`} />;
|
||||||
|
}
|
||||||
return (
|
return (
|
||||||
<div className="viewComponent">
|
<div className="viewComponent">
|
||||||
<div className="document">
|
<div className="document">
|
||||||
@@ -88,8 +93,11 @@ export class SharedViewComponent extends React.PureComponent<
|
|||||||
function mapStateToProps(state: IAppState) {
|
function mapStateToProps(state: IAppState) {
|
||||||
return {
|
return {
|
||||||
loggedIn: state.user.user !== null,
|
loggedIn: state.user.user !== null,
|
||||||
username: state.user.user.username,
|
user: state.user.user,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export const SharedView = SharedViewComponent;
|
export const SharedView = withRouter(
|
||||||
|
connect(mapStateToProps)(SharedViewComponent),
|
||||||
|
);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user