bugfixing

This commit is contained in:
MuslemRahimi 2024-10-30 23:31:24 +01:00
parent f24f6db31c
commit 4faa874d4f

View File

@ -66,18 +66,23 @@
} }
// Save recent ticker // Save recent ticker
searchHistory = [...searchHistory];
console.log(searchHistory);
await saveRecentTicker(); await saveRecentTicker();
// Map of asset types to their corresponding actions // Map of asset types to their corresponding actions
console.log(upperState, assetType);
const assetActions = { const assetActions = {
ETF: () => { ETF: () => {
etfTicker.update(() => upperState); etfTicker.update(() => upperState);
goto(`/etf/${upperState}`);
}, },
Stock: () => { Stock: () => {
stockTicker.update(() => upperState); stockTicker.update(() => upperState);
goto(`/stocks/${upperState}`);
}, },
Crypto: () => { Crypto: () => {
cryptoTicker.update(() => upperState); cryptoTicker.update(() => upperState);
goto(`/crypto/${upperState}`);
}, },
}; };
@ -124,6 +129,8 @@
} }
// Map of asset types to their corresponding actions // Map of asset types to their corresponding actions
searchHistory = [...searchHistory];
console.log(searchHistory);
await saveRecentTicker(); await saveRecentTicker();
const assetActions = { const assetActions = {
@ -236,6 +243,8 @@
let focusedSuggestion = null; let focusedSuggestion = null;
function handleKeyDown(event) { function handleKeyDown(event) {
const newList = searchHistory?.length > 0 ? searchHistory : popularList;
if (event.key === "ArrowDown" && showSuggestions) { if (event.key === "ArrowDown" && showSuggestions) {
// Move down in the suggestions // Move down in the suggestions
event.preventDefault(); // Prevent scrolling event.preventDefault(); // Prevent scrolling
@ -261,23 +270,23 @@
} else if (event.key === "ArrowDown" && !showSuggestions) { } else if (event.key === "ArrowDown" && !showSuggestions) {
// Move down in the suggestions // Move down in the suggestions
event.preventDefault(); // Prevent scrolling event.preventDefault(); // Prevent scrolling
const currentIndex = popularList?.findIndex( const currentIndex = newList?.findIndex(
(item) => item?.symbol === searchQuery, (item) => item?.symbol === searchQuery,
); );
if (currentIndex < popularList?.length - 1) { if (currentIndex < newList?.length - 1) {
searchQuery = popularList[currentIndex + 1]?.symbol; searchQuery = newList[currentIndex + 1]?.symbol;
assetType = popularList[currentIndex + 1]?.type; assetType = newList[currentIndex + 1]?.type;
focusedSuggestion = searchQuery; // Update the focused suggestion focusedSuggestion = searchQuery; // Update the focused suggestion
} }
} else if (event.key === "ArrowUp" && !showSuggestions) { } else if (event.key === "ArrowUp" && !showSuggestions) {
// Move up in the suggestions // Move up in the suggestions
event.preventDefault(); // Prevent scrolling event.preventDefault(); // Prevent scrolling
const currentIndex = popularList?.findIndex( const currentIndex = newList?.findIndex(
(item) => item?.symbol === searchQuery, (item) => item?.symbol === searchQuery,
); );
if (currentIndex > 0) { if (currentIndex > 0) {
searchQuery = popularList[currentIndex - 1]?.symbol; searchQuery = newList[currentIndex - 1]?.symbol;
assetType = popularList[currentIndex - 1]?.type; assetType = newList[currentIndex - 1]?.type;
focusedSuggestion = searchQuery; // Update the focused suggestion focusedSuggestion = searchQuery; // Update the focused suggestion
} }
} }
@ -539,11 +548,8 @@
{#if !showSuggestions} {#if !showSuggestions}
{#each searchHistory?.length > 0 ? searchHistory : popularList as item} {#each searchHistory?.length > 0 ? searchHistory : popularList as item}
<li class="border-b border-gray-600"> <li class="border-b border-gray-600">
<a <label
data-sveltekit-preload-data={false} on:click={() => popularTicker(item?.symbol, item?.type)}
href={`/${item?.type === "ETF" ? "etf" : item?.type === "Crypto" ? "crypto" : "stocks"}/${item?.symbol}`}
on:click={() =>
popularTicker(item?.symbol, item?.assetType)}
class="mb-2 {item?.symbol === focusedSuggestion class="mb-2 {item?.symbol === focusedSuggestion
? 'shake-ticker cursor-pointer flex justify-start items-center p-2 text-white bg-[#27272A] rounded group' ? 'shake-ticker cursor-pointer flex justify-start items-center p-2 text-white bg-[#27272A] rounded group'
: 'shake-ticker cursor-pointer bg-[#09090B] sm:hover:bg-[#27272A] rounded-lg flex justify-start items-center p-2 text-white group'} w-full" : 'shake-ticker cursor-pointer bg-[#09090B] sm:hover:bg-[#27272A] rounded-lg flex justify-start items-center p-2 text-white group'} w-full"
@ -572,7 +578,7 @@
{item?.type} {item?.type}
</div> </div>
</div> </div>
</a> </label>
</li> </li>
{/each} {/each}
{:else if showSuggestions && searchResults?.length > 0} {:else if showSuggestions && searchResults?.length > 0}
@ -730,9 +736,7 @@
{#if !showSuggestions} {#if !showSuggestions}
{#each searchHistory?.length > 0 ? searchHistory : popularList as item} {#each searchHistory?.length > 0 ? searchHistory : popularList as item}
<li class="border-b border-gray-600"> <li class="border-b border-gray-600">
<a <label
data-sveltekit-preload-data={false}
href={`/${item?.type === "ETF" ? "etf" : item?.type === "Crypto" ? "crypto" : "stocks"}/${item?.symbol}`}
on:click={() => popularTicker(item?.symbol, item?.type)} on:click={() => popularTicker(item?.symbol, item?.type)}
class="mb-2 {item?.symbol === focusedSuggestion class="mb-2 {item?.symbol === focusedSuggestion
? 'shake-ticker cursor-pointer flex justify-start items-center p-2 text-white bg-[#27272A] rounded group' ? 'shake-ticker cursor-pointer flex justify-start items-center p-2 text-white bg-[#27272A] rounded group'
@ -762,7 +766,7 @@
{item?.type} {item?.type}
</div> </div>
</div> </div>
</a> </label>
</li> </li>
{/each} {/each}
{:else if showSuggestions && searchResults?.length > 0} {:else if showSuggestions && searchResults?.length > 0}