diff --git a/src/Main.elm b/src/Main.elm
@@ -2,7 +2,7 @@ module Main exposing (main)
import View exposing (view)
import Types exposing (..)
-
+import Icon exposing (Icon, Icons)
import Html exposing (Html, img)
import Html.Attributes exposing (src)
import Browser exposing (document)
@@ -31,10 +31,10 @@ update msg model =
Update image ->
({ model | image = image }, Cmd.none)
- Load icon result ->
+ Load icon ->
let
loaded =
- Result.withDefault model (Result.map (load model icon) result)
+ Result.withDefault model (Result.map (load model) (Icon.popResult icon))
in
({ loaded | load = increment loaded.load }, Cmd.none)
@@ -53,39 +53,14 @@ update msg model =
Scroll scroll ->
({model | editorScroll = scroll}, Cmd.none)
-load : Model -> Icon -> String -> Model
-load model icon data =
+load : Model -> Icon String -> Model
+load model icon =
let
icons =
- Result.withDefault model.icons (Result.map (loadIcon model.icons icon) (parse data))
+ Result.withDefault model.icons (Result.map (Icon.load model.icons) (Icon.popResult (Icon.map parse icon)))
in
{ model | icons = icons }
--- Loads an icon into model.icons
-loadIcon : Icons -> Icon -> Html Msg -> Icons
-loadIcon icons icon svg =
- case icon of
- Logo ->
- { icons | logo = svg }
-
- DownloadIcon ->
- { icons | download = svg }
-
- UploadIcon ->
- { icons | upload = svg }
-
- Moon ->
- { icons | moon = svg }
-
- Sun ->
- { icons | sun = svg }
-
- Github ->
- { icons | github = svg }
-
- Error ->
- { icons | error = svg }
-
upload : Model -> Upload -> (Model, Cmd Msg)
upload model upl =
case upl of
@@ -117,7 +92,7 @@ init =
, load = Loading 0
}
-initIcons : Icons
+initIcons : Icons (Html Msg)
initIcons =
{ logo = img [ src "assets/logo.svg" ] []
, download = img [ src "assets/download.svg" ] []
@@ -133,34 +108,34 @@ loadContent =
Cmd.batch
[ Http.get
{ url = "assets/logo.svg"
- , expect = Http.expectString (Load Logo)
+ , expect = Http.expectString (\res -> Load (Icon.Logo res))
}
, Http.get
{ url = "assets/download.svg"
- , expect = Http.expectString (Load DownloadIcon)
+ , expect = Http.expectString (\res -> Load (Icon.Download res))
}
, Http.get
{ url = "assets/upload.svg"
- , expect = Http.expectString (Load UploadIcon)
+ , expect = Http.expectString (\res -> Load (Icon.Upload res))
}
, Http.get
{ url = "assets/moon.svg"
- , expect = Http.expectString (Load Moon)
+ , expect = Http.expectString (\res -> Load (Icon.Moon res))
}
, Http.get
{ url = "assets/sun.svg"
- , expect = Http.expectString (Load Sun)
+ , expect = Http.expectString (\res -> Load (Icon.Sun res))
}
, Http.get
{ url = "assets/github.svg"
- , expect = Http.expectString (Load Github)
+ , expect = Http.expectString (\res -> Load (Icon.Github res))
}
, Http.get
{ url = "assets/error.svg"
- , expect = Http.expectString (Load Error)
+ , expect = Http.expectString (\res -> Load (Icon.Error res))
}
, Http.get
{ url = "assets/example.svg"
- , expect = Http.expectString (\result -> Result.withDefault (Update "") (Result.map Update result))
+ , expect = Http.expectString (\res -> Result.withDefault (Update "") (Result.map Update res))
}
]
diff --git a/src/Types.elm b/src/Types.elm
@@ -1,5 +1,6 @@
module Types exposing (..)
+import Icon exposing (Icon, Icons)
import Html exposing (Html)
import File exposing (File)
import Regex exposing (Regex)
@@ -12,29 +13,17 @@ type alias Model =
, uriEncoder : Regex
, fileName : String
, editorScroll : (Int, Int)
- , icons : Icons
+ , icons : Icons (Html Msg)
, load : Load
}
-type alias Icons =
- { logo : Html Msg
- , download : Html Msg
- , upload : Html Msg
- , moon : Html Msg
- , sun : Html Msg
- , github : Html Msg
- , error : Html Msg
- }
-
type Upload = Requested | Selected File
-type Icon = Logo | DownloadIcon | UploadIcon | Moon | Sun | Github | Error
-
type Load = Loaded | Loading Int
type Msg
= Update String
- | Load Icon (Result Http.Error String)
+ | Load (Icon (Result Http.Error String))
| Validation Bool
| ToggleDarkMode
| Download