Skip to content

Commit

Permalink
Handle log out
Browse files Browse the repository at this point in the history
  • Loading branch information
yukims19 committed Jan 15, 2019
1 parent 5176f18 commit 51fdaab
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 11 deletions.
28 changes: 23 additions & 5 deletions spotify-app/src/User.bs.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

42 changes: 36 additions & 6 deletions spotify-app/src/User.re
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ module Css = AppStyle;
let userIcon = requireAssetURI("./img/user.png");

type action =
| HandleLogOut
| Toggle;

type state = {isDropdownOpen: bool};
Expand All @@ -17,13 +18,35 @@ let userAccountWrapper = [%css

let component = ReasonReact.reducerComponent("User");

let make = _children => {
let make = (~auth, ~setLogInStatus, ~userName, _children) => {
...component,
initialState: () => {isDropdownOpen: false},
reducer: (action, state) =>
switch (action) {
| Toggle => ReasonReact.Update({isDropdownOpen: !state.isDropdownOpen})
},
Js.Promise.(
OneGraphAuth.(
switch (action) {
| HandleLogOut =>
Js.log("Clicked LogOut!!");
ReasonReact.SideEffects(
(
_state =>
auth
|> logout(_, "gmail")
|> then_(() => isLoggedIn(auth, "gmail"))
|> then_(loginStatus => {
Js.log(loginStatus);
setLogInStatus(loginStatus);
resolve();
})
|> catch(err => resolve(Js.log(err)))
|> ignore
),
);
| Toggle =>
ReasonReact.Update({isDropdownOpen: !state.isDropdownOpen})
}
)
),
render: self =>
ReasonReact.(
<header className={Css.flexWrapper(~justify=`flexEnd, ~align=`center)}>
Expand All @@ -42,11 +65,18 @@ let make = _children => {
}>
<img className=Css.userIcon src=userIcon alt="user icon" />
<p style={ReactDOMRe.Style.make(~margin="0px", ())}>
{ReasonReact.string("userABC")}
{
switch (userName) {
| Some(userName) => ReasonReact.string(userName)
| None => null
}
}
</p>
</DropdownToggle>
<DropdownMenu right=true>
<DropdownItem> {string("Sign Out")} </DropdownItem>
<DropdownItem onClick={() => self.send(HandleLogOut)}>
{string("Sign Out")}
</DropdownItem>
</DropdownMenu>
</Dropdown>
</div>
Expand Down

0 comments on commit 51fdaab

Please sign in to comment.