bugfixing infinite loader
This commit is contained in:
parent
a61ce7613a
commit
6bf1c9be11
@ -1,7 +1,6 @@
|
|||||||
<script lang='ts'>
|
<script lang='ts'>
|
||||||
import { goto } from '$app/navigation';
|
import { goto } from '$app/navigation';
|
||||||
import { numberOfUnreadNotification, screenWidth } from '$lib/store';
|
import { numberOfUnreadNotification, screenWidth } from '$lib/store';
|
||||||
import InfiniteLoading from '$lib/components/InfiniteLoading.svelte';
|
|
||||||
import { abbreviateNumber } from '$lib/utils';
|
import { abbreviateNumber } from '$lib/utils';
|
||||||
import { onMount } from 'svelte';
|
import { onMount } from 'svelte';
|
||||||
import UpgradeToPro from '$lib/components/UpgradeToPro.svelte';
|
import UpgradeToPro from '$lib/components/UpgradeToPro.svelte';
|
||||||
@ -16,23 +15,32 @@
|
|||||||
let stockList = [];
|
let stockList = [];
|
||||||
|
|
||||||
|
|
||||||
async function infiniteHandler({ detail: { loaded, complete } })
|
async function handleScroll() {
|
||||||
{
|
const scrollThreshold = document.body.offsetHeight * 0.8; // 80% of the website height
|
||||||
if (stockList?.length === rawData?.length) {
|
const isBottom = window.innerHeight + window.scrollY >= scrollThreshold;
|
||||||
complete();
|
if (isBottom && stockList?.length !== rawData?.length) {
|
||||||
} else {
|
|
||||||
const nextIndex = stockList?.length;
|
const nextIndex = stockList?.length;
|
||||||
const newArticles = rawData?.slice(nextIndex, nextIndex + 5);
|
const filteredNewResults = rawData?.slice(nextIndex, nextIndex + 25);
|
||||||
stockList = [...stockList, ...newArticles];
|
stockList = [...stockList, ...filteredNewResults];
|
||||||
loaded();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
onMount(() => {
|
onMount(() => {
|
||||||
rawData = data?.getMostRetailVolume ?? [];
|
rawData = data?.getMostRetailVolume ?? [];
|
||||||
stockList = rawData?.slice(0,20) ?? []
|
stockList = rawData?.slice(0,20) ?? []
|
||||||
|
|
||||||
isLoaded = true;
|
isLoaded = true;
|
||||||
|
|
||||||
|
|
||||||
|
if(data?.user?.tier === 'Pro') {
|
||||||
|
window.addEventListener('scroll', handleScroll);
|
||||||
|
return () => {
|
||||||
|
window.removeEventListener('scroll', handleScroll);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
@ -208,7 +216,6 @@
|
|||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
<InfiniteLoading on:infinite={infiniteHandler} />
|
|
||||||
<UpgradeToPro data={data} title="Get the top 100 stocks that retail investors put their money on the market to never miss out the next hype"/>
|
<UpgradeToPro data={data} title="Get the top 100 stocks that retail investors put their money on the market to never miss out the next hype"/>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@ -142,7 +142,6 @@ onmessage = async (event: MessageEvent) => {
|
|||||||
const { rawData, ruleOfList, filterQuery } = event.data || {};
|
const { rawData, ruleOfList, filterQuery } = event.data || {};
|
||||||
const filteredData = await filterRawData(rawData, ruleOfList, filterQuery);
|
const filteredData = await filterRawData(rawData, ruleOfList, filterQuery);
|
||||||
postMessage({ message: "success", filteredData });
|
postMessage({ message: "success", filteredData });
|
||||||
console.log(filteredData);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export {};
|
export {};
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user