mock shop page: store listing search in query
This commit is contained in:
+46
-6
@@ -2,6 +2,7 @@
|
|||||||
{{ $platform := parsePlatform .PathParams.platform }}
|
{{ $platform := parsePlatform .PathParams.platform }}
|
||||||
{{ $shopID := .PathParams.shopID }}
|
{{ $shopID := .PathParams.shopID }}
|
||||||
{{- $shop := .Accounts.GetMockShop $acctID $platform $shopID }}
|
{{- $shop := .Accounts.GetMockShop $acctID $platform $shopID }}
|
||||||
|
{{- $initialSearchTerm := .Request.URL.Query.Get "search" }}
|
||||||
|
|
||||||
<h1 class="mt-[1em] text-center">
|
<h1 class="mt-[1em] text-center">
|
||||||
{{ $shop.Name }}
|
{{ $shop.Name }}
|
||||||
@@ -21,9 +22,9 @@
|
|||||||
<h2 class="text-center">
|
<h2 class="text-center">
|
||||||
Listings
|
Listings
|
||||||
</h2>
|
</h2>
|
||||||
<h3 class="text-center">
|
<p class="text-center">
|
||||||
Add listings to your mock store to begin mocking store synchronization
|
Add listings to begin synchronization on your mocking store
|
||||||
</h3>
|
</p>
|
||||||
</header>
|
</header>
|
||||||
|
|
||||||
<div
|
<div
|
||||||
@@ -154,7 +155,7 @@
|
|||||||
set the value of the first <input[name='name']/> in me to name
|
set the value of the first <input[name='name']/> in me to name
|
||||||
set the value of the first <input[name='sku']/> in me to sku
|
set the value of the first <input[name='sku']/> in me to sku
|
||||||
set the value of the first <input[name='description']/> in me to description
|
set the value of the first <input[name='description']/> in me to description
|
||||||
set the innerHTML of the <h3/> in me to ('Editing ' + name)
|
set the innerHTML of the <h3/> in me to ('Editing: ' + name)
|
||||||
"
|
"
|
||||||
>
|
>
|
||||||
<h3 class="col-[span_2] text-center">
|
<h3 class="col-[span_2] text-center">
|
||||||
@@ -224,6 +225,9 @@
|
|||||||
h-fit
|
h-fit
|
||||||
rounded-lg
|
rounded-lg
|
||||||
"
|
"
|
||||||
|
{{/* the next two lines to prevent form submission */}}
|
||||||
|
onsubmit="return false;"
|
||||||
|
hx-boost="false"
|
||||||
>
|
>
|
||||||
<label for="name" class="self-center">
|
<label for="name" class="self-center">
|
||||||
Find Listing
|
Find Listing
|
||||||
@@ -232,9 +236,9 @@
|
|||||||
type="search"
|
type="search"
|
||||||
name="name"
|
name="name"
|
||||||
class="bg-accent p-[0.25em] rounded-sm"
|
class="bg-accent p-[0.25em] rounded-sm"
|
||||||
|
value="{{$initialSearchTerm}}"
|
||||||
_="
|
_="
|
||||||
on input
|
def filterList(term)
|
||||||
set term to event.target.value
|
|
||||||
if (not term)
|
if (not term)
|
||||||
remove .hidden from <li/> in next <ul/>
|
remove .hidden from <li/> in next <ul/>
|
||||||
else
|
else
|
||||||
@@ -247,6 +251,42 @@
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
init
|
||||||
|
set :prevTerm to '{{$initialSearchTerm}}'
|
||||||
|
|
||||||
|
on load
|
||||||
|
make a URL from window.location.href called url
|
||||||
|
set params to url.searchParams
|
||||||
|
|
||||||
|
set :prevTerm to params.get('search')
|
||||||
|
if (not :prevTerm)
|
||||||
|
set :prevTerm to ''
|
||||||
|
end
|
||||||
|
filterList(:prevTerm)
|
||||||
|
end
|
||||||
|
|
||||||
|
on input
|
||||||
|
event.preventDefault()
|
||||||
|
set term to event.target.value
|
||||||
|
filterList(term)
|
||||||
|
set :prevTerm to term
|
||||||
|
|
||||||
|
-- update the url query with the search term
|
||||||
|
-- including in the history
|
||||||
|
|
||||||
|
make a URL from window.location.href called url
|
||||||
|
set params to url.searchParams
|
||||||
|
if term
|
||||||
|
params.set('search', term)
|
||||||
|
else
|
||||||
|
params.delete('search')
|
||||||
|
end
|
||||||
|
history.replaceState(null, null, url.toString())
|
||||||
|
|
||||||
|
on rerun
|
||||||
|
filterList(:prevTerm)
|
||||||
"
|
"
|
||||||
/>
|
/>
|
||||||
</form>
|
</form>
|
||||||
|
|||||||
Reference in New Issue
Block a user