diff options
author | Yorhel <git@yorhel.nl> | 2019-11-05 11:13:48 +0100 |
---|---|---|
committer | Yorhel <git@yorhel.nl> | 2019-11-10 12:44:55 +0100 |
commit | 1ae8c1e325bdf3d37400552aad21c7574f0b1f24 (patch) | |
tree | 2b39747cdbd14d8a5a21749a66f696999606cb91 /elm | |
parent | 24f03ae521a6b35def38788e0446201aa6095314 (diff) |
ulist: Implement notes editing + small code reorg
Diffstat (limited to 'elm')
-rw-r--r-- | elm/UList/DateEdit.elm | 2 | ||||
-rw-r--r-- | elm/UList/LabelEdit.elm | 2 | ||||
-rw-r--r-- | elm/UList/ManageLabels.elm | 2 | ||||
-rw-r--r-- | elm/UList/Opt.elm | 50 | ||||
-rw-r--r-- | elm/UList/Opt.js | 5 | ||||
-rw-r--r-- | elm/UList/VoteEdit.elm | 2 |
6 files changed, 48 insertions, 15 deletions
diff --git a/elm/UList/DateEdit.elm b/elm/UList/DateEdit.elm index dc6b18e8..fc5da234 100644 --- a/elm/UList/DateEdit.elm +++ b/elm/UList/DateEdit.elm @@ -8,7 +8,7 @@ import Process import Browser import Lib.Api as Api import Gen.Api as GApi -import Gen.DateEdit as GDE +import Gen.UListDateEdit as GDE main : Program GDE.Send Model Msg diff --git a/elm/UList/LabelEdit.elm b/elm/UList/LabelEdit.elm index ce65e414..28e4b154 100644 --- a/elm/UList/LabelEdit.elm +++ b/elm/UList/LabelEdit.elm @@ -13,7 +13,7 @@ import Dict exposing (Dict) import Lib.Html exposing (..) import Lib.Api as Api import Gen.Api as GApi -import Gen.LabelEdit as GLE +import Gen.UListLabelEdit as GLE main : Program GLE.Recv Model Msg diff --git a/elm/UList/ManageLabels.elm b/elm/UList/ManageLabels.elm index 755c4e08..4cb82777 100644 --- a/elm/UList/ManageLabels.elm +++ b/elm/UList/ManageLabels.elm @@ -10,7 +10,7 @@ import Lib.Html exposing (..) import Lib.Util exposing (..) import Lib.Api as Api import Gen.Api as GApi -import Gen.ManageLabels as GML +import Gen.UListManageLabels as GML main : Program GML.Send Model Msg diff --git a/elm/UList/Opt.elm b/elm/UList/Opt.elm index edbdf187..916e723f 100644 --- a/elm/UList/Opt.elm +++ b/elm/UList/Opt.elm @@ -12,9 +12,10 @@ import Lib.Api as Api import Gen.Types as T import Gen.Api as GApi import Gen.UListVNOpt as GVO +import Gen.UListVNNotes as GVN import Gen.UListDel as GDE -main : Program GVO.Send Model Msg +main : Program GVO.Recv Model Msg main = Browser.element { init = \f -> (init f, Cmd.none) , subscriptions = always Sub.none @@ -23,24 +24,34 @@ main = Browser.element } port ulistVNDeleted : Bool -> Cmd msg +port ulistNotesChanged : String -> Cmd msg type alias Model = - { flags : GVO.Send - , del : Bool - , delState : Api.State + { flags : GVO.Recv + , del : Bool + , delState : Api.State + , notes : String + , notesRev : Int + , notesState : Api.State } -init : GVO.Send -> Model +init : GVO.Recv -> Model init f = - { flags = f - , del = False - , delState = Api.Normal + { flags = f + , del = False + , delState = Api.Normal + , notes = f.notes + , notesRev = 0 + , notesState = Api.Normal } type Msg = Del Bool | Delete | Deleted GApi.Response + | Notes String + | NotesSave Int + | NotesSaved Int GApi.Response update : Msg -> Model -> (Model, Cmd Msg) @@ -51,6 +62,19 @@ update msg model = Deleted GApi.Success -> (model, ulistVNDeleted True) Deleted e -> ({ model | delState = Api.Error e }, Cmd.none) + Notes s -> ({ model | notes = s, notesRev = model.notesRev + 1 }, Task.perform (\_ -> NotesSave (model.notesRev+1)) <| Process.sleep 1000) + NotesSave rev -> + if rev /= model.notesRev || model.notes == model.flags.notes + then (model, Cmd.none) + else ({ model | notesState = Api.Loading }, Api.post "/u/ulist/setnote.json" (GVN.encode { uid = model.flags.uid, vid = model.flags.vid, notes = model.notes }) (NotesSaved rev)) + NotesSaved rev GApi.Success -> + let f = model.flags + nf = { f | notes = model.notes } + in if model.notesRev /= rev + then (model, Cmd.none) + else ({model | flags = nf, notesState = Api.Normal }, ulistNotesChanged model.notes) + NotesSaved _ e -> ({ model | notesState = Api.Error e }, Cmd.none) + view : Model -> Html Msg view model = @@ -58,10 +82,14 @@ view model = opt = [ tr [] [ td [ colspan 5 ] - [ textarea ([ placeholder "Notes", rows 2, cols 100 ] ++ GVO.valNotes) [ text model.flags.notes ] + [ textarea ([ placeholder "Notes", rows 2, cols 80, onInput Notes, onBlur (NotesSave model.notesRev) ] ++ GVN.valNotes) [ text model.notes ] , div [ ] - [ div [ class "spinner invisible" ] [] - , br_ 2 + [ div [ class "spinner", classList [("invisible", model.notesState /= Api.Loading)] ] [] + , br [] [] + , case model.notesState of + Api.Error e -> b [ class "standout" ] [ text <| Api.showResponse e ] + _ -> text "" + , br [] [] , a [ href "#", onClickD (Del True) ] [ text "Remove VN" ] ] ] diff --git a/elm/UList/Opt.js b/elm/UList/Opt.js index 6a4f126f..41bd1ce2 100644 --- a/elm/UList/Opt.js +++ b/elm/UList/Opt.js @@ -13,4 +13,9 @@ Elm.UList.Opt.init = function(opt) { for(var i=0; i<rows.length; i++) rows[i].classList.toggle('odd', Math.floor(i/2) % 2 == 0); }); + + app.ports.ulistNotesChanged.subscribe(function(n) { + document.getElementById('ulist_notes_'+opt.flags.vid).innerText = n; + document.getElementById('ulist_noteflag_'+opt.flags.vid).classList.toggle('blurred', n.length == 0); + }); }; diff --git a/elm/UList/VoteEdit.elm b/elm/UList/VoteEdit.elm index 8007d648..380cb6c8 100644 --- a/elm/UList/VoteEdit.elm +++ b/elm/UList/VoteEdit.elm @@ -10,7 +10,7 @@ import Lib.Html exposing (..) import Lib.Api as Api import Lib.Ffi as Ffi import Gen.Api as GApi -import Gen.VoteEdit as GVE +import Gen.UListVoteEdit as GVE main : Program GVE.Send Model Msg |