Preserve search options between packages and options search page (#82)

This commit is contained in:
Rok Garbas 2020-06-10 14:03:44 +02:00 committed by GitHub
parent 9413e66d90
commit 6905ea40dd
Failed to generate hash of commit

View file

@ -28,10 +28,10 @@ import Html.Attributes
import Page.Home import Page.Home
import Page.Options import Page.Options
import Page.Packages import Page.Packages
import RemoteData
import Route import Route
import Search import Search
import Url import Url
import Url.Builder
@ -113,7 +113,7 @@ submitQuery :
-> ( Model, Cmd Msg ) -> ( Model, Cmd Msg )
submitQuery old ( new, cmd ) = submitQuery old ( new, cmd ) =
let let
triggerSearch oldModel newModel msg makeRequest = triggerSearch _ newModel msg makeRequest =
if newModel.query /= Nothing then if newModel.query /= Nothing then
( new ( new
, Cmd.batch , Cmd.batch
@ -241,7 +241,7 @@ view model =
[ a [ class "brand", href "https://search.nixos.org" ] [ a [ class "brand", href "https://search.nixos.org" ]
[ img [ src "https://nixos.org/logo/nix-wiki.png", class "logo" ] [] [ img [ src "https://nixos.org/logo/nix-wiki.png", class "logo" ] []
] ]
, viewNavigation model.url , viewNavigation model.page model.url
] ]
] ]
] ]
@ -263,13 +263,36 @@ view model =
] ]
viewNavigation : Url.Url -> Html Msg viewNavigation : Page -> Url.Url -> Html Msg
viewNavigation url = viewNavigation page url =
let
preserveSearchOptions =
case page of
Packages model ->
model.query
|> Maybe.map (\q -> [ Url.Builder.string "query" q ])
|> Maybe.withDefault []
|> List.append [ Url.Builder.string "channel" model.channel ]
Options model ->
model.query
|> Maybe.map (\q -> [ Url.Builder.string "query" q ])
|> Maybe.withDefault []
|> List.append [ Url.Builder.string "channel" model.channel ]
_ ->
[]
createUrl path =
[]
|> List.append preserveSearchOptions
|> Url.Builder.absolute [ path ]
in
ul [ class "nav" ] ul [ class "nav" ]
(List.map (List.map
(viewNavigationItem url) (viewNavigationItem url)
[ ( "/packages", "Packages" ) [ ( createUrl "packages", "Packages" )
, ( "/options", "Options" ) , ( createUrl "options", "Options" )
] ]
) )