@@ -4,6 +4,7 @@ import Browser
4
4
import Html exposing (..)
5
5
import Html.Attributes exposing (..)
6
6
import Html.Events exposing (..)
7
+ import Html.Keyed as Keyed
7
8
import Json.Decode as Json
8
9
import String
9
10
import Platform
@@ -245,48 +246,58 @@ viewEntries visibility entries =
245
246
, label
246
247
[ for "toggle-all" ]
247
248
[ text "Mark all as complete" ]
248
- , ul [ class "todo-list" ] <|
249
- Array.map viewEntry ( Array.keepIf isVisible entries)
249
+ , Keyed. ul [ class "todo-list" ] <|
250
+ Array.map viewEntry ( Array.keepIf isVisible entries )
250
251
]
251
252
252
253
253
254
254
255
-- VIEW INDIVIDUAL ENTRIES
255
256
256
257
257
- viewEntry : Entry -> Html Msg
258
+ viewEntry : Entry -> { key : String, node : Html Msg }
258
259
viewEntry todo =
259
- li
260
- [ classList [ { class = "completed", enabled = todo.completed }, { class = "editing", enabled = todo.editing } ] ]
261
- [ div
262
- [ class "view" ]
263
- [ input
264
- [ class "toggle"
265
- , type_ "checkbox"
266
- , checked todo.completed
267
- , onClick (Check { id = todo.id, checked = (not todo.completed) })
268
- ]
269
- []
270
- , label
271
- [ onDoubleClick (EditingEntry { id = todo.id, checked = True }) ]
272
- [ text todo.description ]
273
- , button
274
- [ class "destroy"
275
- , onClick (Delete todo.id)
276
- ]
277
- []
278
- ]
279
- , input
280
- [ class "edit"
281
- , value todo.description
282
- , name "title"
283
- , id ("todo-" ++ String.fromInt todo.id)
284
- , onInput (\value -> UpdateEntry { id = todo.id, value = value })
285
- , onBlur (EditingEntry { id = todo.id, checked = False })
286
- , onEnter (EditingEntry { id = todo.id, checked = False })
260
+ let
261
+ nodeId = "todo-" ++ String.fromInt todo.id
262
+ in
263
+ { key = nodeId
264
+ , node =
265
+ li
266
+ [ classList
267
+ [ { class = "completed", enabled = todo.completed }
268
+ , { class = "editing", enabled = todo.editing }
287
269
]
288
- []
289
- ]
270
+ ]
271
+ [ div
272
+ [ class "view" ]
273
+ [ input
274
+ [ class "toggle"
275
+ , type_ "checkbox"
276
+ , checked todo.completed
277
+ , onClick (Check { id = todo.id, checked = (not todo.completed) })
278
+ ]
279
+ []
280
+ , label
281
+ [ onDoubleClick (EditingEntry { id = todo.id, checked = True }) ]
282
+ [ text todo.description ]
283
+ , button
284
+ [ class "destroy"
285
+ , onClick (Delete todo.id)
286
+ ]
287
+ []
288
+ ]
289
+ , input
290
+ [ class "edit"
291
+ , value todo.description
292
+ , name "title"
293
+ , id nodeId
294
+ , onInput (\value -> UpdateEntry { id = todo.id, value = value })
295
+ , onBlur (EditingEntry { id = todo.id, checked = False })
296
+ , onEnter (EditingEntry { id = todo.id, checked = False })
297
+ ]
298
+ []
299
+ ]
300
+ }
290
301
291
302
292
303
0 commit comments