forked from supermario/lamdera-realworld
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Shared.elm
109 lines (80 loc) · 2.45 KB
/
Shared.elm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
module Shared exposing
( Flags
, Model
, Msg(..)
, init
, subscriptions
, update
, view
)
import Api.User exposing (User)
import Bridge exposing (..)
import Components.Footer
import Components.Navbar
import Html exposing (..)
import Html.Attributes exposing (class, href, rel)
import Request exposing (Request)
import Utils.Route
import View exposing (View)
-- INIT
type alias Flags =
()
type alias Model =
{ user : Maybe User
}
init : Request -> Flags -> ( Model, Cmd Msg )
init _ json =
( Model Nothing
, Cmd.none
)
-- UPDATE
type Msg
= ClickedSignOut
| SignedInUser User
update : Request -> Msg -> Model -> ( Model, Cmd Msg )
update _ msg model =
case msg of
SignedInUser user ->
( { model | user = Just user }
, Cmd.none
)
ClickedSignOut ->
( { model | user = Nothing }
, model.user |> Maybe.map (\user -> sendToBackend (SignedOut user)) |> Maybe.withDefault Cmd.none
)
subscriptions : Request -> Model -> Sub Msg
subscriptions _ _ =
Sub.none
-- VIEW
view :
Request
-> { page : View msg, toMsg : Msg -> msg }
-> Model
-> View msg
view req { page, toMsg } model =
{ title =
if String.isEmpty page.title then
"Conduit"
else
page.title ++ " | Conduit"
, body =
css
++ [ div [ class "layout" ]
[ Components.Navbar.view
{ user = model.user
, currentRoute = Utils.Route.fromUrl req.url
, onSignOut = toMsg ClickedSignOut
}
, div [ class "page" ] page.body
, Components.Footer.view
]
]
}
css =
-- Import Ionicon icons & Google Fonts our Bootstrap theme relies on
[ Html.node "link" [ rel "stylesheet", href "//code.ionicframework.com/ionicons/2.0.1/css/ionicons.min.css" ] []
, Html.node "link" [ rel "stylesheet", href "//fonts.googleapis.com/css?family=Titillium+Web:700|Source+Serif+Pro:400,700|Merriweather+Sans:400,700|Source+Sans+Pro:400,300,600,700,300italic,400italic,600italic,700italic" ] []
-- Import the custom Bootstrap 4 theme from our hosted CDN
, Html.node "link" [ rel "stylesheet", href "//demo.productionready.io/main.css" ] []
, Html.node "link" [ rel "stylesheet", href "/style.css" ] []
]