prefetching data

This commit is contained in:
MuslemRahimi 2024-09-21 17:34:35 +02:00
parent e98252ad00
commit d02b71b6dd
3 changed files with 12 additions and 15 deletions

View File

@ -11,14 +11,13 @@
async function toggle() { async function toggle() {
hasUnreadElement = false; hasUnreadElement = false;
goto('/notifications')
} }
</script> </script>
<!--Start Notification Bell--> <!--Start Notification Bell-->
{#if data?.user} {#if data?.user}
<div on:click={toggle} class="text-gray-300 sm:hover:text-white cursor-pointer sm:hover:bg-[#27272A] relative border p-2 rounded-lg border-gray-800 ml-3 -mr-1"> <a href="/notifications" on:click={toggle} class="text-gray-300 sm:hover:text-white cursor-pointer sm:hover:bg-[#27272A] relative border p-2 rounded-lg border-gray-800 ml-3 -mr-1">
<Bell class="h-[20px] w-[20px]" /> <Bell class="h-[20px] w-[20px]" />
{#if hasUnreadElement} {#if hasUnreadElement}
@ -30,7 +29,7 @@ async function toggle() {
{/if} {/if}
</div> </a>
{/if} {/if}

View File

@ -19,6 +19,9 @@
} }
else else
{ {
const closePopup = document.getElementById("priceAlertModal");
closePopup?.dispatchEvent(new MouseEvent('click'))
const postData = { const postData = {
'userId': data?.user?.id, 'userId': data?.user?.id,
'symbol': $assetType === 'stock' ? $stockTicker : $assetType === 'etf' ? $etfTicker : $cryptoTicker, 'symbol': $assetType === 'stock' ? $stockTicker : $assetType === 'etf' ? $etfTicker : $cryptoTicker,
@ -40,9 +43,6 @@
const output = (await response.json())?.items const output = (await response.json())?.items
const closePopup = document.getElementById("priceAlertModal");
closePopup?.dispatchEvent(new MouseEvent('click'))
if (output === 'success') { if (output === 'success') {
toast.success(`Successfully created price alert`, { toast.success(`Successfully created price alert`, {
style: 'border-radius: 10px; background: #333; color: #fff; padding: 12px; margin-top: 10px; box-shadow: 0 25px 50px -12px rgb(0 0 0 / 0.25);', style: 'border-radius: 10px; background: #333; color: #fff; padding: 12px; margin-top: 10px; box-shadow: 0 25px 50px -12px rgb(0 0 0 / 0.25);',

View File

@ -9,6 +9,8 @@
export let apiURL; export let apiURL;
export let apiKey; export let apiKey;
let dataLoaded = false; // Flag to track data loading
let assetType = ''; let assetType = '';
let showSuggestions = false; let showSuggestions = false;
@ -21,13 +23,9 @@
async function loadSearchData() { async function loadSearchData() {
if ($searchBarData.length !== 0 || dataLoaded) return;
if($searchBarData?.length !== 0)
{
return
}
else { else {
dataLoaded = true;
// make the GET request to the endpoint // make the GET request to the endpoint
const response = await fetch(apiURL+'/searchbar-data', { const response = await fetch(apiURL+'/searchbar-data', {
method: 'GET', method: 'GET',
@ -37,8 +35,8 @@
}); });
$searchBarData = await response.json(); $searchBarData = await response.json();
}
}
} }
@ -315,7 +313,7 @@ $: {
<label on:click={loadSearchData} for="searchBarModal" class="cursor-pointer p-2 sm:hover:bg-[#27272A] text-gray-300 sm:hover:text-white flex-shrink-0 flex items-center justify-center border border-gray-800 rounded-lg"> <label on:mouseover={loadSearchData} on:click={loadSearchData} for="searchBarModal" class="cursor-pointer p-2 sm:hover:bg-[#27272A] text-gray-300 sm:hover:text-white flex-shrink-0 flex items-center justify-center border border-gray-800 rounded-lg">
<Search class="h-[20px] w-[20px]" /> <Search class="h-[20px] w-[20px]" />
</label> </label>