summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYorhel <git@yorhel.nl>2020-01-02 10:56:32 +0100
committerYorhel <git@yorhel.nl>2020-01-02 10:56:32 +0100
commitab6eb079e3f66218a6089bed584944911ae85f94 (patch)
tree8054daea737ba9e2487e4527e948eac3f2a85d4d
parent651649b642d0e07052625b83fbbe2fdbb6ee1f11 (diff)
ulist: Automatically unset other progress labels when changing progress label
-rw-r--r--elm/Lib/Util.elm5
-rw-r--r--elm/UList/LabelEdit.elm15
2 files changed, 16 insertions, 4 deletions
diff --git a/elm/Lib/Util.elm b/elm/Lib/Util.elm
index b86fcbad..7a120c7d 100644
--- a/elm/Lib/Util.elm
+++ b/elm/Lib/Util.elm
@@ -1,6 +1,7 @@
module Lib.Util exposing (..)
import Dict
+import Task
-- Delete an element from a List
delidx : Int -> List a -> List a
@@ -35,3 +36,7 @@ hasDuplicates l =
-- Haskell's 'lookup' - find an entry in an association list
lookup : a -> List (a,b) -> Maybe b
lookup n l = List.filter (\(a,_) -> a == n) l |> List.head |> Maybe.map Tuple.second
+
+
+selfCmd : msg -> Cmd msg
+selfCmd m = Task.perform (always m) (Task.succeed True)
diff --git a/elm/UList/LabelEdit.elm b/elm/UList/LabelEdit.elm
index 471f6eb6..6d0a4ea5 100644
--- a/elm/UList/LabelEdit.elm
+++ b/elm/UList/LabelEdit.elm
@@ -4,8 +4,10 @@ import Html exposing (..)
import Html.Attributes exposing (..)
import Html.Events exposing (..)
import Browser
+import Task
import Set exposing (Set)
import Dict exposing (Dict)
+import Lib.Util exposing (..)
import Lib.Html exposing (..)
import Lib.Api as Api
import Lib.DropDown as DD
@@ -46,7 +48,7 @@ init f =
type Msg
= Open Bool
- | Toggle Int Bool
+ | Toggle Int Bool Bool
| Saved Int Bool GApi.Response
@@ -58,12 +60,17 @@ update msg model =
case msg of
Open b -> ({ model | dd = DD.toggle model.dd b }, Cmd.none)
- Toggle l b ->
+ Toggle l cascade b ->
( { model
| tsel = if b then Set.insert l model.tsel else Set.remove l model.tsel
, state = Dict.insert l Api.Loading model.state
}
- , Api.post "/u/ulist/setlabel.json" (GLE.encode { uid = model.uid, vid = model.vid, label = l, applied = b }) (Saved l b)
+ , Cmd.batch <|
+ Api.post "/u/ulist/setlabel.json" (GLE.encode { uid = model.uid, vid = model.vid, label = l, applied = b }) (Saved l b)
+ -- Unselect other progress labels (1..4) when setting a progress label
+ :: if cascade
+ then (List.map (\i -> selfCmd (Toggle i False False)) <| List.filter (\i -> i >= 0 && l <= 4 && i /= l) <| Set.toList model.tsel)
+ else []
)
Saved l b (GApi.Success) ->
@@ -79,7 +86,7 @@ view model =
item l =
li [ ]
- [ linkRadio (Set.member l.id model.tsel) (Toggle l.id)
+ [ linkRadio (Set.member l.id model.tsel) (Toggle l.id True)
[ text l.label
, text " "
, span [ class "spinner", classList [("invisible", Dict.get l.id model.state /= Just Api.Loading)] ] []