-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstalk-form.tsx
54 lines (50 loc) · 1.95 KB
/
stalk-form.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import * as React from 'react';
import { Link } from 'react-router-dom';
import {fetchUser} from '../../utils/api-facade';
import {useState} from 'react';
const css = require('../../styles/stalk-form.css');
/**
* @param props - since it gets the props from the connected App, we have all actions and state:
* E.G props.setUser, props.sortFollowersByName, props.sortFollowersByScreenName.
*/
export function StalkForm(props) {
const [screenName, setScreenName] = useState('');
const [showSortingButtons, setShowSortingButtons] = useState(false);
function submitUser() {
fetchUser(screenName).then(response => {
const user = response.data;
/*
6. YOUR CODE HERE
Reset batch index using the action you have on props.
*/
/*
7. YOUR CODE HERE
Set the user using the action you have on the props.
*/
setShowSortingButtons(true);
}).catch(e => alert(`${screenName} is not an existing user, please put an existing user name`));
}
function SortingButtons() {
/*
12. YOUR CODE HERE
Implement the sorting functions
*/
const sortByName = () => null;
const sortByScreenName = () => null;
return (
<div className={css.sortingButtonsContainer}>
<button onClick={() => sortByName()} className={css.sortingButton}>Sort by name</button>
<button onClick={() => sortByScreenName()} className={css.sortingButton}>Sort by screen name</button>
</div>);
}
return (
<div className={css.root}>
<h2 className={css.title}>Which user would you like to stalk?</h2>
<div className={css.formStyle}>
<input onChange={e => setScreenName(e.target.value)} value={screenName} className={css.fieldStyle} type='text' name='username' placeholder='User Name' required />
<button onClick={submitUser} className={`${css.pushButton} ${css.blue}`}>Who Follows Him</button>
{showSortingButtons && <SortingButtons/>}
</div>
</div>
);
}