-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #293 from curiosta/feat/add-umami-script
feat: add umami script
- Loading branch information
Showing
2 changed files
with
57 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,63 @@ | ||
import Button from '@components/Button'; | ||
import FormControl from '@components/FormControl'; | ||
import Input from '@components/Input'; | ||
import type { Signal } from '@preact/signals'; | ||
import type { Product } from '@store/productStore'; | ||
import debounce from '@utils/debounce'; | ||
import getProductsFromUrl from '@utils/getProductsFromUrl'; | ||
import type { FunctionComponent } from 'preact'; | ||
import Button from "@components/Button"; | ||
import FormControl from "@components/FormControl"; | ||
import Input from "@components/Input"; | ||
import type { Signal } from "@preact/signals"; | ||
import type { Product } from "@store/productStore"; | ||
import debounce from "@utils/debounce"; | ||
import getProductsFromUrl from "@utils/getProductsFromUrl"; | ||
import type { FunctionComponent } from "preact"; | ||
|
||
type TSearchInputProps = { | ||
products: Signal<Product[]> | ||
} | ||
products: Signal<Product[]>; | ||
}; | ||
|
||
const SearchInput: FunctionComponent<TSearchInputProps> = ({ products }) => { | ||
const onSearchChange = (e: any) => { | ||
const url = new URL(window.location.href) | ||
url.searchParams.set('q', e.target.value) | ||
window.history.replaceState(undefined, '', url.href) | ||
const url = new URL(window.location.href); | ||
url.searchParams.set("q", e.target.value); | ||
window.history.replaceState(undefined, "", url.href); | ||
|
||
debounce(async () => { | ||
const { result } = await getProductsFromUrl(url.href) | ||
const { result } = await getProductsFromUrl(url.href); | ||
products.value = result.products; | ||
}) | ||
} | ||
|
||
if (e.target.value) { | ||
const searchValue = e.target.value; | ||
window.umami.track(e.target.name, { searchValue }); | ||
} | ||
}); | ||
}; | ||
|
||
return ( | ||
<div className={`flex w-3/4`}> | ||
<FormControl className={'flex w-full'}> | ||
<Input placeholder="Search products..." className={`rounded-r-none h-10`} onChange={onSearchChange} /> | ||
<Button className={`p-0 w-10 h-10 rounded-l-none flex items-center justify-center`}> | ||
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="w-6 h-6"> | ||
<path stroke-linecap="round" stroke-linejoin="round" d="M21 21l-5.197-5.197m0 0A7.5 7.5 0 105.196 5.196a7.5 7.5 0 0010.607 10.607z" /> | ||
<FormControl className={"flex w-full"}> | ||
<Input | ||
placeholder="Search products..." | ||
className={`rounded-r-none h-10`} | ||
onChange={onSearchChange} | ||
name="search" | ||
/> | ||
<Button | ||
className={`p-0 w-10 h-10 rounded-l-none flex items-center justify-center`} | ||
> | ||
<svg | ||
xmlns="http://www.w3.org/2000/svg" | ||
fill="none" | ||
viewBox="0 0 24 24" | ||
stroke-width="1.5" | ||
stroke="currentColor" | ||
class="w-6 h-6" | ||
> | ||
<path | ||
stroke-linecap="round" | ||
stroke-linejoin="round" | ||
d="M21 21l-5.197-5.197m0 0A7.5 7.5 0 105.196 5.196a7.5 7.5 0 0010.607 10.607z" | ||
/> | ||
</svg> | ||
</Button> | ||
</FormControl> | ||
</div> | ||
) | ||
} | ||
); | ||
}; | ||
|
||
export default SearchInput | ||
export default SearchInput; |