From 0b37c8b715b8f5ebea4472c9e7d6104ca8adbdc8 Mon Sep 17 00:00:00 2001 From: jackyzha0 Date: Fri, 15 May 2020 22:11:13 -0700 Subject: add view raw button --- frontend/src/components/App.js | 63 ++++++++++++++++++++------------ frontend/src/components/PasteInfo.js | 25 ++++++++++++- frontend/src/components/ViewPaste.js | 1 + frontend/src/components/renderers/Raw.js | 56 ++++++++++++++++++++++++++++ 4 files changed, 120 insertions(+), 25 deletions(-) create mode 100644 frontend/src/components/renderers/Raw.js (limited to 'frontend/src/components') diff --git a/frontend/src/components/App.js b/frontend/src/components/App.js index 3b147db..ae95dcb 100644 --- a/frontend/src/components/App.js +++ b/frontend/src/components/App.js @@ -10,6 +10,7 @@ import { Link, useParams } from "react-router-dom"; +import Raw from './renderers/Raw' const SpacedTitle = styled.div` margin-top: 10vh @@ -29,35 +30,49 @@ const GetPasteWithParam = () => { ); } +const GetRawWithParam = () => { + let { hash } = useParams(); + + return ( + + ); +} + function App() { return ( -
- - - - -
- - } - /> - - - - -
- -
-
+ + } + /> +
+ + + + +
+ + } + /> + + + + +
+ +
+
+
); } + export default App; diff --git a/frontend/src/components/PasteInfo.js b/frontend/src/components/PasteInfo.js index dabbb94..5217901 100644 --- a/frontend/src/components/PasteInfo.js +++ b/frontend/src/components/PasteInfo.js @@ -1,5 +1,6 @@ import React from 'react'; import styled from 'styled-components' +import { useHistory } from 'react-router-dom'; import { LangInput, ThemeInput } from './Inputs' const Bold = styled.span` @@ -7,10 +8,17 @@ const Bold = styled.span` ` const StyledDiv = styled.div` - margin: 2em 0; display: inline-block; ` +const Button = styled.button` + margin-left: 0 !important; +` + +const ButtonRow = styled.div` + display: inline; +` + const Flex = styled.div` float: right; display: flex; @@ -19,6 +27,12 @@ const Flex = styled.div` ` const PasteInfo = (props) => { + const history = useHistory(); + const redir = () => { + const redirUrl = `/raw/${props.hash}` + history.push(redirUrl); + } + return (
@@ -32,6 +46,15 @@ const PasteInfo = (props) => { id="themeInput" /> + + + expires: {props.expiry}
diff --git a/frontend/src/components/ViewPaste.js b/frontend/src/components/ViewPaste.js index 491c440..0b2ebe7 100644 --- a/frontend/src/components/ViewPaste.js +++ b/frontend/src/components/ViewPaste.js @@ -92,6 +92,7 @@ class ViewPaste extends React.Component { theme={this.state.theme} id="pasteInput" /> + {this.state.content} + + ); + } + + componentDidMount() { + FetchPaste(this.props.hash) + .then((response) => { + const data = response.data + this.setState({ content: data.content }) + }).catch((error) => { + const resp = error.response + + // catch 401 unauth (password protected) + if (resp.status === 401) { + this.setState({ content: 'err: password protected' }) + return + } + + // some weird err + if (resp !== undefined) { + const errTxt = `${resp.statusText}: ${resp.data}` + this.setState({ content: errTxt }) + return + } + + // some weird err (e.g. network) + this.setState({ content: error }) + }) + } +} + +export default Raw \ No newline at end of file -- cgit v1.2.3