From 0144bfc9cc6c616a00a8171f3950a75ec948427e Mon Sep 17 00:00:00 2001 From: jackyzha0 Date: Sun, 11 Apr 2021 10:27:27 -0700 Subject: base next refactor --- frontend/src/components/PasteInfo.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'frontend/src/components/PasteInfo.js') diff --git a/frontend/src/components/PasteInfo.js b/frontend/src/components/PasteInfo.js index 6ab5b19..2f912fb 100644 --- a/frontend/src/components/PasteInfo.js +++ b/frontend/src/components/PasteInfo.js @@ -1,8 +1,8 @@ import React from 'react'; import styled from 'styled-components' -import { useHistory } from 'react-router-dom'; import { Theme } from './Inputs' import {Button} from "./Common/Button"; +import {useRouter} from "next/router"; const Bold = styled.span` font-weight: 700 @@ -28,10 +28,10 @@ const Flex = styled.div` ` const PasteInfo = (props) => { - const history = useHistory(); + const router = useRouter() const redirRaw = () => { const redirUrl = `/raw/${props.hash}` - history.push(redirUrl); + router.push(redirUrl); } const renderable = () => { -- cgit v1.2.3 From ed65c8b61d2c7955998f877ee501ef84a1473626 Mon Sep 17 00:00:00 2001 From: jackyzha0 Date: Sun, 11 Apr 2021 12:42:42 -0700 Subject: refactor error handling in pasteinfo --- frontend/src/components/PasteInfo.js | 34 +++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 15 deletions(-) (limited to 'frontend/src/components/PasteInfo.js') diff --git a/frontend/src/components/PasteInfo.js b/frontend/src/components/PasteInfo.js index 2f912fb..1ef69cc 100644 --- a/frontend/src/components/PasteInfo.js +++ b/frontend/src/components/PasteInfo.js @@ -3,6 +3,7 @@ import styled from 'styled-components' import { Theme } from './Inputs' import {Button} from "./Common/Button"; import {useRouter} from "next/router"; +import {ErrMsg} from "./Err"; const Bold = styled.span` font-weight: 700 @@ -27,21 +28,21 @@ const Flex = styled.div` flex-direction: row; ` -const PasteInfo = (props) => { +const PasteInfo = ({hash, lang, theme, expiry, toggleRenderCallback, isRenderMode, onChange, err}) => { const router = useRouter() const redirRaw = () => { - const redirUrl = `/raw/${props.hash}` + const redirUrl = `/raw/${hash}` router.push(redirUrl); } const renderable = () => { - const buttonTxt = props.isRenderMode ? 'text' : 'render' - if (props.lang === 'latex' || props.lang === 'markdown') { + const buttonTxt = isRenderMode ? 'text' : 'render' + if (lang === 'latex' || lang === 'markdown') { return ( + onClick={toggleRenderCallback}> {buttonTxt} ); @@ -59,20 +60,23 @@ const PasteInfo = (props) => { {renderable()} - - language: {props.lang} - - - expires: {props.expiry} - + {err ? + {err} : + <> + + language: {lang} + + + expires: {expiry} + + + } -
- {props.err} ); } -- cgit v1.2.3