@@ -6,95 +6,148 @@ import FFI exposing (getBridge)
6import Html exposing (..)
6import Html exposing (..)
7import Html.Attributes as Attr
7import Html.Attributes as Attr
8import Html.Events as Ev
8import Html.Events as Ev
10+import Pages.Loader exposing (loader)
11+import Pages.Login as Login
12+import Pages.Navigation as Navigation
9import Utils exposing (..)
13import Utils exposing (..)
13 = RecieveMessage String
17 = RecieveMessage String
14− | Error String
18+ | ShowError String
15− | UpdateEmail String
19+ | CloseNotification
16− | UpdateServer String
20+ | Submit { email : String, password : String, server : String }
17− | UpdatePassword String
21+ | LoginMsg Login.Msg
21type alias Model =
24type alias Model =
22 { messages : List String
25 { messages : List String
23− , error : Maybe String
26+ , notification : Maybe Notification.Config
24− , server : String
27+ , page : PageModel
32+ = LoginModel Login.Model
36+showPage : PageModel -> ( String, List (Html Msg) )
42+ Login.page loginCallbacks LoginMsg
44+ ( p.title model, p.view model )
30main : Program () Model Msg
50main : Program () Model Msg
32 Browser.element
52 Browser.element
33 { init = \_ -> ( init, Cmd.none )
53 { init = \_ -> ( init, Cmd.none )
34 , view = view
54 , view = view
35 , update = update
55 , update = update
36− , subscriptions = \_ -> getBridge Error (always (RecieveMessage "Got it!"))
62+ RecieveMessage "Got it!"
64+ Bridge.GotEverything everything ->
65+ RecieveMessage everything
40init : Model
70init : Model
42 { messages = []
72 { messages = []
43− , error = Nothing
73+ , notification = Nothing
44− , server = "bitwarden.iko.soy"
74+ , page = LoadingPage
45− , email = "mail@iko.soy"
50view : Model -> Html Msg
78view : Model -> Html Msg
51view model =
79view model =
53− (maybeList model.error (text >> List.singleton >> h2 [])
85+ [ Navigation.navigation { back = False, title = title }
54− ++ [ h1 [] [ text "HELLO" ]
86+ , main_ []
55− , ul [] (model.messages |> List.map (text >> List.singleton >> li []))
87+ (maybeList model.notification (Notification.notification CloseNotification)
56− , h4 [] [ text "Email" ]
88+ ++ body
57− , input [ Attr.type_ "text", Attr.value model.email, Ev.onInput UpdateEmail ] []
89+ )
58− , h4 [] [ text "Password" ]
59− , input [ Attr.type_ "text", Attr.value model.password, Ev.onInput UpdatePassword ] []
60− , h4 [] [ text "Server" ]
61− , input [ Attr.type_ "text", Attr.value model.server, Ev.onInput UpdateServer ] []
62− , button [ Ev.onClick Submit ] [ text "Submit" ]
65− (List.repeat 10 (tr [] [ td [] [ text "test" ] ]))
71update : Msg -> Model -> ( Model, Cmd Msg )
93update : Msg -> Model -> ( Model, Cmd Msg )
72update msg model =
94update msg model =
96+ processPage : (pageModel -> PageModel) -> ( Result String pageModel, Cmd Msg ) -> ( Model, Cmd Msg )
97+ processPage liftModel ( resultModel, cmd ) =
100+ ( { model | page = liftModel mdl }, cmd )
106+ { title = "An error had occured"
108+ , severity = Notification.Error
73 case msg of
114 case msg of
74 RecieveMessage x ->
115 RecieveMessage x ->
75 ( { model | messages = x :: model.messages }
116 ( { model | messages = x :: model.messages }
76 , Cmd.none
117 , Cmd.none
79− Error err ->
120+ ShowError err ->
80− ( { model | error = Just err }, Cmd.none )
121+ ( { model
82− UpdateEmail email ->
123+ Just
83− ( { model | email = email }, Cmd.none )
124+ { title = "Something went wrong"
85− UpdateServer server ->
126+ , severity = Notification.Error
86− ( { model | server = server }, Cmd.none )
129+ , Cmd.none
88− UpdatePassword password ->
132+ CloseNotification ->
133+ ( { model | notification = Nothing }
89− ( { model | password = password }, Cmd.none )
134+ , Cmd.none
91− Submit ->
137+ Submit data ->
93− , FFI.sendBridge
139+ , FFI.sendBridge (Bridge.Login data)
95− { email = model.email
96− , server = model.server
97− , password = model.password
145+ (Login.page loginCallbacks LoginMsg).update imsg page |> processPage LoginModel
151+loginCallbacks : Login.Callbacks Msg