This repository has been archived by the owner on May 11, 2021. It is now read-only.
-
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.
feat: App state token is now option(token)
- Loading branch information
1 parent
4b88f98
commit 6638062
Showing
3 changed files
with
19 additions
and
10 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 |
---|---|---|
@@ -1,31 +1,39 @@ | ||
type state = {token: string}; | ||
type state = {token: option(string)}; | ||
|
||
type action = | ||
| Login(string) | ||
| Logout; | ||
|
||
let reducer = (action, _state) => | ||
switch (action) { | ||
| Login(jwt) => ReasonReact.Update({token: jwt}) | ||
| Logout => ReasonReact.Update({token: ""}) | ||
| Login(jwt) => ReasonReact.Update({token: Js.Option.some(jwt)}) | ||
| Logout => ReasonReact.Update({token: None}) | ||
}; | ||
|
||
let component = ReasonReact.reducerComponent("App"); | ||
|
||
let make = _children => { | ||
...component, | ||
reducer, | ||
initialState: () => {token: ""}, | ||
initialState: () => {token: None}, | ||
render: self => | ||
<div className="app"> | ||
( | ||
(self.state.token === "") ? | ||
<Login updateToken=(token => self.send(Login(token))) /> | ||
: | ||
switch (self.state.token) { | ||
| None => | ||
<Login updateToken=( | ||
token => | ||
switch (token) { | ||
| Some(token) => self.send(Login(token)) | ||
| None => self.send(Logout) | ||
} | ||
) /> | ||
| Some(_token) => | ||
<JobApp | ||
submitHandler=(_event => self.send(Logout)) | ||
signOutHandler=(_event => self.send(Logout)) | ||
/> | ||
} | ||
) | ||
</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