-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
355 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,73 @@ | ||
import React from "react"; | ||
import AutosizeInput from "react-input-autosize"; | ||
|
||
export default ({ value, onClick, onSubmit, editable }) => | ||
editable ? ( | ||
<span className="ba bw2 b--black"> | ||
<input type="text" value={value} /> | ||
</span> | ||
) : ( | ||
<span>{value}</span> | ||
); | ||
export default class EditableInput extends React.Component { | ||
constructor() { | ||
super(); | ||
|
||
this.state = { | ||
focused: false | ||
}; | ||
|
||
this.onFocus = this.onFocus.bind(this); | ||
this.onBlur = this.onBlur.bind(this); | ||
} | ||
|
||
onFocus() { | ||
this.setState({ | ||
focused: true | ||
}); | ||
} | ||
|
||
onBlur() { | ||
this.setState({ | ||
focused: false | ||
}); | ||
} | ||
|
||
render() { | ||
const { | ||
props: { className, value, multiline }, | ||
state: { focused } | ||
} = this; | ||
|
||
return ( | ||
<div className="mv0 dib"> | ||
{focused ? ( | ||
<AutosizeInput | ||
value={value} | ||
autoComplete="off" | ||
autoFocus | ||
ref={i => { | ||
this.inputRef = i; | ||
}} | ||
inputStyle={{ | ||
fontFamily: "inherit" | ||
}} | ||
type="text" | ||
name={this.props.name} | ||
onChange={this.props.onChange} | ||
onBlur={this.onBlur} | ||
placeholder={this.props.placeholder} | ||
inputClassName={`mw-100 db input-reset outline-0 ba bw1 b--black ph2 pv0 ${className}`} | ||
onKeyDown={e => { | ||
console.log({ e, k: e.key }); | ||
if (e.key === "Enter") this.onBlur(); | ||
}} | ||
/> | ||
) : ( | ||
<span | ||
className={`db ba bw1 b--white ph2 pv0 ${className}`} | ||
onClick={this.onFocus} | ||
onFocus={this.onFocus} | ||
tabIndex="0" | ||
> | ||
{console.log(value, !!value, this.props.placeholder) || value !== "" | ||
? value | ||
: this.props.placeholder} | ||
</span> | ||
)} | ||
</div> | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import { Component } from "react"; | ||
import axios from "axios"; | ||
|
||
const PENDING = "PENDING"; | ||
const ERROR = "ERROR"; | ||
const DONE = "DONE"; | ||
|
||
export default class FetchData extends Component { | ||
state = { | ||
requestStatus: PENDING | ||
}; | ||
|
||
componentDidMount() { | ||
axios[this.props.method](this.props.url, { | ||
headers: { | ||
Authorization: `Bearer ${window.localStorage.getItem("jwt")}` | ||
} | ||
}).then( | ||
response => { | ||
this.setState({ | ||
payload: response.data, | ||
requestStatus: DONE | ||
}); | ||
}, | ||
error => { | ||
this.setState({ | ||
error, | ||
requestStatus: ERROR | ||
}); | ||
} | ||
); | ||
} | ||
|
||
render() { | ||
const { | ||
state: { requestStatus, payload, error }, | ||
props: { renderPending, renderError, children } | ||
} = this; | ||
|
||
console.log("rendering", requestStatus); | ||
|
||
if (requestStatus === PENDING) return renderPending(); | ||
|
||
if (requestStatus === ERROR) return renderError(error); | ||
|
||
return children(payload); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.