aboutsummaryrefslogtreecommitdiff
path: root/src/Main.elm
diff options
context:
space:
mode:
Diffstat (limited to 'src/Main.elm')
-rw-r--r--src/Main.elm59
1 files changed, 30 insertions, 29 deletions
diff --git a/src/Main.elm b/src/Main.elm
index 4ca4934..2b1cc67 100644
--- a/src/Main.elm
+++ b/src/Main.elm
@@ -4,14 +4,14 @@ import Array exposing (..)
4import Base exposing (..) 4import Base exposing (..)
5import Browser 5import Browser
6import Css 6import Css
7import Css.Global exposing (everything, global, selector) 7import Css.Global exposing (body, everything, global, selector)
8import Data exposing (..) 8import Data exposing (..)
9import Html 9import Html
10import Html.Styled exposing (..) 10import Html.Styled exposing (..)
11import Html.Styled.Attributes exposing (..) 11import Html.Styled.Attributes exposing (..)
12import Html.Styled.Events exposing (onClick, onInput) 12import Html.Styled.Events exposing (onClick, onInput)
13import Random 13import Random
14import Styles exposing (styledButton, styledInput, styledTextBox) 14import Styles exposing (styledButton, styledInput, styledTextBox, wordStyle)
15import Task 15import Task
16import Time 16import Time
17import Utils exposing (isJust, isNothing) 17import Utils exposing (isJust, isNothing)
@@ -44,7 +44,7 @@ generateWords config =
44 44
45defaultModel : Model 45defaultModel : Model
46defaultModel = 46defaultModel =
47 Model Nothing Nothing Array.empty Nothing defaultConfig 0 "" 47 Model Nothing Nothing Array.empty Nothing defaultConfig 0 "" False
48 48
49 49
50init : () -> ( Model, Cmd Msg ) 50init : () -> ( Model, Cmd Msg )
@@ -143,8 +143,11 @@ update msg model =
143 143
144 else 144 else
145 Cmd.none 145 Cmd.none
146
147 inpStat =
148 String.startsWith s (currentContents model)
146 in 149 in
147 ( { model | inputBox = s } 150 ( { model | inputBox = s, inputCorrect = inpStat }
148 , cmd 151 , cmd
149 ) 152 )
150 153
@@ -183,28 +186,13 @@ update msg model =
183 ) 186 )
184 187
185 188
186wordStyle : WordStatus -> Attribute msg
187wordStyle w =
188 case w of
189 Correct ->
190 style "color" "green"
191
192 Wrong ->
193 style "color" "red"
194
195 Todo ->
196 style "color" "black"
197
198 CurrentWord ->
199 style "color" "magenta"
200
201
202toPara : Array Word -> Int -> String -> Html Msg 189toPara : Array Word -> Int -> String -> Html Msg
203toPara words current content = 190toPara words current content =
204 words 191 words
205 |> Array.map (\w -> span [ wordStyle w.status ] [ text (w.content ++ " ") ]) 192 |> Array.map (\w -> span [ css [ wordStyle w.status ] ] [ text w.content ])
206 |> Array.set current (span [ wordStyle CurrentWord ] [ text (content ++ " ") ]) 193 |> Array.set current (span [ css [ wordStyle CurrentWord ] ] [ text content ])
207 |> Array.toList 194 |> Array.toList
195 |> List.intersperse (span [] [ text " " ])
208 |> styledTextBox [] 196 |> styledTextBox []
209 197
210 198
@@ -217,20 +205,33 @@ currentContents model =
217 205
218view : Model -> Html Msg 206view : Model -> Html Msg
219view model = 207view model =
220 div [] 208 div
221 [ div [] 209 [ style "width" "95%"
210 , style "max-width" "650px"
211 , style "margin" "auto"
212 , style "padding-top" "15%"
213 ]
214 [ div
215 [ style "width" "100%"
216 ]
222 [ viewWordLengthOptions 217 [ viewWordLengthOptions
223 , viewStats model 218 , div
219 [ style "float" "right" ]
220 [ styledButton [ onClick Redo ] [ text "redo" ] ]
224 ] 221 ]
225 , div [] 222 , div []
226 [ toPara model.words model.currentWord (currentContents model) 223 [ toPara model.words model.currentWord (currentContents model)
227 , div [] 224 , div []
228 [ styledInput [ onInput handleInputChanged, value model.inputBox ] [] 225 [ text "> "
229 , styledButton [ onClick Redo ] [ text "redo" ] 226 , styledInput model.inputCorrect [ onInput handleInputChanged, value model.inputBox ] []
230 ] 227 ]
231 ] 228 ]
232 , global [ selector "li:not(:last-child)::after" [ Css.property "content" "' / '" ] ] 229 , div [] [ viewStats model ]
233 , global [ everything [ Css.fontFamily Css.monospace ] ] 230
231 -- , global [ selector "li:not(:last-child)::after" [ Css.property "content" "' ยท '" ] ]
232 , global [ everything [ Css.fontFamily Css.monospace, Css.fontSize (Css.px 18) ] ]
233
234 -- , global [ body [ Css.backgroundColor (Css.hex "#000"), Css.color (Css.hex "#fff") ] ]
234 ] 235 ]
235 236
236 237