add list of recent searches

This commit is contained in:
Aaron Bieber 2024-04-25 09:16:21 -06:00
parent 0c6a6b2370
commit a65335bf31
No known key found for this signature in database
3 changed files with 491 additions and 263 deletions

View File

@ -53,7 +53,7 @@
default = pkgs.mkShell { default = pkgs.mkShell {
shellHook = '' shellHook = ''
PS1='\u@\h:\@; ' PS1='\u@\h:\@; '
nix flake run github:qbit/xin#flake-warn nix run github:qbit/xin#flake-warn
echo "Perl `${pkgs.perl}/bin/perl --version`" echo "Perl `${pkgs.perl}/bin/perl --version`"
''; '';
buildInputs = with pkgs.perlPackages; [ buildInputs = with pkgs.perlPackages; [

File diff suppressed because it is too large Load Diff

View File

@ -7,7 +7,7 @@ import Html.Styled exposing (..)
import Html.Styled.Attributes exposing (css, href, placeholder, style) import Html.Styled.Attributes exposing (css, href, placeholder, style)
import Html.Styled.Events exposing (onClick, onInput) import Html.Styled.Events exposing (onClick, onInput)
import Http exposing (..) import Http exposing (..)
import Json.Decode as Decode exposing (Decoder, field, list, map2, map6, string) import Json.Decode as Decode exposing (Decoder, field, list, map2, map7, string)
type Status type Status
@ -25,6 +25,7 @@ type Msg
= RunSearch = RunSearch
| GotResult (Result Http.Error Model) | GotResult (Result Http.Error Model)
| GCResult (Result Http.Error WorkStatus) | GCResult (Result Http.Error WorkStatus)
| GotSearches (Result Http.Error Searches)
| UpdateResult (Result Http.Error WorkStatus) | UpdateResult (Result Http.Error WorkStatus)
| SetPR String | SetPR String
| UpdateBackend | UpdateBackend
@ -41,11 +42,22 @@ type alias WorkStatus =
} }
type alias Search =
{ pull_request : Int
, title : String
}
type alias Searches =
List Search
type alias Model = type alias Model =
{ pull_request : Int { pull_request : Int
, release : String , release : String
, status : Status , status : Status
, title : String , title : String
, searches : Searches
, branches : Branches , branches : Branches
, error : String , error : String
, loading : Bool , loading : Bool
@ -100,6 +112,12 @@ update msg model =
GotResult (Ok pr) -> GotResult (Ok pr) ->
( pr, Cmd.none ) ( pr, Cmd.none )
GotSearches (Err err) ->
( { model | error = "Error: " ++ httpErr err, loading = False }, Cmd.none )
GotSearches (Ok searches) ->
( { model | searches = searches }, Cmd.none )
GCResult (Err err) -> GCResult (Err err) ->
( { model | error = "Error: " ++ httpErr err, loading = False }, Cmd.none ) ( { model | error = "Error: " ++ httpErr err, loading = False }, Cmd.none )
@ -139,6 +157,7 @@ initialModel =
, status = Open , status = Open
, title = "" , title = ""
, branches = [] , branches = []
, searches = []
, error = "" , error = ""
, loading = False , loading = False
, updateStatus = , updateStatus =
@ -154,7 +173,7 @@ initialModel =
init : () -> ( Model, Cmd Msg ) init : () -> ( Model, Cmd Msg )
init _ = init _ =
( initialModel, Cmd.none ) ( initialModel, getSearches )
loading : Html msg loading : Html msg
@ -210,6 +229,10 @@ view model =
_ -> _ ->
span [ style "color" "red" ] [ text model.error ] span [ style "color" "red" ] [ text model.error ]
, hr [] [] , hr [] []
, div []
[ viewSearches model.searches
]
, hr [] []
, div [] , div []
[ button [ button
[ onClick UpdateBackend [ onClick UpdateBackend
@ -235,6 +258,32 @@ view model =
} }
viewSearch : Search -> Html Msg
viewSearch search =
let
prStr =
String.fromInt search.pull_request
in
ol []
[ text prStr
, text (": " ++ search.title)
, ul []
[ li [] [ a [ href ("https://github.com/NixOS/nixpkgs/pull/" ++ prStr) ] [ text "nixpkgs" ] ]
, li [] [ a [ href ("/" ++ prStr) ] [ text "json" ] ]
, li [] [ a [ onClick (SetPR prStr) ] [ text "Refresh" ] ]
]
]
viewSearches : Searches -> Html Msg
viewSearches searches =
ul []
(List.map
viewSearch
searches
)
viewWorkAction : WorkStatus -> Html Msg viewWorkAction : WorkStatus -> Html Msg
viewWorkAction work = viewWorkAction work =
case work.action of case work.action of
@ -324,6 +373,14 @@ getResult model =
} }
getSearches : Cmd Msg
getSearches =
Http.get
{ url = "/searches"
, expect = Http.expectJson GotSearches searchListDecoder
}
getGC : Cmd Msg getGC : Cmd Msg
getGC = getGC =
Http.get Http.get
@ -367,15 +424,28 @@ workStatusDecoder =
(field "updateTime" Decode.float) (field "updateTime" Decode.float)
searchListDecoder : Decoder Searches
searchListDecoder =
list searchDecoder
searchDecoder : Decoder Search
searchDecoder =
map2 Search
(field "pull_request" Decode.int)
(field "title" string)
resultDecoder : Decoder Model resultDecoder : Decoder Model
resultDecoder = resultDecoder =
map6 map7
(\pull_request release status title branches error -> (\pull_request release status title branches searches error ->
{ pull_request = pull_request { pull_request = pull_request
, release = release , release = release
, status = status , status = status
, title = title , title = title
, branches = branches , branches = branches
, searches = searches
, error = error , error = error
, loading = False , loading = False
, updateStatus = initialModel.updateStatus , updateStatus = initialModel.updateStatus
@ -387,6 +457,7 @@ resultDecoder =
(field "status" statusDecoder) (field "status" statusDecoder)
(field "title" string) (field "title" string)
(field "branches" (list string)) (field "branches" (list string))
(field "searches" (list searchDecoder))
(field "error" string) (field "error" string)