feat(users/Profpatsch/whatcd-resolver): simplify search
Throws out htmx for search in favor of a full page-reload for search. This means we can reload the page and it will re-do the search. It’s not POST anymore cause we don’t really change anything, just do some caching when doing the search. Could probably also cache the search result, but simple simple Change-Id: I70b0cbac55f67c986aeecfedcf0b3968890b3b9c Reviewed-on: https://cl.tvl.fyi/c/depot/+/13212 Tested-by: BuildkiteCI Reviewed-by: Profpatsch <mail@profpatsch.de>
This commit is contained in:
parent
dde78515f6
commit
0b881b6d23
1 changed files with 74 additions and 44 deletions
|
|
@ -135,37 +135,43 @@ htmlUi = do
|
||||||
counterHtml <- counterHtmlM
|
counterHtml <- counterHtmlM
|
||||||
mainHtml counterHtml uniqueRunId span
|
mainHtml counterHtml uniqueRunId span
|
||||||
),
|
),
|
||||||
( "snips/redacted/search",
|
( "redacted-search",
|
||||||
Html $
|
HtmlWithQueryArgs (singleQueryArgument "searchstr" Cat.id) $
|
||||||
\span -> do
|
\searchstr _span -> do
|
||||||
dat <-
|
t <- redactedSearchAndInsert [("searchstr", searchstr)]
|
||||||
parseMultipartOrThrow
|
|
||||||
span
|
|
||||||
req
|
|
||||||
( do
|
|
||||||
label @"searchstr" <$> Multipart.field "redacted-search" Cat.id
|
|
||||||
)
|
|
||||||
t <- redactedSearchAndInsert [("searchstr", dat.searchstr)]
|
|
||||||
runTransaction $ do
|
runTransaction $ do
|
||||||
res <- t
|
res <- t
|
||||||
table <-
|
(table, settings) <-
|
||||||
getBestTorrentsTable
|
concurrentlyTraced
|
||||||
(label @"groupByReleaseType" True)
|
( getBestTorrentsTable
|
||||||
( Just (E21 (label @"onlyTheseTorrents" res.newTorrents)) ::
|
(label @"groupByReleaseType" True)
|
||||||
( Maybe
|
( Just
|
||||||
( E2
|
( E21
|
||||||
"onlyTheseTorrents"
|
(label @"onlyTheseTorrents" res.newTorrents)
|
||||||
[Label "torrentId" Int]
|
) ::
|
||||||
"artistRedactedId"
|
Maybe
|
||||||
Natural
|
( E2
|
||||||
)
|
"onlyTheseTorrents"
|
||||||
|
[Label "torrentId" Int]
|
||||||
|
"artistRedactedId"
|
||||||
|
Natural
|
||||||
|
)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
pure
|
(getSettings)
|
||||||
[hsx|
|
pure $
|
||||||
<h1>Search results for <pre>{dat.searchstr}</pre></h1>
|
mainHtml'
|
||||||
{table}
|
( MainHtml
|
||||||
|]
|
{ pageTitle = [fmt|whatcd-resolver – Search – {searchstr & bytesToTextUtf8Lenient}|],
|
||||||
|
counterHtml = "",
|
||||||
|
mainContent =
|
||||||
|
[hsx|<h1>Search results for <pre>{searchstr}</pre></h1>{table}|],
|
||||||
|
uniqueRunId,
|
||||||
|
searchFieldContent = searchstr & bytesToTextUtf8Lenient,
|
||||||
|
settings
|
||||||
|
}
|
||||||
|
)
|
||||||
|
_span
|
||||||
),
|
),
|
||||||
( "snips/redacted/torrentDataJson",
|
( "snips/redacted/torrentDataJson",
|
||||||
Html $ \span -> do
|
Html $ \span -> do
|
||||||
|
|
@ -337,28 +343,52 @@ htmlUi = do
|
||||||
(getBestTorrentsTable (label @"groupByReleaseType" False) Nothing)
|
(getBestTorrentsTable (label @"groupByReleaseType" False) Nothing)
|
||||||
(getSettings)
|
(getSettings)
|
||||||
-- transmissionTorrentsTable <- lift @Transaction getTransmissionTorrentsTable
|
-- transmissionTorrentsTable <- lift @Transaction getTransmissionTorrentsTable
|
||||||
let returnUrl = (label @"returnUrl" "/")
|
|
||||||
pure $
|
pure $
|
||||||
htmlPageChrome
|
mainHtml'
|
||||||
"whatcd-resolver"
|
( MainHtml
|
||||||
( [hsx|
|
{ pageTitle = "whatcd-resolver",
|
||||||
{counterHtml}
|
counterHtml,
|
||||||
{settingButtons returnUrl settings}
|
mainContent = bestTorrentsTable,
|
||||||
|
uniqueRunId,
|
||||||
|
settings,
|
||||||
|
searchFieldContent = ""
|
||||||
|
}
|
||||||
|
)
|
||||||
|
_span
|
||||||
|
|
||||||
|
data MainHtml = MainHtml
|
||||||
|
{ pageTitle :: Text,
|
||||||
|
counterHtml :: Html,
|
||||||
|
mainContent :: Html,
|
||||||
|
searchFieldContent :: Text,
|
||||||
|
uniqueRunId :: Text,
|
||||||
|
settings :: Settings
|
||||||
|
}
|
||||||
|
|
||||||
|
mainHtml' :: MainHtml -> Otel.Span -> Html
|
||||||
|
mainHtml' dat _span = do
|
||||||
|
-- transmissionTorrentsTable <- lift @Transaction getTransmissionTorrentsTable
|
||||||
|
let returnUrl = (label @"returnUrl" "/")
|
||||||
|
|
||||||
|
htmlPageChrome
|
||||||
|
dat.pageTitle
|
||||||
|
( [hsx|
|
||||||
|
{dat.counterHtml}
|
||||||
|
{settingButtons returnUrl dat.settings}
|
||||||
|]
|
|]
|
||||||
<> [hsx|
|
<> [hsx|
|
||||||
<form
|
<form action="redacted-search">
|
||||||
hx-post="/snips/redacted/search"
|
<label for="redacted-search-input">Redacted Search</label>
|
||||||
hx-target="#redacted-search-results">
|
|
||||||
<label for="redacted-search">Redacted Search</label>
|
|
||||||
<input
|
<input
|
||||||
id="redacted-search"
|
id="redacted-search-input"
|
||||||
type="text"
|
type="text"
|
||||||
name="redacted-search" />
|
name="searchstr"
|
||||||
|
value={dat.searchFieldContent} />
|
||||||
<button type="submit" hx-disabled-elt="this">Search</button>
|
<button type="submit" hx-disabled-elt="this">Search</button>
|
||||||
<div class="htmx-indicator">Search running!</div>
|
<div class="htmx-indicator">Search running!</div>
|
||||||
</form>
|
</form>
|
||||||
<div id="redacted-search-results">
|
<div>
|
||||||
{bestTorrentsTable}
|
{dat.mainContent}
|
||||||
</div>
|
</div>
|
||||||
<!-- refresh the page if the uniqueRunId is different -->
|
<!-- refresh the page if the uniqueRunId is different -->
|
||||||
<input
|
<input
|
||||||
|
|
@ -366,13 +396,13 @@ htmlUi = do
|
||||||
type="text"
|
type="text"
|
||||||
id="autorefresh"
|
id="autorefresh"
|
||||||
name="hasItBeenRestarted"
|
name="hasItBeenRestarted"
|
||||||
value={uniqueRunId}
|
value={dat.uniqueRunId}
|
||||||
hx-get="/autorefresh"
|
hx-get="/autorefresh"
|
||||||
hx-trigger="every 5s"
|
hx-trigger="every 5s"
|
||||||
hx-swap="none"
|
hx-swap="none"
|
||||||
/>
|
/>
|
||||||
|]
|
|]
|
||||||
)
|
)
|
||||||
|
|
||||||
-- | Run two actions concurrently, and add them to the current Otel trace
|
-- | Run two actions concurrently, and add them to the current Otel trace
|
||||||
concurrentlyTraced :: (MonadUnliftIO m) => m a -> m b -> m (a, b)
|
concurrentlyTraced :: (MonadUnliftIO m) => m a -> m b -> m (a, b)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue