Allow deleting tiles by deleting their contents
This commit is contained in:
parent
cab50f5295
commit
5bf639cd2d
18
src/Main.elm
18
src/Main.elm
|
@ -10,10 +10,10 @@ import Browser.Navigation exposing (Key)
|
|||
import Browser.Events exposing (onResize)
|
||||
import Html exposing (button, div, h3, input, Html, section, text)
|
||||
import Html.Attributes exposing (class, style, value)
|
||||
import Html.Events exposing (onClick, onInput)
|
||||
import Html.Events exposing (onBlur, onClick, onInput)
|
||||
import Json.Decode as D
|
||||
import List exposing (map, singleton)
|
||||
import String exposing (fromInt)
|
||||
import String exposing (fromInt, isEmpty)
|
||||
import Svg exposing (Svg, svg)
|
||||
import Svg.Attributes exposing (height, viewBox, width)
|
||||
import Svg.Events exposing (on)
|
||||
|
@ -35,6 +35,7 @@ type Msg
|
|||
| WindowSize Int Int
|
||||
| SetTileText Int Int String
|
||||
| AddTile Int
|
||||
| TileDeselected Int
|
||||
|
||||
type alias Model =
|
||||
{ windowW: Int
|
||||
|
@ -123,6 +124,7 @@ viewTile columnIndex tileIndex tile =
|
|||
[ input
|
||||
[ value tile.text
|
||||
, onInput (SetTileText columnIndex tileIndex)
|
||||
, onBlur (TileDeselected columnIndex)
|
||||
]
|
||||
[]
|
||||
, svg
|
||||
|
@ -151,6 +153,13 @@ addTileToColumn : Column -> Column
|
|||
addTileToColumn column =
|
||||
{ column | tiles = Array.push blankTile column.tiles }
|
||||
|
||||
isTileEmpty : Tile -> Bool
|
||||
isTileEmpty = .text >> isEmpty
|
||||
|
||||
pruneTiles : Column -> Column
|
||||
pruneTiles column =
|
||||
{ column | tiles = Array.filter (not << isTileEmpty) column.tiles }
|
||||
|
||||
updateTileText : String -> Tile -> Tile
|
||||
updateTileText text tile =
|
||||
{ tile | text = text }
|
||||
|
@ -193,4 +202,9 @@ update msg model = case Debug.log "UPDATE" (msg, model) of
|
|||
modColumnInPage columnIndex
|
||||
addTileToColumn
|
||||
model
|
||||
|> withoutCmd
|
||||
( TileDeselected columnIndex, _ ) ->
|
||||
modColumnInPage columnIndex
|
||||
pruneTiles
|
||||
model
|
||||
|> withoutCmd
|
Loading…
Reference in New Issue