summaryrefslogtreecommitdiff
path: root/elm/UList/SaveDefault.elm
blob: 0ab2cef9c6552b20190b9fc9df9b8babb1864e69 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
module UList.SaveDefault exposing (main)

import Html exposing (..)
import Html.Attributes exposing (..)
import Html.Events exposing (..)
import Browser
import Lib.Html exposing (..)
import Lib.Util exposing (..)
import Lib.Api as Api
import Gen.Api as GApi
import Gen.UListSaveDefault as GUSD


main : Program GUSD.Recv Model Msg
main = Browser.element
  { init   = \e -> (init e, Cmd.none)
  , view   = view
  , update = update
  , subscriptions = always Sub.none
  }

type alias Model =
  { state : Api.State
  , uid   : Int
  , opts  : GUSD.SendOpts
  , field : String -- Ewwww stringly typed enum
  , hid   : Bool
  }

init : GUSD.Recv -> Model
init d =
  { state = Api.Normal
  , uid   = d.uid
  , opts  = d.opts
  , field = "vnlist"
  , hid   = True
  }

type Msg
  = SetField String
  | Submit
  | Submitted GApi.Response


update : Msg -> Model -> (Model, Cmd Msg)
update msg model =
  case msg of
    SetField s -> ({ model | field = s, hid = False }, Cmd.none)

    Submit ->
      ( { model | state = Api.Loading, hid = False }
      , GUSD.send { uid = model.uid, opts = model.opts, field = model.field } Submitted)
    Submitted GApi.Success -> ({ model | state = Api.Normal, hid = True }, Cmd.none)
    Submitted r -> ({ model | state = Api.Error r }, Cmd.none)


view : Model -> Html Msg
view model =
  form_ "" Submit (model.state == Api.Loading)
  [ div [ classList [("savedefault", True), ("hidden", model.hid)] ]
    [ b [] [ text "Save as default" ]
    , br [] []
    , text "This will change the default label selection, visible columns and table sorting options for the selected page to the currently applied settings."
    , text " The saved view will also apply to users visiting your lists."
    , br [] []
    , text "(If you just changed the label filters, make sure to hit \"Update filters\" before saving)"
    , br [] []
    , label [] [ inputRadio "savedefault_page" (model.field == "votes")  (always (SetField "votes") ), text " My Votes" ]
    , br [] []
    , label [] [ inputRadio "savedefault_page" (model.field == "vnlist") (always (SetField "vnlist")), text " My Visual Novel List" ]
    , br [] []
    , label [] [ inputRadio "savedefault_page" (model.field == "wish")   (always (SetField "wish")  ), text " My Wishlist" ]
    , br [] []
    , submitButton "Save" model.state True
    ]
  ]