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'
|
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,7 +6757,8 @@ 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(
|
||||||
|
function (model, newlink) {
|
||||||
return A2(
|
return A2(
|
||||||
$elm$html$Html$div,
|
$elm$html$Html$div,
|
||||||
_List_Nil,
|
_List_Nil,
|
||||||
@ -6758,33 +6780,36 @@ var $author$project$Main$linkForm = function (newlink) {
|
|||||||
_List_Nil,
|
_List_Nil,
|
||||||
_List_fromArray(
|
_List_fromArray(
|
||||||
[
|
[
|
||||||
A4(
|
A5(
|
||||||
$author$project$Main$labeledTextBox,
|
$author$project$Main$labeledInput,
|
||||||
'Name: ',
|
'Name: ',
|
||||||
'Potato',
|
'Potato',
|
||||||
'name',
|
'name',
|
||||||
|
model.newlink.name,
|
||||||
function (v) {
|
function (v) {
|
||||||
return $author$project$Main$GotNewLink(
|
return $author$project$Main$GotNewLink(
|
||||||
_Utils_update(
|
_Utils_update(
|
||||||
newlink,
|
newlink,
|
||||||
{name: v}));
|
{name: v}));
|
||||||
}),
|
}),
|
||||||
A4(
|
A5(
|
||||||
$author$project$Main$labeledTextBox,
|
$author$project$Main$labeledInput,
|
||||||
'URL: ',
|
'URL: ',
|
||||||
'https://....',
|
'https://....',
|
||||||
'url',
|
'url',
|
||||||
|
model.newlink.url,
|
||||||
function (v) {
|
function (v) {
|
||||||
return $author$project$Main$GotNewLink(
|
return $author$project$Main$GotNewLink(
|
||||||
_Utils_update(
|
_Utils_update(
|
||||||
newlink,
|
newlink,
|
||||||
{url: v}));
|
{url: v}));
|
||||||
}),
|
}),
|
||||||
A4(
|
A5(
|
||||||
$author$project$Main$labeledTextBox,
|
$author$project$Main$labeledInput,
|
||||||
'Icon: ',
|
'Icon: ',
|
||||||
'https://....',
|
'https://....',
|
||||||
'logo_url',
|
'logo_url',
|
||||||
|
model.newlink.logo_url,
|
||||||
function (v) {
|
function (v) {
|
||||||
return $author$project$Main$GotNewLink(
|
return $author$project$Main$GotNewLink(
|
||||||
_Utils_update(
|
_Utils_update(
|
||||||
@ -6817,7 +6842,7 @@ var $author$project$Main$linkForm = function (newlink) {
|
|||||||
]))
|
]))
|
||||||
])))
|
])))
|
||||||
]));
|
]));
|
||||||
};
|
});
|
||||||
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,7 +7042,8 @@ 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(
|
||||||
|
function (model, newwatch) {
|
||||||
return A2(
|
return A2(
|
||||||
$elm$html$Html$div,
|
$elm$html$Html$div,
|
||||||
_List_Nil,
|
_List_Nil,
|
||||||
@ -7031,22 +7057,24 @@ var $author$project$Main$watchForm = function (newwatch) {
|
|||||||
_List_Nil,
|
_List_Nil,
|
||||||
_List_fromArray(
|
_List_fromArray(
|
||||||
[
|
[
|
||||||
A4(
|
A5(
|
||||||
$author$project$Main$labeledTextBox,
|
$author$project$Main$labeledInput,
|
||||||
'Item: ',
|
'Item: ',
|
||||||
'some string...',
|
'some string...',
|
||||||
'name',
|
'name',
|
||||||
|
model.newwatch.name,
|
||||||
function (v) {
|
function (v) {
|
||||||
return $author$project$Main$GotNewWatch(
|
return $author$project$Main$GotNewWatch(
|
||||||
_Utils_update(
|
_Utils_update(
|
||||||
newwatch,
|
newwatch,
|
||||||
{name: v}));
|
{name: v}));
|
||||||
}),
|
}),
|
||||||
A4(
|
A5(
|
||||||
$author$project$Main$labeledTextBox,
|
$author$project$Main$labeledInput,
|
||||||
'Repository: ',
|
'Repository: ',
|
||||||
'NixOS/nixpkgs',
|
'NixOS/nixpkgs',
|
||||||
'repo',
|
'repo',
|
||||||
|
model.newwatch.repo,
|
||||||
function (v) {
|
function (v) {
|
||||||
return $author$project$Main$GotNewWatch(
|
return $author$project$Main$GotNewWatch(
|
||||||
_Utils_update(
|
_Utils_update(
|
||||||
@ -7055,7 +7083,7 @@ var $author$project$Main$watchForm = function (newwatch) {
|
|||||||
})
|
})
|
||||||
])))
|
])))
|
||||||
]));
|
]));
|
||||||
};
|
});
|
||||||
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(
|
||||||
|
38
src/Main.elm
38
src/Main.elm
@ -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)
|
||||||
|
Loading…
Reference in New Issue
Block a user