Skip to content

Commit 60405b5

Browse files
committed
setup architecture
1 parent 669f917 commit 60405b5

20 files changed

+354
-28
lines changed

elm.json

+23-6
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,45 @@
11
{
22
"type": "application",
33
"source-directories": [
4-
"src"
4+
"src",
5+
"openapi",
6+
"themes"
57
],
68
"elm-version": "0.19.1",
79
"dependencies": {
810
"direct": {
11+
"BrianHicks/elm-css-reset": "1.0.2",
12+
"danyx23/elm-uuid": "2.1.2",
913
"elm/browser": "1.0.2",
1014
"elm/core": "1.0.5",
11-
"elm/html": "1.0.0"
12-
},
13-
"indirect": {
15+
"elm/html": "1.0.0",
16+
"elm/http": "2.0.0",
1417
"elm/json": "1.1.3",
1518
"elm/time": "1.0.0",
1619
"elm/url": "1.0.0",
17-
"elm/virtual-dom": "1.0.2"
20+
"rtfeldman/elm-css": "16.1.1",
21+
"rtfeldman/elm-iso8601-date-strings": "1.1.4"
22+
},
23+
"indirect": {
24+
"elm/bytes": "1.0.8",
25+
"elm/file": "1.0.5",
26+
"elm/parser": "1.1.0",
27+
"elm/random": "1.0.0",
28+
"elm/regex": "1.0.0",
29+
"elm/virtual-dom": "1.0.2",
30+
"rtfeldman/elm-hex": "1.0.0"
1831
}
1932
},
2033
"test-dependencies": {
2134
"direct": {
35+
"avh4/elm-program-test": "3.6.3",
2236
"elm-explorations/test": "1.2.2"
2337
},
2438
"indirect": {
25-
"elm/random": "1.0.0"
39+
"avh4/elm-fifo": "1.0.4",
40+
"elm-community/list-extra": "8.5.2",
41+
"hecrj/html-parser": "2.4.0",
42+
"mgold/elm-nonempty-list": "4.2.0"
2643
}
2744
}
2845
}

index.html

-3
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,6 @@
77
<title>Vite App</title>
88
</head>
99
<body>
10-
<div id="app">
11-
<div></div>
12-
</div>
1310
<script type="module" src="/src/main.js"></script>
1411
</body>
1512
</html>

src/Effect.elm

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
module Effect exposing (Effect(..), n, perform)
2+
3+
import Browser.Navigation as Nav
4+
import Msg exposing (Msg)
5+
6+
7+
type Effect
8+
= NoEffect
9+
| NavLoadEffect String
10+
| NavPushUrlEffect Nav.Key String
11+
12+
13+
n : model -> ( model, Effect )
14+
n model =
15+
( model, NoEffect )
16+
17+
18+
perform : Effect -> Cmd Msg
19+
perform effect =
20+
case effect of
21+
NoEffect ->
22+
Cmd.none
23+
24+
NavLoadEffect url ->
25+
Nav.load url
26+
27+
NavPushUrlEffect key url ->
28+
Nav.pushUrl key url

src/Init.elm

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
module Init exposing (init)
2+
3+
import Browser.Navigation as Nav
4+
import Effect exposing (Effect(..), n)
5+
import Iknaio
6+
import Locale.Init as Locale
7+
import Model exposing (..)
8+
import Url exposing (Url)
9+
10+
11+
init : Flags -> Url -> Nav.Key -> ( Model, Effect )
12+
init _ url key =
13+
n
14+
{ url = url
15+
, key = key
16+
, locale = Locale.init
17+
, theme = Iknaio.theme
18+
, search = ()
19+
, user = ()
20+
}

src/Locale.elm

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
module Locale.Update exposing (update)
2+
3+
import Locale.Effect exposing (Effect, n)
4+
import Locale.Model exposing (Model)
5+
import Locale.Msg exposing (Msg(..))
6+
7+
8+
update : Msg -> Model -> ( Model, Effect )
9+
update msg model =
10+
n model

src/Locale/Effect.elm

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
module Locale.Effect exposing (Effect(..), n)
2+
3+
4+
type Effect
5+
= NoEffect
6+
7+
8+
n : model -> ( model, Effect )
9+
n model =
10+
( model, NoEffect )

src/Locale/Init.elm

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
module Locale.Init exposing (init)
2+
3+
import Locale.Model as Model exposing (Model)
4+
5+
6+
init : Model
7+
init =
8+
{ getString = \str -> str
9+
}

src/Locale/Model.elm

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
module Locale.Model exposing (Model)
2+
3+
4+
type alias Model =
5+
{ getString : String -> String
6+
}

src/Locale/Update.elm

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
module Locale exposing (..)
2+
3+
import Locale.Effect as Effect exposing (n)
4+
import Locale.Model as Model exposing (..)
5+
import Locale.Msg as Msg exposing (Msg)
6+
7+
8+
update : Msg -> Model -> Model
9+
update msg model =
10+
n model

src/Main.elm

+21-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,29 @@
11
module Main exposing (main)
22

