From c076670767b07ddf26b895c5691382cfef77ae40 Mon Sep 17 00:00:00 2001 From: MuslemRahimi Date: Mon, 9 Sep 2024 00:41:14 +0200 Subject: [PATCH] fix div infinite scroll for modal --- .../etf/[tickerID]/options/+page.svelte | 34 +++++++++++++++---- .../stocks/[tickerID]/options/+page.svelte | 34 +++++++++++++++---- 2 files changed, 56 insertions(+), 12 deletions(-) diff --git a/src/routes/etf/[tickerID]/options/+page.svelte b/src/routes/etf/[tickerID]/options/+page.svelte index f8472cf3..8cc167ce 100644 --- a/src/routes/etf/[tickerID]/options/+page.svelte +++ b/src/routes/etf/[tickerID]/options/+page.svelte @@ -433,15 +433,34 @@ function daysLeft(targetDate) { let optionHistoryList = []; +let container; +let rawDataHistory = []; + +function getScroll() { + const scrollThreshold = container.scrollHeight * 0.8; // 80% of the container height + + // Check if the user has scrolled to the bottom based on the threshold + const isBottom = container.scrollTop + container.clientHeight >= scrollThreshold; + + // Only load more data if at the bottom and there is still data to load + if (isBottom && optionHistoryList?.length !== rawDataHistory?.length) { + const nextIndex = optionHistoryList.length; // Ensure optionHistoryList is defined + const filteredNewResults = rawDataHistory.slice(nextIndex, nextIndex + 25); // Ensure rawData is defined + optionHistoryList = [...optionHistoryList, ...filteredNewResults]; + } +} + async function handleViewData(date:string) { isLoaded = false; optionDetailsDesktopModal?.showModal() - optionHistoryList = await getDailyTransactions($etfTicker+'-'+date); + rawDataHistory = await getDailyTransactions($etfTicker+'-'+date); - optionHistoryList?.forEach((item) => { + rawDataHistory?.forEach((item) => { item.dte = daysLeft(item?.date_expiration); }); + + optionHistoryList = rawDataHistory?.slice(0,20) isLoaded = true; } @@ -464,7 +483,10 @@ function changeStatement(event) { optionChainList = (data?.getOptionsChainData?.filter(item => item?.date_expiration === event.target.value))?.at(0)?.chain || []; } - + + + + $: { if ((displayTimePeriod || displayData) && optionsPlotData?.length !== 0 && typeof window !== 'undefined') { // Filter the raw plot data based on the selected time period @@ -872,17 +894,17 @@ $: {