Skip to content

Commit

Permalink
Populate inputs on /search page
Browse files Browse the repository at this point in the history
  • Loading branch information
runeksvendsen committed Nov 29, 2024
1 parent dac7ebe commit 11e68c4
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
5 changes: 3 additions & 2 deletions src/server/Server/Pages/Root.hs
Original file line number Diff line number Diff line change
Expand Up @@ -122,14 +122,15 @@ mkInput
-> [Attribute] -- ^ Attributes
-> Html () -- ^ Initial suggestions
-> T.Text -- ^ input ID
-> Maybe FunGraph.FullyQualifiedType
-> Maybe FunGraph.FullyQualifiedType -- ^ initial value (optional)
-> Html ()
mkInput jsTriggerFunctionName attrs initialSuggestions id' mInitialValue = do
suggestions
input_ $ attrs ++
[ name_ id'
, id_ id'
, type_ "search"
, value_ $ maybe mempty Server.Pages.Typeahead.renderSearchValue mInitialValue
, list_ suggestionsId
, hxGet_ "/typeahead" -- get suggestions from here (TODO: use something type-safe)
, hxTarget_ $ "#" <> suggestionsId -- put suggestions here
Expand All @@ -145,4 +146,4 @@ mkInput jsTriggerFunctionName attrs initialSuggestions id' mInitialValue = do
datalist_
[ id_ suggestionsId
, name_ suggestionsId
] $ maybe mempty (Server.Pages.Typeahead.suggestionOption_ [selected_ ""]) mInitialValue <> initialSuggestions
] initialSuggestions
7 changes: 6 additions & 1 deletion src/server/Server/Pages/Typeahead.hs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
module Server.Pages.Typeahead
( mkHandler, HandlerType
, suggestionOption_
, renderSearchValue
)
where

Expand Down Expand Up @@ -109,7 +110,11 @@ suggestions prioTrie prefix = do
suggestionOption_ :: [Attribute] -> FunGraph.FullyQualifiedType -> Html ()
suggestionOption_ extraAttrs fqt =
option_
([ value_ $ FunGraph.renderFullyQualifiedType fqt
([ value_ $ renderSearchValue fqt
, label_ $ FunGraph.renderFullyQualifiedTypeNoPackage fqt
] ++ extraAttrs)
""

-- ^ Render a value that goes into the src/dst search input
renderSearchValue :: FunGraph.FullyQualifiedType -> T.Text
renderSearchValue = FunGraph.renderFullyQualifiedType

0 comments on commit 11e68c4

Please sign in to comment.