33
import Browser
4-
import Msg exposing (Msg)
4+
import Effect exposing (perform)
5+
import Init exposing (init)
6+
import Model exposing (Flags, Model)
7+
import Msg exposing (Msg(..))
8+
import Sub exposing (subscriptions)
9+
import Tuple
510
import Update exposing (update)
611
import View exposing (view)
712

813

9-
main : Program () Int Msg
14+
main : Program Flags Model Msg
1015
main =
11-
Browser.sandbox { init = 0, update = update, view = view }
16+
Browser.application
17+
{ init =
18+
\flags url key ->
19+
init flags url key
20+
|> Tuple.mapSecond perform
21+
, update =
22+
\msg model ->
23+
update msg model
24+
|> Tuple.mapSecond perform
25+
, view = view
26+
, subscriptions = subscriptions
27+
, onUrlChange = BrowserChangedUrl
28+
, onUrlRequest = UserRequestsUrl
29+
}

src/Model.elm

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
module Model exposing (..)
2+
3+
import Browser.Navigation as Nav
4+
import Locale.Model as Locale
5+
import Themes.Model exposing (Theme)
6+
import Url exposing (Url)
7+
8+
9+
type alias Flags =
10+
{}
11+
12+
13+
type alias Config =
14+
{ getString : String -> String
15+
}
16+
17+
18+
type alias Model =
19+
{ url : Url
20+
, key : Nav.Key
21+
, locale : Locale.Model
22+
, theme : Theme
23+
, search : ()
24+
, user : ()
25+
}

src/Msg.elm

+7-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
module Msg exposing (Msg(..))
22

3+
import Browser exposing (UrlRequest)
4+
import Model exposing (..)
5+
import Url exposing (Url)
6+
7+
38
type Msg
4-
= Increment
5-
| Decrement
9+
= UserRequestsUrl UrlRequest
10+
| BrowserChangedUrl Url

src/Sub.elm

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
module Sub exposing (subscriptions)
2+
3+
import Model exposing (Model)
4+
import Msg exposing (Msg)
5+
6+
7+
subscriptions : Model -> Sub Msg
8+
subscriptions _ =
9+
Sub.none

src/Themes/Model.elm

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
module Themes.Model exposing (Theme)
2+
3+
import Css exposing (Style)
4+
5+
6+
type alias Theme =
7+
{ header : Style
8+
}

src/Update.elm

+24-5
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,32 @@
11
module Update exposing (update)
22

3+
import Browser
4+
import Effect exposing (Effect(..), n)
5+
import Model exposing (Model)
36
import Msg exposing (..)
7+
import Url exposing (Url)
48

59

6-
update : Msg -> number -> number
10+
update : Msg -> Model -> ( Model, Effect )
711
update msg model =
812
case msg of
9-
Increment ->
10-
model + 2
13+
UserRequestsUrl request ->
14+
case request of
15+
Browser.Internal url ->
16+
( model
17+
, Url.toString url
18+
|> NavPushUrlEffect model.key
19+
)
1120

12-
Decrement ->
13-
model - 1
21+
Browser.External url ->
22+
( model
23+
, NavLoadEffect url
24+
)
25+
26+
BrowserChangedUrl url ->
27+
updateByUrl url model
28+
29+
30+
updateByUrl : Url -> Model -> ( Model, Effect )
31+
updateByUrl _ model =
32+
n model

src/View.elm

+61-7
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,68 @@
11
module View exposing (view)
22

3-
import HelloWorld exposing (helloWorld)
4-
import Html exposing (Html, div, img)
5-
import Html.Attributes exposing (src, style)
3+
import Browser exposing (Document)
4+
import Css exposing (..)
5+
import Css.Reset
6+
import Html.Styled exposing (..)
7+
import Html.Styled.Attributes exposing (..)
8+
import Model exposing (..)
69
import Msg exposing (..)
10+
import View.Header as Header
711

812

9-
view : Int -> Html Msg
13+
view : Model -> Document Msg
1014
view model =
11-
div []
12-
[ img [ src "/logo.png", style "width" "400px" ] []
13-
, helloWorld model
15+
{ title = model.locale.getString "Iknaio Dashboard"
16+
, body =
17+
[ Css.Reset.meyerV2 |> toUnstyled
18+
, body model |> toUnstyled
19+
]
20+
}
21+
22+
23+
body : Model -> Html Msg
24+
body model =
25+
div
26+
[ css
27+
[ Css.height <| vh 100
28+
, displayFlex
29+
, flexDirection column
30+
, overflow Css.hidden
31+
]
32+
]
33+
[ Header.header
34+
{ theme = model.theme
35+
, search = model.search
36+
, user = model.user
37+
}
38+
, section
39+
[ css
40+
[ displayFlex
41+
, flexDirection row
42+
, flexGrow (num 1)
43+
]
44+
]
45+
[ nav
46+
[ css
47+
[ displayFlex
48+
, flexDirection column
49+
]
50+
]
51+
[ button
52+
[]
53+
[ text "S"
54+
]
55+
, button
56+
[]
57+
[ text "D"
58+
]
59+
]
60+
, main_
61+
[ css
62+
[ flexGrow (num 1)
63+
]
64+
]
65+
[ text "MAIN"
66+
]
67+
]
1468
]

0 commit comments

Comments
 (0)