-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs(todo): no preload, show users in login page
- Loading branch information
Showing
3 changed files
with
23 additions
and
13 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,20 +3,37 @@ | |
* @author junbao <[email protected]> | ||
*/ | ||
|
||
import { useDispatch } from 'amos/react'; | ||
import { useDispatch, useSelector } from 'amos/react'; | ||
import { memo, useState } from 'react'; | ||
import { signIn } from '../store/user.actions'; | ||
import { userMapBox } from '../store/user.boxes'; | ||
|
||
export const SignIn = memo(() => { | ||
const [input, setInput] = useState(''); | ||
const dispatch = useDispatch(); | ||
const userMap = useSelector(userMapBox); | ||
return ( | ||
<div className="sign-in"> | ||
<input placeholder="Your name" value={input} onChange={(e) => setInput(e.target.value)} /> | ||
| ||
<button disabled={!input.trim()} onClick={() => dispatch(signIn(input))}> | ||
Sign In | ||
</button> | ||
<br /> | ||
{userMap.size() > 0 && ( | ||
<div> | ||
<br /> | ||
<span>Users: </span> | ||
{Array.from(userMap.values(), (u) => ( | ||
<> | ||
<button key={u.id} onClick={() => dispatch(signIn(u.name))}> | ||
{u.name} | ||
</button> | ||
| ||
</> | ||
))} | ||
</div> | ||
)} | ||
</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
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