summaryrefslogtreecommitdiff
path: root/elm/Report.elm
blob: f9fb1cd3683c4903cf609259fe1dbe13f6e058a5 (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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
module Report exposing (main)

import Html exposing (..)
import Html.Attributes exposing (..)
import Html.Events exposing (..)
import Browser
import Browser.Navigation exposing (load)
import Lib.Html exposing (..)
import Lib.Api as Api
import Lib.Ffi as Ffi
import Gen.Api as GApi
import Gen.Report as GR


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

type alias Model = (Api.State,GR.Send)

type Msg
  = Reason String
  | Message String
  | Submit
  | Submitted GApi.Response


type alias ReasonLabel =
  { label  : String
  , vis    : String -> Bool -- Given an objectid, returns whether it should be listed
  , submit : Bool -- Whether it allows submission of the form
  , msg    : String -> List (Html Msg) -- Message to display
  }


vis _ = True
nomsg _ = []
objtype s o = String.any (\c -> String.startsWith (String.fromChar c) o) s
editable = objtype "vrpcs"
initial = { label = "-- Select --" , vis = vis, submit = False , msg = nomsg }

reasons : List ReasonLabel
reasons =
  [ initial
  , { label  = "Spam"
    , vis    = vis
    , submit = True
    , msg    = nomsg
    }
  , { label  = "Links to piracy or illegal content"
    , vis    = vis
    , submit = True
    , msg    = nomsg
    }
  , { label  = "Off-topic"
    , vis    = objtype "tw"
    , submit = True
    , msg    = nomsg
    }
  , { label  = "Unwelcome behavior"
    , vis    = objtype "tw"
    , submit = True
    , msg    = nomsg
    }
  , { label  = "Unmarked spoilers"
    , vis    = vis
    , submit = True
    , msg    = \o -> if not (editable o) then [] else
        [ text "VNDB is an open wiki, it is often easier if you removed the spoilers yourself by "
        , a [ href ("/" ++ o ++ "/edit") ] [ text " editing the entry" ]
        , text ". You likely know more about this entry than our moderators, after all. "
        , br [] []
        , text "If you're not sure whether something is a spoiler or if you need help with editing, you can also report this issue on the "
        , a [ href "/t/db" ] [ text "discussion board" ]
        , text " so that others may be able to help you."
        ]
    }
  , { label  = "Unmarked or improperly flagged NSFW image"
    , vis    = objtype "vc"
    , submit = True
    , msg    = nomsg
    }
  , { label  = "Incorrect information"
    , vis    = editable
    , submit = False
    , msg    = \o ->
        [ text "VNDB is an open wiki, you can correct the information in this database yourself by "
        , a [ href ("/" ++ o ++ "/edit") ] [ text " editing the entry" ]
        , text ". You likely know more about this entry than our moderators, after all. "
        , br [] []
        , text "If you need help with editing, you can also report this issue on the "
        , a [ href "/t/db" ] [ text "discussion board" ]
        , text " so that others may be able to help you."
        ]
    }
  , { label  = "Missing information"
    , vis    = editable
    , submit = False
    , msg    = \o ->
        [ text "VNDB is an open wiki, you can add any missing information to this database yourself. "
        , text "You likely know more about this entry than our moderators, after all. "
        , br [] []
        , text "If you need help with contributing information, feel free to ask around on the "
        , a [ href "/t/db" ] [ text "discussion board" ]
        , text "."
        ]
    }
  , { label  = "Not a visual novel"
    , vis    = objtype "v"
    , submit = False
    , msg    = \_ ->
        [ text "If you suspect that this entry does not adhere to our "
        , a [ href "/d2#1" ] [ text "inclusion criteria" ]
        , text ", please report it in "
        , a [ href "/t2108" ] [ text "this thread" ]
        , text ", so that other users have a chance to provide feedback before a moderator makes their final decision."
        ]
    }
  , { label  = "Does not belong here"
    , vis    = \o -> editable o && not (objtype "v" o)
    , submit = True
    , msg    = nomsg
    }
  , { label  = "Duplicate entry"
    , vis    = editable
    , submit = True
    , msg    = \_ -> [ text "Please include a link to the entry that this is a duplicate of." ]
    }
  , { label  = "Other"
    , vis    = vis
    , submit = True
    , msg    = \o ->
        if editable o
        then [ text "Keep in mind that VNDB is an open wiki, you can edit most of the information in this database."
             , br [] []
             , text "Reports for issues that do not require a moderator to get involved will most likely be ignored."
             , br [] []
             , text "If you need help with contributing to the database, feel free to ask around on the "
             , a [ href "/t/db" ] [ text "discussion board" ]
             , text "."
             ]
        else []
    }
  ]


update : Msg -> Model -> (Model, Cmd Msg)
update msg (state,model) =
  case msg of
    Reason s    -> ((state, { model | reason  = s }), Cmd.none)
    Message s   -> ((state, { model | message = s }), Cmd.none)
    Submit      -> ((Api.Loading, model), GR.send model Submitted)
    Submitted r -> ((Api.Error r, model), Cmd.none)


view : Model -> Html Msg
view (state,model) =
  let
    lst = List.filter (\l -> l.vis model.object) reasons
    cur = List.filter (\l -> l.label == model.reason) lst |> List.head |> Maybe.withDefault initial
  in
  form_ "" Submit (state == Api.Loading)
  [ div [ class "mainbox" ]
    [ h1 [] [ text "Submit report" ]
    , if state == Api.Error GApi.Success
      then p [] [ text "Your report has been submitted, a moderator will look at it as soon as possible." ]
      else table [ class "formtable" ] <|
        [ formField "Subject" [ span [ Ffi.innerHtml model.title ] [] ]
        , formField ""
          [ text "Your report will be forwarded to a moderator."
          , br [] []
          , text "Keep in mind that not every report will be acted upon, we may decide that the problem you reported is still within acceptable limits."
          , br [] []
          , if model.loggedin
            then text "We generally do not provide feedback on reports, but a moderator may decide to contact you for clarification."
            else text "We generally do not provide feedback on reports, but you may leave your email address in the message if you wish to be available for clarification."
          ]
        , formField "reason::Reason" [ inputSelect "reason" model.reason Reason [style "width" "300px"] <| List.map (\l->(l.label,l.label)) lst ]
        , formField "" (cur.msg model.object)
        ] ++ if not cur.submit then [] else
        [ formField "message::Message" [ inputTextArea "message" model.message Message [] ]
        , formField "" [ submitButton "Submit" state True ]
        ]
    ]
  ]