diff options
| author | jackyzha0 <[email protected]> | 2020-05-12 21:09:50 -0700 |
|---|---|---|
| committer | jackyzha0 <[email protected]> | 2020-05-12 21:09:50 -0700 |
| commit | 07a3d810065e6e8b838c5e53bc7d18241e0ff3c5 (patch) | |
| tree | cddc9aa74c9ed1ff1ef8cdbec365ba516a14cff5 /frontend/src/components/ViewPaste.js | |
| parent | Merge pull request #18 from jackyzha0/no-pass-rendering (diff) | |
| download | ctrl-v-07a3d810065e6e8b838c5e53bc7d18241e0ff3c5.tar.xz ctrl-v-07a3d810065e6e8b838c5e53bc7d18241e0ff3c5.zip | |
password modal
Diffstat (limited to 'frontend/src/components/ViewPaste.js')
| -rw-r--r-- | frontend/src/components/ViewPaste.js | 50 |
1 files changed, 42 insertions, 8 deletions
diff --git a/frontend/src/components/ViewPaste.js b/frontend/src/components/ViewPaste.js index 79b1840..4b7c46c 100644 --- a/frontend/src/components/ViewPaste.js +++ b/frontend/src/components/ViewPaste.js @@ -3,6 +3,7 @@ import axios from 'axios'; import Error from './Err'; import { TitleInput, PasteInput } from './Inputs'; import PasteInfo from './PasteInfo'; +import PasswordModal from './PasswordModal' const RENDER_MODES = Object.freeze({ RAW: 'raw text', @@ -19,10 +20,18 @@ class ViewPaste extends React.Component { title: 'untitled paste', content: '', hasPass: false, + enteredPass: '', + validPass: false, expiry: 'no expiry', error: '', mode: RENDER_MODES.RAW, }; + + this.handleChange = this.handleChange.bind(this); + } + + handleChange(event) { + this.setState({ enteredPass: event.target.value }); } newErr(msg, duration = 5000) { @@ -50,9 +59,21 @@ class ViewPaste extends React.Component { } } + validatePass(pass) { + // stub + console.log(pass) + // need to toggle validPass + } + render() { return ( <div> + <PasswordModal + hasPass={this.state.hasPass} + validPass={this.state.validPass} + value={this.state.enteredPass} + onChange={this.handleChange} + validateCallback={this.validatePass} /> <TitleInput value={this.state.title} id="titleInput" @@ -74,28 +95,41 @@ class ViewPaste extends React.Component { return d.toLocaleDateString("en-US", options).toLocaleLowerCase() } + setStateFromData(data) { + this.setState({ + title: data.title, + content: data.content, + expiry: this.fmtDateStr(data.expiry), + }) + } + componentDidMount() { const serverURL = `http://localhost:8080/api/${this.props.hash}` axios.get(serverURL) .then((response) => { const data = response.data - this.setState({ - title: data.title, - content: data.content, - expiry: this.fmtDateStr(data.expiry), - }) + this.setStateFromData(data) }).catch((error) => { const resp = error.response + console.log(resp.status) + + // catch 401 unauth (password protected) + if (resp.status === 401) { + this.setState({hasPass: true}) + return + } + // some weird err if (resp !== undefined) { const errTxt = `${resp.statusText}: ${resp.data}` this.newErr(errTxt, -1) - } else { - // some weird err (e.g. network) - this.newErr(error, -1) + return } + + // some weird err (e.g. network) + this.newErr(error, -1) }) } } |