From 712bf925f8ae84a5a2fee87b8aa3c969df48fd50 Mon Sep 17 00:00:00 2001 From: jackyzha0 Date: Sat, 16 May 2020 22:42:48 -0700 Subject: allow language saving --- frontend/src/components/NewPaste.js | 7 +++++-- frontend/src/components/Options.js | 6 +++++- frontend/src/components/PasteInfo.js | 1 + frontend/src/components/ViewPaste.js | 11 +++++++++-- frontend/src/components/renderers/Code.js | 2 +- frontend/src/css/index.css | 2 +- frontend/src/helpers/httpHelper.js | 1 + 7 files changed, 23 insertions(+), 7 deletions(-) (limited to 'frontend/src') diff --git a/frontend/src/components/NewPaste.js b/frontend/src/components/NewPaste.js index 0b1c795..6e1b507 100644 --- a/frontend/src/components/NewPaste.js +++ b/frontend/src/components/NewPaste.js @@ -4,6 +4,7 @@ import OptionsContainer from './Options' import Error from './Err' import { PostNewPaste } from '../helpers/httpHelper' import PasteModal from './modals/PasteModal' +import { LANGS } from './renderers/Code' class NewPaste extends React.Component { constructor(props) { @@ -12,6 +13,7 @@ class NewPaste extends React.Component { title: '', content: '', pass: '', + language: LANGS.raw, expiry: '', hash: '', error: '', @@ -73,12 +75,13 @@ class NewPaste extends React.Component { content={this.state.content} maxLength="100000" id="pasteInput" /> - - + + ); } diff --git a/frontend/src/components/Options.js b/frontend/src/components/Options.js index 21e932a..f874c35 100644 --- a/frontend/src/components/Options.js +++ b/frontend/src/components/Options.js @@ -1,6 +1,6 @@ import React from 'react'; import styled from 'styled-components' -import { PassInput, ExpiryInput } from './Inputs' +import { PassInput, ExpiryInput, LangInput } from './Inputs' const Flex = styled.div` float: right; @@ -17,6 +17,10 @@ class OptionsContainer extends React.Component { value={this.props.pass} onChange={this.props.onChange} id="passwordInput" /> + { expires: {props.expiry} + {props.err} ); diff --git a/frontend/src/components/ViewPaste.js b/frontend/src/components/ViewPaste.js index 0b2ebe7..81d78f3 100644 --- a/frontend/src/components/ViewPaste.js +++ b/frontend/src/components/ViewPaste.js @@ -34,7 +34,6 @@ class ViewPaste extends React.Component { handleChange(event) { const target = event.target; const name = target.name; - console.log(target, name) this.setState({ [name]: target.value @@ -96,8 +95,8 @@ class ViewPaste extends React.Component { lang={this.state.language} theme={this.state.theme} onChange={this.handleChange} + err={} expiry={this.state.expiry} /> - ); } @@ -109,9 +108,11 @@ class ViewPaste extends React.Component { } setStateFromData(data) { + console.log(data) this.setState({ title: data.title, content: data.content, + language: data.language, expiry: this.fmtDateStr(data.expiry), }) } @@ -124,6 +125,12 @@ class ViewPaste extends React.Component { }).catch((error) => { const resp = error.response + // network err + if (!resp) { + this.ErrorLabel.current.showMessage(error) + return + } + // catch 401 unauth (password protected) if (resp.status === 401) { this.setState({hasPass: true}) diff --git a/frontend/src/components/renderers/Code.js b/frontend/src/components/renderers/Code.js index 12efc67..a024bb7 100644 --- a/frontend/src/components/renderers/Code.js +++ b/frontend/src/components/renderers/Code.js @@ -14,7 +14,7 @@ export const THEMES = Object.freeze({ export const LANGS = Object.freeze({ 'go': 'go', 'python': 'python', - 'javascript': 'javascript', + 'js': 'javascript', 'html': 'html', 'css': 'css', 'c': 'c', diff --git a/frontend/src/css/index.css b/frontend/src/css/index.css index c0e669c..f377fd5 100644 --- a/frontend/src/css/index.css +++ b/frontend/src/css/index.css @@ -69,7 +69,7 @@ code, pre { } .Dropdown-placeholder { - width: 7em; + width: 5em; } .Dropdown-menu { diff --git a/frontend/src/helpers/httpHelper.js b/frontend/src/helpers/httpHelper.js index 27695d5..28704f5 100644 --- a/frontend/src/helpers/httpHelper.js +++ b/frontend/src/helpers/httpHelper.js @@ -24,6 +24,7 @@ export function PostNewPaste(state) { var bodyFormData = new FormData(); bodyFormData.set('title', state.title); bodyFormData.set('content', state.content); + bodyFormData.set('language', state.language); bodyFormData.set('password', state.pass); bodyFormData.set('expiry', parseExpiry(state.expiry)); -- cgit v1.2.3 From 069a92c001f2f588417b649b31e4d473dfaaa75d Mon Sep 17 00:00:00 2001 From: jackyzha0 Date: Sat, 16 May 2020 22:54:55 -0700 Subject: remove lang input --- frontend/src/components/PasteInfo.js | 21 ++++++++++++++------- frontend/src/css/index.css | 2 +- 2 files changed, 15 insertions(+), 8 deletions(-) (limited to 'frontend/src') diff --git a/frontend/src/components/PasteInfo.js b/frontend/src/components/PasteInfo.js index b1abda6..ea4981c 100644 --- a/frontend/src/components/PasteInfo.js +++ b/frontend/src/components/PasteInfo.js @@ -1,7 +1,7 @@ import React from 'react'; import styled from 'styled-components' import { useHistory } from 'react-router-dom'; -import { LangInput, ThemeInput } from './Inputs' +import { ThemeInput } from './Inputs' const Bold = styled.span` font-weight: 700 @@ -19,6 +19,10 @@ const ButtonRow = styled.div` display: inline; ` +const SpacedText = styled.span` + margin-right: 1em; +` + const Flex = styled.div` float: right; display: flex; @@ -36,10 +40,6 @@ const PasteInfo = (props) => { return (
- { > view raw + + language: {props.lang} + + + expires: {props.expiry} + + + {props.err} + - expires: {props.expiry} - {props.err}
); diff --git a/frontend/src/css/index.css b/frontend/src/css/index.css index f377fd5..488ee08 100644 --- a/frontend/src/css/index.css +++ b/frontend/src/css/index.css @@ -69,7 +69,7 @@ code, pre { } .Dropdown-placeholder { - width: 5em; + width: 5.5em; } .Dropdown-menu { -- cgit v1.2.3