prefetching data
This commit is contained in:
parent
e98252ad00
commit
d02b71b6dd
@ -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}
|
||||||
|
|
||||||
|
|||||||
@ -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,
|
||||||
@ -37,11 +40,8 @@
|
|||||||
},
|
},
|
||||||
body: JSON.stringify(postData)
|
body: JSON.stringify(postData)
|
||||||
});
|
});
|
||||||
|
|
||||||
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`, {
|
||||||
|
|||||||
@ -8,6 +8,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 = '';
|
||||||
|
|
||||||
@ -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,9 +35,9 @@
|
|||||||
});
|
});
|
||||||
|
|
||||||
$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>
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user