Skip to content

Commit

Permalink
Text field and area work together now
Browse files Browse the repository at this point in the history
  • Loading branch information
greenthepear committed Aug 11, 2024
1 parent b8159e2 commit 65349ae
Showing 1 changed file with 32 additions and 2 deletions.
34 changes: 32 additions & 2 deletions src/Main.elm
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ type Msg
= Change Int String
| ChangeOriginal Int String
| ChangeOriginalFromMultiline String
| ChangeParodyFromMultiline String


syllable : Regex.Regex
Expand Down Expand Up @@ -80,6 +81,20 @@ changeOriginal dict lineNum newString =
dict


changeParody : Dict Int Line -> Int -> String -> Dict Int Line
changeParody dict lineNum newString =
Dict.update lineNum
(\maybeLine ->
case maybeLine of
Just line ->
Just { line | parody = newString }

Nothing ->
Just { number = lineNum, original = "", parody = newString }
)
dict


update : Msg -> Model -> Model
update msg model =
case msg of
Expand Down Expand Up @@ -119,6 +134,15 @@ update msg model =
|> List.foldl (\( i, line ) d -> changeOriginal d i line) model.content
}

ChangeParodyFromMultiline str ->
{ model
| content =
String.lines str
|> List.indexedMap Tuple.pair
|> List.foldl (\( i, line ) d -> changeParody d i line) model.content
, fullParody = str
}



-- VIEW
Expand Down Expand Up @@ -157,7 +181,7 @@ makeSongLine ln =
[ div lineCountStyle [ text (syllableCount ln.original |> String.fromInt) ]
, div [] [ input [ value ln.original, disabled True, style "width" "98%" ] [] ]
, div lineCountStyle [ text <| String.fromInt <| syllableCount <| ln.parody ]
, div [] [ input [ placeholder "...", onInput (Change ln.number), style "width" "98%" ] [] ]
, div [] [ input [ value ln.parody, placeholder "...", onInput (Change ln.number), style "width" "98%" ] [] ]
]


Expand Down Expand Up @@ -192,7 +216,13 @@ view model =
]
, div [ style "height" "95%" ]
[ p [] [ text "Changed:" ]
, textarea [ value model.fullParody, style "width" "100%", style "height" "50%" ] []
, textarea
[ onInput ChangeParodyFromMultiline
, value model.fullParody
, style "width" "100%"
, style "height" "50%"
]
[]
]
]
]

0 comments on commit 65349ae

Please sign in to comment.