ui: clear input fields on success

This commit is contained in:
Aaron Bieber 2023-06-06 13:13:16 -06:00
parent a8b2bb72a4
commit 0adaeb57f3
No known key found for this signature in database
2 changed files with 178 additions and 142 deletions

View File

@ -6294,6 +6294,9 @@ var $author$project$Main$addLink = function (model) {
url: '/links' url: '/links'
}); });
}; };
var $author$project$Main$AddedWatch = function (a) {
return {$: 'AddedWatch', a: a};
};
var $author$project$Main$addWatch = function (model) { var $author$project$Main$addWatch = function (model) {
var body = $elm$http$Http$jsonBody( var body = $elm$http$Http$jsonBody(
$elm$json$Json$Encode$object( $elm$json$Json$Encode$object(
@ -6309,7 +6312,7 @@ var $author$project$Main$addWatch = function (model) {
return $elm$http$Http$post( return $elm$http$Http$post(
{ {
body: body, body: body,
expect: $elm$http$Http$expectWhatever($author$project$Main$AddedLink), expect: $elm$http$Http$expectWhatever($author$project$Main$AddedWatch),
url: '/watches' url: '/watches'
}); });
}; };
@ -6375,6 +6378,22 @@ var $author$project$Main$update = F2(
model, model,
{newlink: newlink}), {newlink: newlink}),
$elm$core$Platform$Cmd$none); $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': case 'AddedLink':
if (msg.a.$ === 'Err') { if (msg.a.$ === 'Err') {
return _Utils_Tuple2( 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$placeholder = $elm$html$Html$Attributes$stringProperty('placeholder');
var $elm$html$Html$Attributes$type_ = $elm$html$Html$Attributes$stringProperty('type'); var $elm$html$Html$Attributes$type_ = $elm$html$Html$Attributes$stringProperty('type');
var $author$project$Main$labeledTextBox = F4( var $elm$html$Html$Attributes$value = $elm$html$Html$Attributes$stringProperty('value');
function (labelStr, placeStr, inputName, inputHandler) { var $author$project$Main$labeledInput = F5(
function (labelStr, placeStr, inputName, inputValue, inputHandler) {
return A2( return A2(
$elm$html$Html$label, $elm$html$Html$label,
_List_Nil, _List_Nil,
@ -6710,7 +6730,8 @@ var $author$project$Main$labeledTextBox = F4(
$elm$html$Html$Attributes$type_('text'), $elm$html$Html$Attributes$type_('text'),
$elm$html$Html$Attributes$name(inputName), $elm$html$Html$Attributes$name(inputName),
$elm$html$Html$Events$onInput(inputHandler), $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) _List_Nil)
])); ]));
@ -6736,88 +6757,92 @@ var $elm$html$Html$Events$onCheck = function (tagger) {
'change', 'change',
A2($elm$json$Json$Decode$map, tagger, $elm$html$Html$Events$targetChecked)); 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(
return A2( function (model, newlink) {
$elm$html$Html$div, return A2(
_List_Nil, $elm$html$Html$div,
_List_fromArray( _List_Nil,
[ _List_fromArray(
A2( [
$author$project$Main$createForm, A2(
$author$project$Main$SubmitLink, $author$project$Main$createForm,
A2( $author$project$Main$SubmitLink,
$elm$html$Html$div, A2(
_List_fromArray( $elm$html$Html$div,
[ _List_fromArray(
$elm$html$Html$Attributes$class('form-content') [
]), $elm$html$Html$Attributes$class('form-content')
_List_fromArray( ]),
[ _List_fromArray(
A2( [
$elm$html$Html$div, A2(
_List_Nil, $elm$html$Html$div,
_List_fromArray( _List_Nil,
[ _List_fromArray(
A4( [
$author$project$Main$labeledTextBox, A5(
'Name: ', $author$project$Main$labeledInput,
'Potato', 'Name: ',
'name', 'Potato',
function (v) { 'name',
return $author$project$Main$GotNewLink( model.newlink.name,
_Utils_update( function (v) {
newlink, return $author$project$Main$GotNewLink(
{name: v})); _Utils_update(
}), newlink,
A4( {name: v}));
$author$project$Main$labeledTextBox, }),
'URL: ', A5(
'https://....', $author$project$Main$labeledInput,
'url', 'URL: ',
function (v) { 'https://....',
return $author$project$Main$GotNewLink( 'url',
_Utils_update( model.newlink.url,
newlink, function (v) {
{url: v})); return $author$project$Main$GotNewLink(
}), _Utils_update(
A4( newlink,
$author$project$Main$labeledTextBox, {url: v}));
'Icon: ', }),
'https://....', A5(
'logo_url', $author$project$Main$labeledInput,
function (v) { 'Icon: ',
return $author$project$Main$GotNewLink( 'https://....',
_Utils_update( 'logo_url',
newlink, model.newlink.logo_url,
{logo_url: v})); function (v) {
}), return $author$project$Main$GotNewLink(
A2( _Utils_update(
$elm$html$Html$label, newlink,
_List_Nil, {logo_url: v}));
_List_fromArray( }),
[ A2(
$elm$html$Html$text('Shared: '), $elm$html$Html$label,
A2( _List_Nil,
$elm$html$Html$input, _List_fromArray(
_List_fromArray( [
[ $elm$html$Html$text('Shared: '),
$elm$html$Html$Attributes$type_('checkbox'), A2(
$elm$html$Html$Attributes$name('linkshared'), $elm$html$Html$input,
$elm$html$Html$Events$onCheck( _List_fromArray(
function (v) { [
return $author$project$Main$GotNewLink( $elm$html$Html$Attributes$type_('checkbox'),
_Utils_update( $elm$html$Html$Attributes$name('linkshared'),
newlink, $elm$html$Html$Events$onCheck(
{shared: v})); function (v) {
}), return $author$project$Main$GotNewLink(
$elm$html$Html$Attributes$checked(newlink.shared) _Utils_update(
]), newlink,
_List_Nil) {shared: v}));
])) }),
])) $elm$html$Html$Attributes$checked(newlink.shared)
]))) ]),
])); _List_Nil)
}; ]))
]))
])))
]));
});
var $elm$html$Html$Events$onClick = function (msg) { var $elm$html$Html$Events$onClick = function (msg) {
return A2( return A2(
$elm$html$Html$Events$on, $elm$html$Html$Events$on,
@ -6907,7 +6932,7 @@ var $author$project$Main$viewLinks = function (model) {
[ [
A2( A2(
$author$project$Main$bar, $author$project$Main$bar,
$author$project$Main$linkForm(model.newlink), A2($author$project$Main$linkForm, model, model.newlink),
A2( A2(
$elm$html$Html$a, $elm$html$Html$a,
_List_fromArray( _List_fromArray(
@ -7017,45 +7042,48 @@ var $author$project$Main$GotNewWatch = function (a) {
return {$: 'GotNewWatch', a: a}; return {$: 'GotNewWatch', a: a};
}; };
var $author$project$Main$SubmitWatch = {$: 'SubmitWatch'}; var $author$project$Main$SubmitWatch = {$: 'SubmitWatch'};
var $author$project$Main$watchForm = function (newwatch) { var $author$project$Main$watchForm = F2(
return A2( function (model, newwatch) {
$elm$html$Html$div, return A2(
_List_Nil, $elm$html$Html$div,
_List_fromArray( _List_Nil,
[ _List_fromArray(
A2( [
$author$project$Main$createForm, A2(
$author$project$Main$SubmitWatch, $author$project$Main$createForm,
A2( $author$project$Main$SubmitWatch,
$elm$html$Html$div, A2(
_List_Nil, $elm$html$Html$div,
_List_fromArray( _List_Nil,
[ _List_fromArray(
A4( [
$author$project$Main$labeledTextBox, A5(
'Item: ', $author$project$Main$labeledInput,
'some string...', 'Item: ',
'name', 'some string...',
function (v) { 'name',
return $author$project$Main$GotNewWatch( model.newwatch.name,
_Utils_update( function (v) {
newwatch, return $author$project$Main$GotNewWatch(
{name: v})); _Utils_update(
}), newwatch,
A4( {name: v}));
$author$project$Main$labeledTextBox, }),
'Repository: ', A5(
'NixOS/nixpkgs', $author$project$Main$labeledInput,
'repo', 'Repository: ',
function (v) { 'NixOS/nixpkgs',
return $author$project$Main$GotNewWatch( 'repo',
_Utils_update( model.newwatch.repo,
newwatch, function (v) {
{repo: v})); return $author$project$Main$GotNewWatch(
}) _Utils_update(
]))) newwatch,
])); {repo: v}));
}; })
])))
]));
});
var $author$project$Main$viewWatches = function (model) { var $author$project$Main$viewWatches = function (model) {
return A2( return A2(
$elm$html$Html$div, $elm$html$Html$div,
@ -7064,7 +7092,7 @@ var $author$project$Main$viewWatches = function (model) {
[ [
A2( A2(
$author$project$Main$bar, $author$project$Main$bar,
$author$project$Main$watchForm(model.newwatch), A2($author$project$Main$watchForm, model, model.newwatch),
A2( A2(
$elm$html$Html$a, $elm$html$Html$a,
_List_fromArray( _List_fromArray(

View File

@ -3,7 +3,7 @@ module Main exposing (..)
import Browser import Browser
import Data import Data
import Html exposing (..) 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 Html.Events exposing (..)
import Http import Http
import Json.Decode as Decode import Json.Decode as Decode
@ -32,6 +32,7 @@ main =
type Msg type Msg
= AddedLink (Result Http.Error ()) = AddedLink (Result Http.Error ())
| AddedWatch (Result Http.Error ())
| DeletedLink (Result Http.Error ()) | DeletedLink (Result Http.Error ())
| DeleteLink Int | DeleteLink Int
| GotLinks (Result Http.Error (List Data.Link)) | GotLinks (Result Http.Error (List Data.Link))
@ -151,7 +152,7 @@ addWatch model =
Http.post Http.post
{ url = "/watches" { url = "/watches"
, body = body , body = body
, expect = Http.expectWhatever AddedLink , expect = Http.expectWhatever AddedWatch
} }
@ -180,6 +181,12 @@ update msg model =
GotNewLink newlink -> GotNewLink newlink ->
( { model | newlink = newlink }, Cmd.none ) ( { 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 _) -> AddedLink (Err _) ->
( { model | status = Errored "Server error adding a link!" }, Cmd.none ) ( { model | status = Errored "Server error adding a link!" }, Cmd.none )
@ -353,29 +360,29 @@ repoInfoDecoder =
(field "nameWithOwner" string) (field "nameWithOwner" string)
watchForm : NewWatch -> Html Msg watchForm : Model -> NewWatch -> Html Msg
watchForm newwatch = watchForm model newwatch =
div [] div []
[ createForm SubmitWatch [ createForm SubmitWatch
(div (div
[] []
[ labeledTextBox "Item: " "some string..." "name" (\v -> GotNewWatch { newwatch | name = v }) [ labeledInput "Item: " "some string..." "name" model.newwatch.name (\v -> GotNewWatch { newwatch | name = v })
, labeledTextBox "Repository: " "NixOS/nixpkgs" "repo" (\v -> GotNewWatch { newwatch | repo = v }) , labeledInput "Repository: " "NixOS/nixpkgs" "repo" model.newwatch.repo (\v -> GotNewWatch { newwatch | repo = v })
] ]
) )
] ]
linkForm : NewLink -> Html Msg linkForm : Model -> NewLink -> Html Msg
linkForm newlink = linkForm model newlink =
div [] div []
[ createForm SubmitLink [ createForm SubmitLink
(div [ class "form-content" ] (div [ class "form-content" ]
[ div [ div
[] []
[ labeledTextBox "Name: " "Potato" "name" (\v -> GotNewLink { newlink | name = v }) [ labeledInput "Name: " "Potato" "name" model.newlink.name (\v -> GotNewLink { newlink | name = v })
, labeledTextBox "URL: " "https://...." "url" (\v -> GotNewLink { newlink | url = v }) , labeledInput "URL: " "https://...." "url" model.newlink.url (\v -> GotNewLink { newlink | url = v })
, labeledTextBox "Icon: " "https://...." "logo_url" (\v -> GotNewLink { newlink | logo_url = v }) , labeledInput "Icon: " "https://...." "logo_url" model.newlink.logo_url (\v -> GotNewLink { newlink | logo_url = v })
, label [] , label []
[ text "Shared: " [ text "Shared: "
, input , input
@ -392,8 +399,8 @@ linkForm newlink =
] ]
labeledTextBox : String -> String -> String -> (String -> msg) -> Html msg labeledInput : String -> String -> String -> String -> (String -> msg) -> Html msg
labeledTextBox labelStr placeStr inputName inputHandler = labeledInput labelStr placeStr inputName inputValue inputHandler =
label [] label []
[ text labelStr [ text labelStr
, input , input
@ -401,6 +408,7 @@ labeledTextBox labelStr placeStr inputName inputHandler =
, name inputName , name inputName
, onInput inputHandler , onInput inputHandler
, placeholder placeStr , placeholder placeStr
, value inputValue
] ]
[] []
] ]
@ -435,7 +443,7 @@ bar left right =
viewLinks : Model -> Html Msg viewLinks : Model -> Html Msg
viewLinks model = viewLinks model =
div [] div []
[ bar (linkForm model.newlink) (a [ onClick ReloadLinks ] [ text " " ]) [ bar (linkForm model model.newlink) (a [ onClick ReloadLinks ] [ text " " ])
, case model.links of , case model.links of
_ :: _ -> _ :: _ ->
div div
@ -450,7 +458,7 @@ viewLinks model =
viewWatches : Model -> Html Msg viewWatches : Model -> Html Msg
viewWatches model = viewWatches model =
div [] div []
[ bar (watchForm model.newwatch) (a [ onClick ReloadWatches ] [ text " " ]) [ bar (watchForm model model.newwatch) (a [ onClick ReloadWatches ] [ text " " ])
, case model.watches of , case model.watches of
_ :: _ -> _ :: _ ->
ul [] (List.map viewWatch model.watches) ul [] (List.map viewWatch model.watches)