зеркало из
1
0
Форкнуть 0
This commit is contained in:
Eugene Tolmachev 2020-10-09 15:53:45 -04:00
Родитель e6e7d27a97
Коммит ce1e9edbf2
3 изменённых файлов: 16 добавлений и 9 удалений

Просмотреть файл

@ -7,15 +7,19 @@ open Types
let init (account, cmd: Cmd) route : Model*Cmd<Msg> = let init (account, cmd: Cmd) route : Model*Cmd<Msg> =
match route, account with match route, account with
| Some Routes.Home, Some r -> | Some r, Some a ->
Unauthenticated, Cmd.ofMsg (LoggedIn r) Unauthenticated r, Cmd.ofMsg (LoggedIn a)
| _ -> Unauthenticated, cmd.login LoggedIn Failed | Some r, None ->
Unauthenticated r, cmd.login LoggedIn Failed
| _ -> Unauthenticated Routes.Home, cmd.login LoggedIn Failed
let update (cmd: Cmd) (msg: Msg) (model: Model) = let update (cmd: Cmd) (msg: Msg) (model: Model) =
match model, msg with match model, msg with
| _, LogIn -> | Unauthenticated route, LogIn ->
Unauthenticated, cmd.login LoggedIn Failed Unauthenticated route, cmd.login LoggedIn Failed
| Authenticated state, LogIn ->
Unauthenticated state.route, cmd.login LoggedIn Failed
| _, LoggedIn r -> | _, LoggedIn r ->
Authenticated { route = Routes.Home Authenticated { route = Routes.Home
user = None }, user = None },
@ -27,8 +31,9 @@ let update (cmd: Cmd) (msg: Msg) (model: Model) =
console.error e console.error e
model, Cmd.none model, Cmd.none
| _, LogOut -> | _, LogOut ->
Unauthenticated, Cmd.batch [ cmd.logout Failed Unauthenticated Routes.Guest,
Navigation.newUrl (Routes.toAddress Routes.Guest)] Cmd.batch [ cmd.logout Failed
Navigation.newUrl (Routes.toAddress Routes.Guest)]
| _ -> model, Cmd.none | _ -> model, Cmd.none
@ -36,6 +41,8 @@ let urlUpdate (result: Option<Routes.Route>) model =
match result, model with match result, model with
| Some page, Authenticated state -> | Some page, Authenticated state ->
Authenticated {state with route = page}, [] Authenticated {state with route = page}, []
| Some route, Unauthenticated _ ->
Unauthenticated route, []
| _ -> | _ ->
model, Navigation.modifyUrl (Routes.toAddress Routes.Home) // no matching route - go home model, Navigation.modifyUrl (Routes.toAddress Routes.Home) // no matching route - go home

Просмотреть файл

@ -6,7 +6,7 @@ type AuthenticatedState =
type Model = type Model =
| Authenticated of AuthenticatedState | Authenticated of AuthenticatedState
| Unauthenticated | Unauthenticated of Routes.Route
type Msg = type Msg =
| Failed of exn | Failed of exn

Просмотреть файл

@ -30,4 +30,4 @@ let root (model: Model) dispatch =
] ]
] ] ] ] ] ] ] ]
| Unauthenticated -> div [] [] | Unauthenticated _ -> div [] []