diff --git a/src/lib/components/TickerInfoCard.svelte b/src/lib/components/TickerInfoCard.svelte index 7b3a8b0b..b094629e 100644 --- a/src/lib/components/TickerInfoCard.svelte +++ b/src/lib/components/TickerInfoCard.svelte @@ -181,7 +181,7 @@ $: { Shares Out. {abbreviateNumber(data?.getStockQuote?.sharesOutstanding)} Forward PE - {forwardPE === undefined ? '-' : forwardPE} + {(forwardPE === undefined || forwardPE === null)? '-' : forwardPE} diff --git a/src/routes/stocks/[tickerID]/forecast/analyst/+page.server.ts b/src/routes/stocks/[tickerID]/forecast/analyst/+page.server.ts index 658b0492..c34681fd 100644 --- a/src/routes/stocks/[tickerID]/forecast/analyst/+page.server.ts +++ b/src/routes/stocks/[tickerID]/forecast/analyst/+page.server.ts @@ -1,6 +1,6 @@ export const load = async ({ locals, params }) => { const getAnalystTickerHistory = async () => { - const { apiURL, apiKey } = locals; + const { apiURL, apiKey, user } = locals; const postData = { ticker: params.tickerID, @@ -16,7 +16,8 @@ export const load = async ({ locals, params }) => { body: JSON.stringify(postData), }); - const output = await response.json(); + let output = await response.json(); + output = user?.tier !== "Pro" ? output?.slice(0, 6) : output; return output; }; diff --git a/src/routes/stocks/[tickerID]/forecast/analyst/+page.svelte b/src/routes/stocks/[tickerID]/forecast/analyst/+page.svelte index 66e63489..83c7af68 100644 --- a/src/routes/stocks/[tickerID]/forecast/analyst/+page.svelte +++ b/src/routes/stocks/[tickerID]/forecast/analyst/+page.svelte @@ -2,20 +2,20 @@ import {numberOfUnreadNotification, displayCompanyName, stockTicker, currentPortfolioPrice} from '$lib/store'; import InfoModal from '$lib/components/InfoModal.svelte'; -import InfiniteLoading from '$lib/components/InfiniteLoading.svelte'; - +import { onMount } from 'svelte'; import UpgradeToPro from '$lib/components/UpgradeToPro.svelte'; export let data; let analystRating = data?.getAnalystRating ?? {}; -let rawData = []; +let rawData = data?.getAnalystTickerHistory ?? []; let historyList = [] let priceTarget = 'n/a'; let numOfAnalyst = 0; let consensusRating = 'n/a'; -let changesPercentage = 0; +let changesPercentage = 0; +let isLoaded = false; const tabs = [ { @@ -41,27 +41,23 @@ function changeTab(index) { } if (activeIdx === 1) { rawData = data?.getAnalystTickerHistory?.filter(item => item?.analystScore >=4) - historyList = rawData?.slice(0,10) + historyList = rawData?.slice(0,30) } else { rawData = data?.getAnalystTickerHistory ?? []; - historyList = rawData?.slice(0,10) + historyList = rawData?.slice(0,30) } } -async function infiniteHandler({ detail: { loaded, complete } }) -{ -if (historyList?.length === rawData?.length) { - complete(); - } else { - const nextIndex = historyList?.length; - const newArticles = rawData?.slice(nextIndex, nextIndex + 5); - historyList = [...historyList, ...newArticles]; - loaded(); +async function handleScroll() { + const scrollThreshold = document.body.offsetHeight * 0.8; // 80% of the website height + const isBottom = window.innerHeight + window.scrollY >= scrollThreshold; + if (isBottom && historyList?.length !== rawData?.length) { + const nextIndex = historyList?.length; + const filteredNewResults = rawData?.slice(nextIndex, nextIndex + 50); + historyList = [...historyList, ...filteredNewResults]; + } } -} - - function latestInfoDate(inputDate) { // Convert the input date string to milliseconds since epoch @@ -80,8 +76,17 @@ function latestInfoDate(inputDate) { return differenceInDays <=4; } +onMount(async () => { + isLoaded = false; + changeTab(0) + isLoaded = true; -changeTab(0) + window.addEventListener('scroll', handleScroll); + return () => { + window.removeEventListener('scroll', handleScroll); + }; + +}) @@ -127,8 +132,8 @@ changeTab(0) - - {#if historyList?.length !== 0} + {#if isLoaded} +
@@ -235,6 +240,8 @@ changeTab(0)
+ {#if rawData?.length !== 0} +
@@ -317,24 +324,28 @@ changeTab(0)
- {#if data?.user?.tier === 'Pro'} - - {/if} - - - {:else} -
-
- - Wall Street analysts have not provided any ratings for {$displayCompanyName} + {:else} +
+
+ + There are no top analyst ratings available for the past 12 months for {$displayCompanyName} +
-
+ {/if} + + - {/if} - - + {:else} +
+
+ +
+
+ {/if}