From 74e403fd09e50450fa2f3415fedde82ee97b6b6a Mon Sep 17 00:00:00 2001 From: MuslemRahimi Date: Thu, 14 Nov 2024 00:23:53 +0100 Subject: [PATCH] update search feature --- src/lib/components/Searchbar.svelte | 684 ++++++++------------ src/routes/+layout.svelte | 3 +- src/routes/api/searchbar-data/+server.ts | 17 - src/routes/api/searchbar/+server.ts | 17 + src/routes/crypto/[tickerID]/+layout.svelte | 23 +- src/routes/etf/[tickerID]/+layout.svelte | 22 +- src/routes/stocks/[tickerID]/+layout.svelte | 23 +- 7 files changed, 279 insertions(+), 510 deletions(-) delete mode 100644 src/routes/api/searchbar-data/+server.ts create mode 100644 src/routes/api/searchbar/+server.ts diff --git a/src/lib/components/Searchbar.svelte b/src/lib/components/Searchbar.svelte index b06ec617..4ddbada6 100644 --- a/src/lib/components/Searchbar.svelte +++ b/src/lib/components/Searchbar.svelte @@ -1,40 +1,50 @@ - - @@ -469,125 +330,108 @@ - {#if $searchBarData?.length !== 0} -
- -
- {#if notFoundTicker} -

- Oh snapp, ticker does not exist in our database -

- {/if} +
+ +
+ {#if !showSuggestions} +
+ {searchHistory?.length > 0 ? "Recent" : "Popular"} +
+ {/if} + +
+ {/each} + {:else if showSuggestions && searchBarData?.length > 0} +
+ Suggestions +
+ {#each searchBarData as item} +
  • + + + searchBarTicker(item?.symbol)} + class="mb-2 {item?.symbol === focusedSuggestion + ? 'shake-ticker cursor-pointer flex justify-start items-center p-2 text-white bg-[#27272A] rounded group' + : 'cursor-pointer mb-2 bg-[#09090B] sm:hover:bg-[#27272A] rounded-lg flex justify-start items-center p-2 text-white group'}" + > +
    +
    + {item?.symbol} + {item?.name?.length > 150 + ? item?.name?.slice(0, 150) + "..." + : item?.name} +
    + +
    + {item?.type} +
    +
    +
    +
  • + {/each} + {:else if showSuggestions && searchBarData?.length === 0} +
  • + +
  • + {/if} +
    - {:else} -
    -
    - -
    -
    - {/if} +
    - {#if $searchBarData?.length !== 0} -
    - -
    - {#if notFoundTicker} -

    - Oh snapp, ticker does not exist in our database -

    - {/if} +
    + +
    + {#if !showSuggestions} +
    + {searchHistory?.length > 0 ? "Recent" : "Popular"} +
    + {/if} +
    + {/each} + {:else if showSuggestions && searchBarData?.length > 0} +
    + Suggestions +
    + {#each searchBarData as item} +
  • + + + searchBarTicker(item?.symbol)} + class="mb-2 {item?.symbol === focusedSuggestion + ? 'shake-ticker cursor-pointer flex justify-start items-center p-2 text-white bg-[#27272A] rounded group' + : 'cursor-pointer mb-2 bg-[#09090B] bg-opacity-[0.4] rounded-lg flex justify-start items-center p-2 text-white group'}" + > +
    +
    + {item?.symbol} + {item?.name.length > charNumber + ? item?.name.slice(0, charNumber) + "..." + : item?.name} +
    + +
    + {item?.type} +
    +
    +
    +
  • + {/each} + {:else if showSuggestions && searchBarData?.length === 0} +
  • + +
  • + {/if} +
    - {:else} -
    - -
    - {/if} +
    -