This commit is contained in:
MuslemRahimi 2024-12-24 18:03:09 +01:00
parent d9dc0a0284
commit a21eab3cfb
2 changed files with 350 additions and 319 deletions

View File

@ -19,7 +19,6 @@
$: inputValue = "";
let searchOpen = false;
let searchBarModalChecked = false; // Initialize it to false
let inputElement;
@ -54,9 +53,9 @@
async function handleSearch(symbol, assetType) {
searchBarTicker(symbol);
goto(`/${assetType === "ETF" ? "etf" : assetType === "Crypto" ? "crypto" : "stocks"}/${symbol}`)
goto(
`/${assetType === "ETF" ? "etf" : assetType === "Crypto" ? "crypto" : "stocks"}/${symbol}`,
);
}
async function popularTicker(state) {
@ -145,7 +144,6 @@
searchBarData = await response?.json();
}, 50); // delay
isLoading = false;
}
const onKeyPress = (e) => {
@ -198,12 +196,11 @@
assetType = selectedItem?.type;
focusedSuggestion = selectedItem?.symbol;
}
}
const handleControlK = async (event) => {
if (event.ctrlKey && event.key === "k") {
//const keyboardSearch = document.getElementById("searchBarModal");
//keyboardSearch?.dispatchEvent(new MouseEvent("click"));
const keyboardSearch = document.getElementById("combobox-input");
keyboardSearch?.dispatchEvent(new MouseEvent("click"));
event.preventDefault();
}
};
@ -243,7 +240,6 @@
};
});
$: {
if (searchBarModalChecked === true && typeof window !== "undefined") {
if ($screenWidth > 640) {
@ -284,24 +280,28 @@
}
}
}
</script>
<div class="hidden sm:block w-full sm:max-w-[600px] grow">
<div >
<div class="hidden sm:block w-full sm:max-w-[600px]">
<div>
<div class="relative flex items-center">
<div class="absolute inset-y-0 left-0 flex items-center pl-2.5">
<svg class="h-4 w-4 text-icon xs:h-5 xs:w-5" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="3" stroke="currentColor" viewBox="0 0 24 24" style="max-width: 40px" aria-hidden="true"><path d="M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z"></path></svg></div>
<Combobox.Root
items={searchBarData}
bind:inputValue
bind:touchedInput
<svg
class="h-4 w-4 text-icon xs:h-5 xs:w-5"
fill="none"
stroke-linecap="round"
stroke-linejoin="round"
stroke-width="3"
stroke="currentColor"
viewBox="0 0 24 24"
style="max-width: 40px"
aria-hidden="true"
><path d="M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z"></path></svg
>
</div>
<Combobox.Root items={searchBarData} bind:inputValue bind:touchedInput>
<div class="relative w-full">
<div
class="absolute inset-y-0 left-0 flex items-center pl-2.5"
>
<div class="absolute inset-y-0 left-0 flex items-center pl-2.5">
<svg
class="text-icon h-5 w-5"
fill="none"
@ -313,23 +313,25 @@
style="max-width: 40px"
aria-hidden="true"
>
<path d="M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z"
></path>
<path d="M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z"></path>
</svg>
</div>
<Combobox.Input
id="combobox-input"
on:input={search}
class="grow rounded-sm border border-gray-600 py-2 pl-9 text-[1rem] placeholder-gray-400 focus:border-default focus:shadow-lg focus:outline-none focus:ring-0 tiny:pl-8 xs:pl-10 text-white md:py-2 w-full bg-secondary sm:hover:bg-[#09090B] focus:bg-[#09090B] dark:bg-dark-700 dark:hover:bg-dark-700 dark:focus:bg-dark-700"
placeholder="Company or stock symbol..."
aria-label="Company or stock symbol..."
/>
<div class="absolute inset-y-0 right-0 flex items-center gap-x-2 px-3 text-gray-350 font-semibold">
<div
class="absolute inset-y-0 right-0 flex items-center gap-x-2 px-3 text-gray-350 font-semibold"
>
{#if isLoading}
<span class="loading loading-spinner loading-sm"></span>
{:else if inputValue?.length > 0}
<label class="cursor-pointer" on:click={() => inputValue = ""}>
<label class="cursor-pointer" on:click={() => (inputValue = "")}>
<svg
class="w-6 h-6 "
class="w-6 h-6"
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 24 24"
><path
@ -339,50 +341,60 @@
>
</label>
{:else}
<div class="pointer-events-none rounded-md border border-gray-500 px-2 py-0.5">
/
<div
class="pointer-events-none absolute end-6 top-2.5 gap-1 opacity-80 rtl:flex-row-reverse hidden lg:flex"
>
<kbd class="kbd kbd-sm">ctrl</kbd>
<kbd class="kbd kbd-sm">K</kbd>
</div>
{/if}
</div>
</div>
{#if inputValue?.length > 0}
<Combobox.Content
class="w-auto z-40 -mt-0.5 rounded-md border border-gray-700 bg-[#09090B] px-1 py-3 shadow-popover outline-none"
sideOffset={8}
on:keydown={handleKeyDown}
>
{#if inputValue?.length > 0 && searchBarData?.length > 0}
{#each searchBarData as item}
<Combobox.Item
class="cursor-pointer text-white border-b border-gray-600 last:border-none flex h-fit w-auto select-none items-center rounded-button py-3 pl-5 pr-1.5 text-sm capitalize outline-none transition-all duration-75 data-[highlighted]:bg-primary"
class="cursor-pointer text-white border-b border-gray-600 last:border-none flex h-fit w-auto select-none items-center rounded-button py-3 pl-3 pr-1.5 text-sm capitalize outline-none transition-all duration-75 data-[highlighted]:bg-primary"
value={item?.symbol}
label={item?.name}
on:click={() => handleSearch(item?.symbol, item?.type)}
>
<div
class="flex flex-row items-center justify-between w-full">
<span class="text-sm text-blue-400"
>{item?.symbol}</span
>
<span class="ml-3 text-sm text-white"
>{item?.name}</span
>
<span class="ml-auto text-sm text-white"
>{item?.type}</span
>
<div class="flex flex-row items-center justify-between w-full">
<span class="text-sm text-blue-400">{item?.symbol}</span>
<span class="ml-3 text-sm text-white">{item?.name}</span>
<span class="ml-auto text-sm text-white">{item?.type}</span>
</div>
</Combobox.Item>
{/each}
{:else if inputValue?.length === 0}
{#each searchHistory as item}
<Combobox.Item
class="cursor-pointer text-white border-b border-gray-600 last:border-none flex h-fit w-auto select-none items-center rounded-button py-3 pl-3 pr-1.5 text-sm capitalize outline-none transition-all duration-75 data-[highlighted]:bg-primary"
value={item?.symbol}
label={item?.name}
on:click={() => handleSearch(item?.symbol, item?.type)}
>
<div class="flex flex-row items-center justify-between w-full">
<span class="text-sm text-blue-400">{item?.symbol}</span>
<span class="ml-3 text-sm text-white">{item?.name}</span>
<span class="ml-auto text-sm text-white">{item?.type}</span>
</div>
</Combobox.Item>
{/each}
{:else}
<span class="block px-5 py-2 text-sm text-white">
No results found
</span>
{/each}
</Combobox.Content>
{/if}
</Combobox.Content>
</Combobox.Root>
</div>
</div>
</div>
</div>
<label
for="searchBarModal"
@ -391,17 +403,16 @@
<Search class="h-[20px] w-[20px]" />
</label>
<input
<input
type="checkbox"
id="searchBarModal"
class="modal-toggle"
bind:checked={searchBarModalChecked}
/>
/>
<dialog id="searchBarModal" class="modal p-3 sm:p-0">
<dialog id="searchBarModal" class="modal p-3 sm:p-0">
<label for="searchBarModal" class="cursor-pointer modal-backdrop"></label>
<div
class="z-[999] modal-box overflow-hidden rounded-md bg-secondary border border-gray-600 sm:my-8 sm:m-auto sm:h-auto w-full sm:w-3/4 lg:w-1/2 2xl:w-1/3"
>
@ -423,20 +434,41 @@
<!-- Search layout -->
<div class="mt-8">
<div class="relative">
<div
class="inline-block cursor-pointer absolute right-5 top-1.5 text-[1.3rem] sm:text-[1.5rem] text-white"
>
{#if isLoading}
<span class="loading loading-spinner loading-sm"></span>
{:else if inputValue?.length > 0}
<label class="cursor-pointer" on:click={() => (inputValue = "")}>
<svg
class="w-6 h-6 mt-2 ml-1"
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 24 24"
><path
fill="white"
d="m6.4 18.308l-.708-.708l5.6-5.6l-5.6-5.6l.708-.708l5.6 5.6l5.6-5.6l.708.708l-5.6 5.6l5.6 5.6l-.708.708l-5.6-5.6z"
/></svg
>
</label>
{:else}
/
{/if}
</div>
<label for="modal-search" class="sr-only">Search</label>
<input
id="modal-search"
class="rounded-md w-full text-white bg-secondary border border-gray-600 focus:ring-transparent placeholder-gray-200 py-3 pl-10 pr-4"
type="search"
placeholder="Search Anything…"
placeholder="Company or stock symbol..."
bind:value={inputValue}
bind:this={inputElement}
on:input={search}
on:keydown={handleKeyDown}
on:keypress={onKeyPress}
autocomplete="off"
/>
<button
on:click={() => searchBarTicker(inputValue)}
class="absolute inset-0 right-auto group"
@ -479,7 +511,6 @@
: 'shake-ticker cursor-pointer bg-secondary sm:hover:bg-primary rounded-md flex justify-start items-center p-2 text-white group'} w-full"
>
<div class="flex flex-row items-center w-full">
<div class="flex flex-col">
<span class="text-blue-400">{item?.symbol}</span>
<span class="text-white"
@ -551,11 +582,8 @@
</ul>
</div>
</div>
</div>
</dialog>
</dialog>
<!--End Drawer Sidewise for mobile-->
<!--End Drawer Sidewise for mobile-->

View File

@ -795,8 +795,6 @@
</Sheet.Close>
{/if}
</nav>
</Sheet.Content>
</Sheet.Root>
@ -809,15 +807,15 @@
<span class="text-white font-semibold ml-2 text-lg">Stocknear</span>
</a>
<div class="relative w-full flex flex-row justify-end sm:justify-between items-center">
<div class="sm:w-full lg:ml-16">
<div
class="relative w-full flex flex-row justify-end sm:justify-between items-center"
>
<div class="sm:w-full xl:ml-16">
<Searchbar />
</div>
<NotificationBell {data} {hasUnreadElement} />
<div class="ml-3">
<div class="ml-4">
{#if data?.user}
<DropdownMenu.Root>
<DropdownMenu.Trigger asChild let:builder>
@ -838,28 +836,39 @@
</Button>
</DropdownMenu.Trigger>
<DropdownMenu.Content align="end">
<a href="/profile" class="cursor-pointer ">
<DropdownMenu.Item class="sm:hover:bg-primary cursor-pointer">
<a href="/profile" class="cursor-pointer">
<DropdownMenu.Item
class="sm:hover:bg-primary cursor-pointer"
>
My Account
</DropdownMenu.Item>
</a>
<DropdownMenu.Separator />
<a href="/watchlist/stocks" class="cursor-pointer">
<DropdownMenu.Item class="sm:hover:bg-primary cursor-pointer">
<DropdownMenu.Item
class="sm:hover:bg-primary cursor-pointer"
>
Watchlist
</DropdownMenu.Item>
</a>
<a href="/price-alert" class="cursor-pointer">
<DropdownMenu.Item class="sm:hover:bg-primary cursor-pointer">
<DropdownMenu.Item
class="sm:hover:bg-primary cursor-pointer"
>
Price Alert
</DropdownMenu.Item>
</a>
<DropdownMenu.Separator />
<form class="cursor-pointer" action="/logout" method="POST">
<button type="submit" class="w-full text-start cursor-pointer">
<DropdownMenu.Item class="sm:hover:bg-primary cursor-pointer">
<button
type="submit"
class="w-full text-start cursor-pointer"
>
<DropdownMenu.Item
class="sm:hover:bg-primary cursor-pointer"
>
<span class="text-start">Logout</span>
</DropdownMenu.Item>
</button>
@ -875,12 +884,7 @@
</a>
{/if}
</div>
</div>
</div>
<div>
<div class="flex w-full">
@ -1172,7 +1176,6 @@
</a>
{/if}
</nav>
</aside>
</div>
<div class="w-full xl:w-5/6">