ui: clear input fields on success
This commit is contained in:
parent
a8b2bb72a4
commit
0adaeb57f3
@ -6294,6 +6294,9 @@ var $author$project$Main$addLink = function (model) {
|
||||
url: '/links'
|
||||
});
|
||||
};
|
||||
var $author$project$Main$AddedWatch = function (a) {
|
||||
return {$: 'AddedWatch', a: a};
|
||||
};
|
||||
var $author$project$Main$addWatch = function (model) {
|
||||
var body = $elm$http$Http$jsonBody(
|
||||
$elm$json$Json$Encode$object(
|
||||
@ -6309,7 +6312,7 @@ var $author$project$Main$addWatch = function (model) {
|
||||
return $elm$http$Http$post(
|
||||
{
|
||||
body: body,
|
||||
expect: $elm$http$Http$expectWhatever($author$project$Main$AddedLink),
|
||||
expect: $elm$http$Http$expectWhatever($author$project$Main$AddedWatch),
|
||||
url: '/watches'
|
||||
});
|
||||
};
|
||||
@ -6375,6 +6378,22 @@ var $author$project$Main$update = F2(
|
||||
model,
|
||||
{newlink: newlink}),
|
||||
$elm$core$Platform$Cmd$none);
|
||||
case 'AddedWatch':
|
||||
if (msg.a.$ === 'Err') {
|
||||
return _Utils_Tuple2(
|
||||
_Utils_update(
|
||||
model,
|
||||
{
|
||||
status: $author$project$Main$Errored('Server error adding a watch!')
|
||||
}),
|
||||
$elm$core$Platform$Cmd$none);
|
||||
} else {
|
||||
return _Utils_Tuple2(
|
||||
_Utils_update(
|
||||
model,
|
||||
{newwatch: $author$project$Main$initialModel.newwatch}),
|
||||
$author$project$Main$getWatches);
|
||||
}
|
||||
case 'AddedLink':
|
||||
if (msg.a.$ === 'Err') {
|
||||
return _Utils_Tuple2(
|
||||
@ -6695,8 +6714,9 @@ var $elm$html$Html$Events$onInput = function (tagger) {
|
||||
};
|
||||
var $elm$html$Html$Attributes$placeholder = $elm$html$Html$Attributes$stringProperty('placeholder');
|
||||
var $elm$html$Html$Attributes$type_ = $elm$html$Html$Attributes$stringProperty('type');
|
||||
var $author$project$Main$labeledTextBox = F4(
|
||||
function (labelStr, placeStr, inputName, inputHandler) {
|
||||
var $elm$html$Html$Attributes$value = $elm$html$Html$Attributes$stringProperty('value');
|
||||
var $author$project$Main$labeledInput = F5(
|
||||
function (labelStr, placeStr, inputName, inputValue, inputHandler) {
|
||||
return A2(
|
||||
$elm$html$Html$label,
|
||||
_List_Nil,
|
||||
@ -6710,7 +6730,8 @@ var $author$project$Main$labeledTextBox = F4(
|
||||
$elm$html$Html$Attributes$type_('text'),
|
||||
$elm$html$Html$Attributes$name(inputName),
|
||||
$elm$html$Html$Events$onInput(inputHandler),
|
||||
$elm$html$Html$Attributes$placeholder(placeStr)
|
||||
$elm$html$Html$Attributes$placeholder(placeStr),
|
||||
$elm$html$Html$Attributes$value(inputValue)
|
||||
]),
|
||||
_List_Nil)
|
||||
]));
|
||||
@ -6736,7 +6757,8 @@ var $elm$html$Html$Events$onCheck = function (tagger) {
|
||||
'change',
|
||||
A2($elm$json$Json$Decode$map, tagger, $elm$html$Html$Events$targetChecked));
|
||||
};
|
||||
var $author$project$Main$linkForm = function (newlink) {
|
||||
var $author$project$Main$linkForm = F2(
|
||||
function (model, newlink) {
|
||||
return A2(
|
||||
$elm$html$Html$div,
|
||||
_List_Nil,
|
||||
@ -6758,33 +6780,36 @@ var $author$project$Main$linkForm = function (newlink) {
|
||||
_List_Nil,
|
||||
_List_fromArray(
|
||||
[
|
||||
A4(
|
||||
$author$project$Main$labeledTextBox,
|
||||
A5(
|
||||
$author$project$Main$labeledInput,
|
||||
'Name: ',
|
||||
'Potato',
|
||||
'name',
|
||||
model.newlink.name,
|
||||
function (v) {
|
||||
return $author$project$Main$GotNewLink(
|
||||
_Utils_update(
|
||||
newlink,
|
||||
{name: v}));
|
||||
}),
|
||||
A4(
|
||||
$author$project$Main$labeledTextBox,
|
||||
A5(
|
||||
$author$project$Main$labeledInput,
|
||||
'URL: ',
|
||||
'https://....',
|
||||
'url',
|
||||
model.newlink.url,
|
||||
function (v) {
|
||||
return $author$project$Main$GotNewLink(
|
||||
_Utils_update(
|
||||
newlink,
|
||||
{url: v}));
|
||||
}),
|
||||
A4(
|
||||
$author$project$Main$labeledTextBox,
|
||||
A5(
|
||||
$author$project$Main$labeledInput,
|
||||
'Icon: ',
|
||||
'https://....',
|
||||
'logo_url',
|
||||
model.newlink.logo_url,
|
||||
function (v) {
|
||||
return $author$project$Main$GotNewLink(
|
||||
_Utils_update(
|
||||
@ -6817,7 +6842,7 @@ var $author$project$Main$linkForm = function (newlink) {
|
||||
]))
|
||||
])))
|
||||
]));
|
||||
};
|
||||
});
|
||||
var $elm$html$Html$Events$onClick = function (msg) {
|
||||
return A2(
|
||||
$elm$html$Html$Events$on,
|
||||
@ -6907,7 +6932,7 @@ var $author$project$Main$viewLinks = function (model) {
|
||||
[
|
||||
A2(
|
||||
$author$project$Main$bar,
|
||||
$author$project$Main$linkForm(model.newlink),
|
||||
A2($author$project$Main$linkForm, model, model.newlink),
|
||||
A2(
|
||||
$elm$html$Html$a,
|
||||
_List_fromArray(
|
||||
@ -7017,7 +7042,8 @@ var $author$project$Main$GotNewWatch = function (a) {
|
||||
return {$: 'GotNewWatch', a: a};
|
||||
};
|
||||
var $author$project$Main$SubmitWatch = {$: 'SubmitWatch'};
|
||||
var $author$project$Main$watchForm = function (newwatch) {
|
||||
var $author$project$Main$watchForm = F2(
|
||||
function (model, newwatch) {
|
||||
return A2(
|
||||
$elm$html$Html$div,
|
||||
_List_Nil,
|
||||
@ -7031,22 +7057,24 @@ var $author$project$Main$watchForm = function (newwatch) {
|
||||
_List_Nil,
|
||||
_List_fromArray(
|
||||
[
|
||||
A4(
|
||||
$author$project$Main$labeledTextBox,
|
||||
A5(
|
||||
$author$project$Main$labeledInput,
|
||||
'Item: ',
|
||||
'some string...',
|
||||
'name',
|
||||
model.newwatch.name,
|
||||
function (v) {
|
||||
return $author$project$Main$GotNewWatch(
|
||||
_Utils_update(
|
||||
newwatch,
|
||||
{name: v}));
|
||||
}),
|
||||
A4(
|
||||
$author$project$Main$labeledTextBox,
|
||||
A5(
|
||||
$author$project$Main$labeledInput,
|
||||
'Repository: ',
|
||||
'NixOS/nixpkgs',
|
||||
'repo',
|
||||
model.newwatch.repo,
|
||||
function (v) {
|
||||
return $author$project$Main$GotNewWatch(
|
||||
_Utils_update(
|
||||
@ -7055,7 +7083,7 @@ var $author$project$Main$watchForm = function (newwatch) {
|
||||
})
|
||||
])))
|
||||
]));
|
||||
};
|
||||
});
|
||||
var $author$project$Main$viewWatches = function (model) {
|
||||
return A2(
|
||||
$elm$html$Html$div,
|
||||
@ -7064,7 +7092,7 @@ var $author$project$Main$viewWatches = function (model) {
|
||||
[
|
||||
A2(
|
||||
$author$project$Main$bar,
|
||||
$author$project$Main$watchForm(model.newwatch),
|
||||
A2($author$project$Main$watchForm, model, model.newwatch),
|
||||
A2(
|
||||
$elm$html$Html$a,
|
||||
_List_fromArray(
|
||||
|
38
src/Main.elm
38
src/Main.elm
@ -3,7 +3,7 @@ module Main exposing (..)
|
||||
import Browser
|
||||
import Data
|
||||
import Html exposing (..)
|
||||
import Html.Attributes exposing (checked, class, classList, href, name, placeholder, src, type_)
|
||||
import Html.Attributes exposing (checked, class, classList, href, name, placeholder, src, type_, value)
|
||||
import Html.Events exposing (..)
|
||||
import Http
|
||||
import Json.Decode as Decode
|
||||
@ -32,6 +32,7 @@ main =
|
||||
|
||||
type Msg
|
||||
= AddedLink (Result Http.Error ())
|
||||
| AddedWatch (Result Http.Error ())
|
||||
| DeletedLink (Result Http.Error ())
|
||||
| DeleteLink Int
|
||||
| GotLinks (Result Http.Error (List Data.Link))
|
||||
@ -151,7 +152,7 @@ addWatch model =
|
||||
Http.post
|
||||
{ url = "/watches"
|
||||
, body = body
|
||||
, expect = Http.expectWhatever AddedLink
|
||||
, expect = Http.expectWhatever AddedWatch
|
||||
}
|
||||
|
||||
|
||||
@ -180,6 +181,12 @@ update msg model =
|
||||
GotNewLink newlink ->
|
||||
( { model | newlink = newlink }, Cmd.none )
|
||||
|
||||
AddedWatch (Err _) ->
|
||||
( { model | status = Errored "Server error adding a watch!" }, Cmd.none )
|
||||
|
||||
AddedWatch (Ok _) ->
|
||||
( { model | newwatch = initialModel.newwatch }, getWatches )
|
||||
|
||||
AddedLink (Err _) ->
|
||||
( { model | status = Errored "Server error adding a link!" }, Cmd.none )
|
||||
|
||||
@ -353,29 +360,29 @@ repoInfoDecoder =
|
||||
(field "nameWithOwner" string)
|
||||
|
||||
|
||||
watchForm : NewWatch -> Html Msg
|
||||
watchForm newwatch =
|
||||
watchForm : Model -> NewWatch -> Html Msg
|
||||
watchForm model newwatch =
|
||||
div []
|
||||
[ createForm SubmitWatch
|
||||
(div
|
||||
[]
|
||||
[ labeledTextBox "Item: " "some string..." "name" (\v -> GotNewWatch { newwatch | name = v })
|
||||
, labeledTextBox "Repository: " "NixOS/nixpkgs" "repo" (\v -> GotNewWatch { newwatch | repo = v })
|
||||
[ labeledInput "Item: " "some string..." "name" model.newwatch.name (\v -> GotNewWatch { newwatch | name = v })
|
||||
, labeledInput "Repository: " "NixOS/nixpkgs" "repo" model.newwatch.repo (\v -> GotNewWatch { newwatch | repo = v })
|
||||
]
|
||||
)
|
||||
]
|
||||
|
||||
|
||||
linkForm : NewLink -> Html Msg
|
||||
linkForm newlink =
|
||||
linkForm : Model -> NewLink -> Html Msg
|
||||
linkForm model newlink =
|
||||
div []
|
||||
[ createForm SubmitLink
|
||||
(div [ class "form-content" ]
|
||||
[ div
|
||||
[]
|
||||
[ labeledTextBox "Name: " "Potato" "name" (\v -> GotNewLink { newlink | name = v })
|
||||
, labeledTextBox "URL: " "https://...." "url" (\v -> GotNewLink { newlink | url = v })
|
||||
, labeledTextBox "Icon: " "https://...." "logo_url" (\v -> GotNewLink { newlink | logo_url = v })
|
||||
[ labeledInput "Name: " "Potato" "name" model.newlink.name (\v -> GotNewLink { newlink | name = v })
|
||||
, labeledInput "URL: " "https://...." "url" model.newlink.url (\v -> GotNewLink { newlink | url = v })
|
||||
, labeledInput "Icon: " "https://...." "logo_url" model.newlink.logo_url (\v -> GotNewLink { newlink | logo_url = v })
|
||||
, label []
|
||||
[ text "Shared: "
|
||||
, input
|
||||
@ -392,8 +399,8 @@ linkForm newlink =
|
||||
]
|
||||
|
||||
|
||||
labeledTextBox : String -> String -> String -> (String -> msg) -> Html msg
|
||||
labeledTextBox labelStr placeStr inputName inputHandler =
|
||||
labeledInput : String -> String -> String -> String -> (String -> msg) -> Html msg
|
||||
labeledInput labelStr placeStr inputName inputValue inputHandler =
|
||||
label []
|
||||
[ text labelStr
|
||||
, input
|
||||
@ -401,6 +408,7 @@ labeledTextBox labelStr placeStr inputName inputHandler =
|
||||
, name inputName
|
||||
, onInput inputHandler
|
||||
, placeholder placeStr
|
||||
, value inputValue
|
||||
]
|
||||
[]
|
||||
]
|
||||
@ -435,7 +443,7 @@ bar left right =
|
||||
viewLinks : Model -> Html Msg
|
||||
viewLinks model =
|
||||
div []
|
||||
[ bar (linkForm model.newlink) (a [ onClick ReloadLinks ] [ text " ⟳" ])
|
||||
[ bar (linkForm model model.newlink) (a [ onClick ReloadLinks ] [ text " ⟳" ])
|
||||
, case model.links of
|
||||
_ :: _ ->
|
||||
div
|
||||
@ -450,7 +458,7 @@ viewLinks model =
|
||||
viewWatches : Model -> Html Msg
|
||||
viewWatches model =
|
||||
div []
|
||||
[ bar (watchForm model.newwatch) (a [ onClick ReloadWatches ] [ text " ⟳" ])
|
||||
[ bar (watchForm model model.newwatch) (a [ onClick ReloadWatches ] [ text " ⟳" ])
|
||||
, case model.watches of
|
||||
_ :: _ ->
|
||||
ul [] (List.map viewWatch model.watches)
|
||||
|
Loading…
Reference in New Issue
Block a user