diff options
Diffstat (limited to 'elm3/UVNList')
-rw-r--r-- | elm3/UVNList/Options.elm | 37 | ||||
-rw-r--r-- | elm3/UVNList/Status.elm | 77 | ||||
-rw-r--r-- | elm3/UVNList/Vote.elm | 103 |
3 files changed, 0 insertions, 217 deletions
diff --git a/elm3/UVNList/Options.elm b/elm3/UVNList/Options.elm deleted file mode 100644 index 2b7f0c1a..00000000 --- a/elm3/UVNList/Options.elm +++ /dev/null @@ -1,37 +0,0 @@ -module UVNList.Options exposing (main) - --- TODO: Actually implement the Edit form & remove functionality - -import Html exposing (..) -import Html.Attributes exposing (..) -import Html.Events exposing (..) -import Browser -import Lib.Html exposing (..) - - -main : Program () Model Msg -main = Browser.element - { init = always ((), Cmd.none) - , subscriptions = always Sub.none - , view = view - , update = \_ _ -> ((), Cmd.none) - } - -type alias Msg = () -type alias Model = () - --- XXX: This dropdown thing relies on the fact that the JS code to find and --- update dropdowns is run *after* all Elm objects have initialized, but this --- is pretty fragile and may break if we ever update our view. This should be --- made more reliable - either by making sure the dropdown-JS can handle DOM --- changes or by moving the handling into Elm. -view : Model -> Html Msg -view model = - div [class "dropdown"] - [ a [href "#", class "more-button more-button--light dropdown__toggle d-block"] - [ span [ class "more-button__dots" ] [] ] - , div [class "dropdown-menu"] - [ a [href "#", class "dropdown-menu__item"] [ text "Edit" ] - , a [href "#", class "dropdown-menu__item"] [ text "Remove" ] - ] - ] diff --git a/elm3/UVNList/Status.elm b/elm3/UVNList/Status.elm deleted file mode 100644 index 7a2782d2..00000000 --- a/elm3/UVNList/Status.elm +++ /dev/null @@ -1,77 +0,0 @@ -module UVNList.Status exposing (main) - -import Html exposing (..) -import Html.Attributes exposing (..) -import Html.Events exposing (..) -import Json.Encode as JE -import Browser -import Lib.Api as Api -import Lib.Html exposing (..) -import Lib.Util exposing (lookup) -import Lib.Gen as Gen - - -main : Program Flags Model Msg -main = Browser.element - { init = \f -> (init f, Cmd.none) - , subscriptions = always Sub.none - , view = view - , update = update - } - -type alias Flags = - { uid : Int - , vid : Int - , status : Int - } - -type alias Model = - { state : Api.State - , flags : Flags - } - -init : Flags -> Model -init f = - { state = Api.Normal - , flags = f - } - - -encodeForm : Model -> JE.Value -encodeForm o = JE.object - [ ("uid", JE.int o.flags.uid) - , ("vid", JE.int o.flags.vid) - , ("status", JE.int o.flags.status) ] - - -type Msg - = Input String - | Saved Api.Response - - -update : Msg -> Model -> (Model, Cmd Msg) -update msg model = - case msg of - Input s -> - let flags = model.flags - nflags = { flags | status = Maybe.withDefault 0 <| String.toInt s } - nmodel = { model | flags = nflags, state = Api.Loading } - in ( nmodel - , Api.post "/u/setvnstatus" (encodeForm nmodel) Saved ) - - Saved Gen.Success -> ({ model | state = Api.Normal }, Cmd.none) - Saved e -> ({ model | state = Api.Error e }, Cmd.none) - - -view : Model -> Html Msg -view model = - -- TODO: Display error somewhere - if model.state == Api.Loading - then div [ class "spinner spinner--md" ] [] - else div [] - [ text <| Maybe.withDefault "" <| lookup model.flags.status Gen.vnlistStatus - , inputSelect - [ class "form-control--table-edit form-control--table-edit-overlay", onInput Input ] - (String.fromInt model.flags.status) - (List.map (\(a,b) -> (String.fromInt a, b)) Gen.vnlistStatus) - ] diff --git a/elm3/UVNList/Vote.elm b/elm3/UVNList/Vote.elm deleted file mode 100644 index 2834e25e..00000000 --- a/elm3/UVNList/Vote.elm +++ /dev/null @@ -1,103 +0,0 @@ -module UVNList.Vote exposing (main) - --- XXX: There's some unobvious and unintuitive behavior when removing a vote: --- If the VN isn't also in the user's 'vnlist', then the VN entry will be --- removed from the user's list and this is only visible on a page refresh. A --- clean solution to this is to merge the 'votes' and 'vnlist' tables so that --- there's always a 'vnlist' entry that remains. This is best done after VNDBv2 --- has been decommissioned. - -import Html exposing (..) -import Html.Attributes exposing (..) -import Html.Events exposing (..) -import Json.Encode as JE -import Browser -import Regex -import Lib.Api as Api -import Lib.Gen as Gen - - -main : Program Flags Model Msg -main = Browser.element - { init = \f -> (init f, Cmd.none) - , subscriptions = always Sub.none - , view = view - , update = update - } - -type alias Flags = - { uid : Int - , vid : Int - , vote : String - } - -type alias Model = - { state : Api.State - , flags : Flags - , text : String - , valid : Bool - } - -init : Flags -> Model -init f = - { state = Api.Normal - , flags = f - , text = f.vote - , valid = True - } - - -encodeForm : Model -> JE.Value -encodeForm o = JE.object - [ ("uid", JE.int o.flags.uid) - , ("vid", JE.int o.flags.vid) - , ("vote", JE.string o.text) ] - - -type Msg - = Input String - | Save - | Saved Api.Response - - -update : Msg -> Model -> (Model, Cmd Msg) -update msg model = - case msg of - Input s -> - ( { model | text = s - , valid = Regex.contains (Maybe.withDefault Regex.never <| Regex.fromString Gen.vnvotePattern) s - } - , Cmd.none - ) - - Save -> - if model.valid && model.text /= model.flags.vote - then ( { model | state = Api.Loading } - , Api.post "/u/setvote" (encodeForm model) Saved ) - else (model, Cmd.none) - - Saved Gen.Success -> - let flags = model.flags - nflags = { flags | vote = model.text } - in ({ model | flags = nflags, state = Api.Normal }, Cmd.none) - - Saved e -> ({ model | state = Api.Error e }, Cmd.none) - - -view : Model -> Html Msg -view model = - -- TODO: Display error somewhere - -- TODO: Save when pressing enter - if model.state == Api.Loading - then - div [ class "spinner spinner--md" ] [] - else - input - [ type_ "text" - , pattern Gen.vnvotePattern - , class "form-control form-control--table-edit form-control--stealth" - , classList [("is-invalid", not model.valid)] - , value model.text - , onInput Input - , onBlur Save - ] [] |