aboutsummaryrefslogtreecommitdiff
path: root/frontend/src/components/renderers
diff options
context:
space:
mode:
authorjackyzha0 <[email protected]>2020-05-22 20:46:21 -0700
committerjackyzha0 <[email protected]>2020-05-22 20:46:21 -0700
commitb09ce50ac2289a8b45fb98494042e2b8202fbcd3 (patch)
tree236df3dca635b30836a23f1f10a442698d8ec52b /frontend/src/components/renderers
parentstyling fixes (diff)
downloadctrl-v-b09ce50ac2289a8b45fb98494042e2b8202fbcd3.tar.xz
ctrl-v-b09ce50ac2289a8b45fb98494042e2b8202fbcd3.zip
switch to styled components for raw renderer
Diffstat (limited to 'frontend/src/components/renderers')
-rw-r--r--frontend/src/components/renderers/Dispatch.js56
-rw-r--r--frontend/src/components/renderers/Latex.js0
-rw-r--r--frontend/src/components/renderers/Raw.js21
3 files changed, 67 insertions, 10 deletions
diff --git a/frontend/src/components/renderers/Dispatch.js b/frontend/src/components/renderers/Dispatch.js
new file mode 100644
index 0000000..fc80a47
--- /dev/null
+++ b/frontend/src/components/renderers/Dispatch.js
@@ -0,0 +1,56 @@
+import React from 'react';
+import { FetchPaste } from '../../helpers/httpHelper'
+
+class Raw extends React.Component {
+
+ constructor(props) {
+ super(props);
+ this.state = {
+ content: '',
+ };
+ }
+
+ render() {
+ const styles = {
+ wordWrap: "break-word",
+ whiteSpace: "pre-wrap",
+ lineHeight: "initial",
+ fontSize: "0.8em",
+ padding: "0 1em"
+ }
+
+ return (
+ <pre style={styles}>
+ {this.state.content}
+ </pre>
+ );
+ }
+
+ 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
diff --git a/frontend/src/components/renderers/Latex.js b/frontend/src/components/renderers/Latex.js
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/frontend/src/components/renderers/Latex.js
diff --git a/frontend/src/components/renderers/Raw.js b/frontend/src/components/renderers/Raw.js
index a8d0e31..7f8e7c1 100644
--- a/frontend/src/components/renderers/Raw.js
+++ b/frontend/src/components/renderers/Raw.js
@@ -1,6 +1,15 @@
import React from 'react';
+import styled from 'styled-components'
import { FetchPaste } from '../../helpers/httpHelper'
+const RawText = styled.pre`
+ word-wrap: break-word;
+ white-space: pre-wrap;
+ line-height: initial;
+ font-size: 0.8em;
+ padding: 0 1em;
+`
+
class Raw extends React.Component {
constructor(props) {
@@ -11,18 +20,10 @@ class Raw extends React.Component {
}
render() {
- const styles = {
- wordWrap: "break-word",
- whiteSpace: "pre-wrap",
- lineHeight: "initial",
- fontSize: "0.8em",
- padding: "0 1em"
- }
-
return (
- <pre style={styles}>
+ <RawText>
{this.state.content}
- </pre>
+ </RawText>
);
}