Text handling done!
This commit is contained in:
parent
25f973e2b3
commit
3027e6c611
9 changed files with 559 additions and 38 deletions
|
|
@ -6,17 +6,22 @@ import { CSSTransition } from 'react-transition-group';
|
|||
import putUrlHandler from '../axios/putUrlHandler';
|
||||
|
||||
export default () => {
|
||||
const [state, setState] = useState('');
|
||||
const [isLoading, setLoading] = useState(false);
|
||||
const [resultUrl, setResultUrl] = useState(null);
|
||||
const [state, setState] = useState({
|
||||
url: null,
|
||||
loading: false,
|
||||
result: null,
|
||||
});
|
||||
|
||||
const submit = (evt) => {
|
||||
evt.preventDefault();
|
||||
if (state.length) {
|
||||
setLoading(true);
|
||||
putUrlHandler(state).then((data) => {
|
||||
setResultUrl(`http://${window.location.host}/u/${data}`.replace('5000', '3000'));
|
||||
setLoading(false);
|
||||
if (state.url) {
|
||||
setState({ ...state, loading: true });
|
||||
putUrlHandler(state.url).then((data) => {
|
||||
setState({
|
||||
...state,
|
||||
result: `http://${window.location.host}/u/${data}`.replace('5000', '3000'),
|
||||
loading: false,
|
||||
});
|
||||
});
|
||||
}
|
||||
};
|
||||
|
|
@ -33,22 +38,22 @@ export default () => {
|
|||
type="text"
|
||||
value={state.url}
|
||||
placeholder="URL To Shorten (https://...)"
|
||||
onChange={(evt) => setState(evt.target.value)}
|
||||
onChange={(evt) => setState({ ...state, url: evt.target.value })}
|
||||
required
|
||||
/>
|
||||
<InputGroup.Append>
|
||||
<Button type="submit" disabled={isLoading}>
|
||||
{isLoading ? 'Loading...' : 'Submit'}
|
||||
<Button type="submit" disabled={state.loading || !state.url}>
|
||||
{state.loading ? 'Loading...' : 'Submit'}
|
||||
</Button>
|
||||
</InputGroup.Append>
|
||||
</InputGroup>
|
||||
</Form.Group>
|
||||
</Form>
|
||||
|
||||
{resultUrl && (
|
||||
{state.result && (
|
||||
<h5 className="text-center">
|
||||
<a rel="noopener noreferrer" href={resultUrl} target="_blank">
|
||||
{resultUrl}
|
||||
<a rel="noopener noreferrer" href={state.result} target="_blank">
|
||||
{state.result}
|
||||
</a>
|
||||
</h5>
|
||||
)}
|
||||
|
|
|
|||
Loading…
Reference in a new issue