From 72855c6d8871f63bb3f11d32e3ce686883a6a4c3 Mon Sep 17 00:00:00 2001 From: MuslemRahimi Date: Mon, 12 Aug 2024 13:05:24 +0200 Subject: [PATCH] update list --- src/routes/list/amex-stocks/+page.svelte | 268 +++++++++-------- .../list/dividend-aristocrats/+page.svelte | 40 +-- src/routes/list/dividend-kings/+page.svelte | 42 +-- src/routes/list/dow-jones-stocks/+page.svelte | 270 +++++++++--------- src/routes/list/dow-jones-stocks/+page.ts | 21 +- .../list/nasdaq-100-stocks/+page.svelte | 268 +++++++++-------- src/routes/list/nasdaq-100-stocks/+page.ts | 22 +- src/routes/list/nasdaq-stocks/+page.svelte | 269 +++++++++-------- src/routes/list/nasdaq-stocks/+page.ts | 23 +- src/routes/list/nyse-stocks/+page.svelte | 270 +++++++++--------- src/routes/list/nyse-stocks/+page.ts | 23 +- src/routes/list/sp-500-stocks/+page.svelte | 270 +++++++++--------- src/routes/list/sp-500-stocks/+page.ts | 19 +- src/routes/list/xetra-stocks/+page.svelte | 269 +++++++++-------- src/routes/list/xetra-stocks/+page.ts | 22 +- 15 files changed, 977 insertions(+), 1119 deletions(-) diff --git a/src/routes/list/amex-stocks/+page.svelte b/src/routes/list/amex-stocks/+page.svelte index 44669576..15b67499 100644 --- a/src/routes/list/amex-stocks/+page.svelte +++ b/src/routes/list/amex-stocks/+page.svelte @@ -2,25 +2,29 @@ import { goto } from '$app/navigation'; import { screenWidth } from '$lib/store'; import { abbreviateNumber} from '$lib/utils'; - import InfiniteLoading from '$lib/components/InfiniteLoading.svelte'; + import { onMount } from 'svelte'; + export let data; let rawData = data?.getAmexStocks; let marketCapList = rawData?.slice(0,50); - async function infiniteHandler({ detail: { loaded, complete } }) - { - - if (marketCapList?.length === rawData?.length) { - complete(); - } - else { - const nextIndex = marketCapList?.length; - const newElements= rawData?.slice(nextIndex, nextIndex + 5); - marketCapList = [...marketCapList, ...newElements]; - 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 && marketCapList?.length !== rawData?.length) { + const nextIndex = marketCapList?.length; + const filteredNewResults = rawData?.slice(nextIndex, nextIndex + 50); + marketCapList = [...marketCapList, ...filteredNewResults]; } - } + } + + onMount(async () => { + window.addEventListener('scroll', handleScroll); + return () => { + window.removeEventListener('scroll', handleScroll); + }; + }) let totalMarketCap = rawData?.reduce((total, stock) => total + stock?.marketCap, 0); let totalRevenue = rawData?.reduce((total, stock) => total + stock?.revenue, 0); @@ -38,136 +42,124 @@ } } - -
- - -
- - A list of all the stocks that are currently listed on the AMEX (American Stock Exchange) stock exchange in the United States. -
- - -
- -
-
Total Stocks
-
{rawData?.length}
-
- -
-
Total Market Cap
-
{abbreviateNumber(totalMarketCap,true)}
-
- -
-
Total Revenue
-
{abbreviateNumber(totalRevenue,true)}
-
- -
-
Total Profits
-
{abbreviateNumber(totalProfits,true)}
-
- -
- - - - -
- +
+ + +
+ + A list of all the stocks that are currently listed on the AMEX (American Stock Exchange) stock exchange in the United States. +
+ + +
+ +
+
Total Stocks
+
{rawData?.length}
+
+ +
+
Total Market Cap
+
{abbreviateNumber(totalMarketCap,true)}
+
+ +
+
Total Revenue
+
{abbreviateNumber(totalRevenue,true)}
+
+ +
+
Total Profits
+
{abbreviateNumber(totalProfits,true)}
+
+ +
+ + + + +
+ + + + +
+ + + + + + + + + + + + + + + + {#each marketCapList as item} + + goto("/stocks/"+item?.symbol)} class="sm:hover:bg-[#245073] sm:hover:bg-opacity-[0.2] odd:bg-[#27272A] border-b-[#09090B] shake-ticker cursor-pointer"> + + + + + + + + + + + + + + + +
SymbolCompanyMarket CapRevenueProfitsPrice
+ {item?.symbol} + + {item?.name?.length > charNumber ? item?.name?.slice(0,charNumber) + "..." : item?.name} + + {abbreviateNumber(item?.marketCap,true)} + + {item?.revenue !== null ? abbreviateNumber(item?.revenue,true) : '-'} + + {item?.netIncome !== null ? abbreviateNumber(item?.netIncome,true) : '-'} + +
- -
- - - - - - - - - - - - - - - - {#each marketCapList as item,index} - - goto("/stocks/"+item?.symbol)} class="sm:hover:bg-[#245073] sm:hover:bg-opacity-[0.2] odd:bg-[#27272A] border-b-[#09090B] shake-ticker cursor-pointer"> - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + - {/each} - -
CompanyMarket CapPrice
- -
-
- {item?.symbol} - {item?.name?.length > charNumber ? item?.name?.slice(0,charNumber) + "..." : item?.name} +
+ ${item.price?.toFixed(2)} +
+ {#if item.changesPercentage >=0} + + +{item.changesPercentage?.toFixed(2)}% + {:else} + + {item.changesPercentage?.toFixed(2)}% + {/if}
-
- {abbreviateNumber(item?.marketCap,true)} - -
- -
- ${item.price?.toFixed(2)} -
- {#if item.changesPercentage >=0} - - +{item.changesPercentage?.toFixed(2)}% - {:else} - - {item.changesPercentage?.toFixed(2)}% - {/if} -
-
- - -
-
- - - + + {/each} +
-
+ +
- -
- - - - \ No newline at end of file + +
\ No newline at end of file diff --git a/src/routes/list/dividend-aristocrats/+page.svelte b/src/routes/list/dividend-aristocrats/+page.svelte index ca3c9184..2802206e 100644 --- a/src/routes/list/dividend-aristocrats/+page.svelte +++ b/src/routes/list/dividend-aristocrats/+page.svelte @@ -1,36 +1,38 @@ -
+
-
+
Dividend Aristocrats are companies in the S&P500 index that have been raising their dividends every year for 25 or more years. This is a list of all the dividend aristocrats. @@ -38,7 +40,7 @@ -
+
@@ -120,9 +122,7 @@ - - - +
diff --git a/src/routes/list/dividend-kings/+page.svelte b/src/routes/list/dividend-kings/+page.svelte index 3733d927..1212c526 100644 --- a/src/routes/list/dividend-kings/+page.svelte +++ b/src/routes/list/dividend-kings/+page.svelte @@ -1,36 +1,38 @@ -
+
-
+
Dividend Kings are companies that have been raising their dividend payments every year for 50 or more years. This is a list of all the dividend kings on the US stock market. @@ -38,7 +40,7 @@ -
+
@@ -120,9 +122,7 @@ - - - +
diff --git a/src/routes/list/dow-jones-stocks/+page.svelte b/src/routes/list/dow-jones-stocks/+page.svelte index fad2534e..183622c1 100644 --- a/src/routes/list/dow-jones-stocks/+page.svelte +++ b/src/routes/list/dow-jones-stocks/+page.svelte @@ -2,26 +2,29 @@ import { goto } from '$app/navigation'; import { screenWidth } from '$lib/store'; import { abbreviateNumber} from '$lib/utils'; - - import InfiniteLoading from '$lib/components/InfiniteLoading.svelte'; + import { onMount } from 'svelte'; + export let data; let rawData = data?.getDowJonesConstituentStocks; let marketCapList = rawData?.slice(0,50); - async function infiniteHandler({ detail: { loaded, complete } }) - { - - if (marketCapList?.length === rawData?.length) { - complete(); - } - else { - const nextIndex = marketCapList?.length; - const newElements= rawData?.slice(nextIndex, nextIndex + 5); - marketCapList = [...marketCapList, ...newElements]; - 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 && marketCapList?.length !== rawData?.length) { + const nextIndex = marketCapList?.length; + const filteredNewResults = rawData?.slice(nextIndex, nextIndex + 50); + marketCapList = [...marketCapList, ...filteredNewResults]; } - } + } + + onMount(async () => { + window.addEventListener('scroll', handleScroll); + return () => { + window.removeEventListener('scroll', handleScroll); + }; + }) let totalMarketCap = rawData?.reduce((total, stock) => total + stock?.marketCap, 0); let totalRevenue = rawData?.reduce((total, stock) => total + stock?.revenue, 0); @@ -39,137 +42,124 @@ } } - -
- - - -
- - A list of the {rawData?.length} stocks in the Dow Jones Industrial Average stock index, which is an index of 30 major companies listed on stock exchanges in the U.S. -
- - -
- -
-
Total Stocks
-
{rawData?.length}
-
- -
-
Total Market Cap
-
{abbreviateNumber(totalMarketCap,true)}
-
- -
-
Total Revenue
-
{abbreviateNumber(totalRevenue,true)}
-
- -
-
Total Profits
-
{abbreviateNumber(totalProfits,true)}
-
- -
- - - - -
- +
+ + +
+ + A list of the 30 stocks in the Dow Jones Industrial Average stock index, which is an index of 30 major companies listed on stock exchanges in the U.S. +
+ + +
+ +
+
Total Stocks
+
{rawData?.length}
+
+ +
+
Total Market Cap
+
{abbreviateNumber(totalMarketCap,true)}
+
+ +
+
Total Revenue
+
{abbreviateNumber(totalRevenue,true)}
+
+ +
+
Total Profits
+
{abbreviateNumber(totalProfits,true)}
+
+ +
+ + + + +
+ + + + +
+ + + + + + + + + + + + + + + + {#each marketCapList as item} + + goto("/stocks/"+item?.symbol)} class="sm:hover:bg-[#245073] sm:hover:bg-opacity-[0.2] odd:bg-[#27272A] border-b-[#09090B] shake-ticker cursor-pointer"> + + + + + + + + + + + + + + + +
SymbolCompanyMarket CapRevenueProfitsPrice
+ {item?.symbol} + + {item?.name?.length > charNumber ? item?.name?.slice(0,charNumber) + "..." : item?.name} + + {abbreviateNumber(item?.marketCap,true)} + + {item?.revenue !== null ? abbreviateNumber(item?.revenue,true) : '-'} + + {item?.netIncome !== null ? abbreviateNumber(item?.netIncome,true) : '-'} + +
- -
- - - - - - - - - - - - - - - - {#each marketCapList as item,index} - - goto("/stocks/"+item?.symbol)} class="sm:hover:bg-[#245073] sm:hover:bg-opacity-[0.2] odd:bg-[#27272A] border-b-[#09090B] shake-ticker cursor-pointer"> - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + - {/each} - -
CompanyMarket CapPrice
- -
-
- {item?.symbol} - {item?.name?.length > charNumber ? item?.name?.slice(0,charNumber) + "..." : item?.name} +
+ ${item.price?.toFixed(2)} +
+ {#if item.changesPercentage >=0} + + +{item.changesPercentage?.toFixed(2)}% + {:else} + + {item.changesPercentage?.toFixed(2)}% + {/if}
-
- {abbreviateNumber(item?.marketCap,true)} - -
- -
- ${item.price?.toFixed(2)} -
- {#if item.changesPercentage >=0} - - +{item.changesPercentage?.toFixed(2)}% - {:else} - - {item.changesPercentage?.toFixed(2)}% - {/if} -
-
- - -
-
- - - + + {/each} +
-
+ +
- -
- - - - \ No newline at end of file + +
\ No newline at end of file diff --git a/src/routes/list/dow-jones-stocks/+page.ts b/src/routes/list/dow-jones-stocks/+page.ts index a4c7d429..29c9654a 100644 --- a/src/routes/list/dow-jones-stocks/+page.ts +++ b/src/routes/list/dow-jones-stocks/+page.ts @@ -1,23 +1,8 @@ -import { userRegion, getCache, setCache } from '$lib/store'; +import { getCache, setCache } from '$lib/store'; -const usRegion = ['cle1','iad1','pdx1','sfo1']; -let apiURL; -let apiKey = import.meta.env.VITE_STOCKNEAR_API_KEY; - - -userRegion.subscribe(value => { - - if (usRegion.includes(value)) { - apiURL = import.meta.env.VITE_USEAST_API_URL; - } else { - apiURL = import.meta.env.VITE_EU_API_URL; - } -}); - - -export const load = async () => { +export const load = async ({parent}) => { const getDowJonesConstituentStocks = async () => { let output; @@ -27,6 +12,8 @@ export const load = async () => { output = cachedData; } else { + const {apiKey, apiURL} = await parent(); + const postData = {'filterList': 'dowjonesConstituent'} const response = await fetch(apiURL + '/exchange-constituents', { diff --git a/src/routes/list/nasdaq-100-stocks/+page.svelte b/src/routes/list/nasdaq-100-stocks/+page.svelte index 3115bc13..bcab7754 100644 --- a/src/routes/list/nasdaq-100-stocks/+page.svelte +++ b/src/routes/list/nasdaq-100-stocks/+page.svelte @@ -2,26 +2,29 @@ import { goto } from '$app/navigation'; import { screenWidth } from '$lib/store'; import { abbreviateNumber} from '$lib/utils'; - - import InfiniteLoading from '$lib/components/InfiniteLoading.svelte'; + import { onMount } from 'svelte'; + export let data; let rawData = data?.getNasdaqConstituentsStocks; let marketCapList = rawData?.slice(0,50); - async function infiniteHandler({ detail: { loaded, complete } }) - { - - if (marketCapList?.length === rawData?.length) { - complete(); - } - else { - const nextIndex = marketCapList?.length; - const newElements= rawData?.slice(nextIndex, nextIndex + 5); - marketCapList = [...marketCapList, ...newElements]; - 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 && marketCapList?.length !== rawData?.length) { + const nextIndex = marketCapList?.length; + const filteredNewResults = rawData?.slice(nextIndex, nextIndex + 50); + marketCapList = [...marketCapList, ...filteredNewResults]; } - } + } + + onMount(async () => { + window.addEventListener('scroll', handleScroll); + return () => { + window.removeEventListener('scroll', handleScroll); + }; + }) let totalMarketCap = rawData?.reduce((total, stock) => total + stock?.marketCap, 0); let totalRevenue = rawData?.reduce((total, stock) => total + stock?.revenue, 0); @@ -39,135 +42,124 @@ } } - -
- -
- - A list of the NASDAQ 100, an index comprising the top 100 non-financial firms on the Nasdaq exchange in the U.S. -
- - -
- -
-
Total Stocks
-
{rawData?.length}
-
- -
-
Total Market Cap
-
{abbreviateNumber(totalMarketCap,true)}
-
- -
-
Total Revenue
-
{abbreviateNumber(totalRevenue,true)}
-
- -
-
Total Profits
-
{abbreviateNumber(totalProfits,true)}
-
- -
- - - - -
- +
+ + +
+ + A list of the NASDAQ 100, an index comprising the top 100 non-financial firms on the Nasdaq exchange in the U.S. +
+ + +
+ +
+
Total Stocks
+
{rawData?.length}
+
+ +
+
Total Market Cap
+
{abbreviateNumber(totalMarketCap,true)}
+
+ +
+
Total Revenue
+
{abbreviateNumber(totalRevenue,true)}
+
+ +
+
Total Profits
+
{abbreviateNumber(totalProfits,true)}
+
+ +
+ + + + +
+ + + + +
+ + + + + + + + + + + + + + + + {#each marketCapList as item} + + goto("/stocks/"+item?.symbol)} class="sm:hover:bg-[#245073] sm:hover:bg-opacity-[0.2] odd:bg-[#27272A] border-b-[#09090B] shake-ticker cursor-pointer"> + + + + + + + + + + + + + + + +
SymbolCompanyMarket CapRevenueProfitsPrice
+ {item?.symbol} + + {item?.name?.length > charNumber ? item?.name?.slice(0,charNumber) + "..." : item?.name} + + {abbreviateNumber(item?.marketCap,true)} + + {item?.revenue !== null ? abbreviateNumber(item?.revenue,true) : '-'} + + {item?.netIncome !== null ? abbreviateNumber(item?.netIncome,true) : '-'} + +
- -
- - - - - - - - - - - - - - - - {#each marketCapList as item,index} - - goto("/stocks/"+item?.symbol)} class="sm:hover:bg-[#245073] sm:hover:bg-opacity-[0.2] odd:bg-[#27272A] border-b-[#09090B] shake-ticker cursor-pointer"> - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + - {/each} - -
CompanyMarket CapPrice
- -
-
- {item?.symbol} - {item?.name?.length > charNumber ? item?.name?.slice(0,charNumber) + "..." : item?.name} +
+ ${item.price?.toFixed(2)} +
+ {#if item.changesPercentage >=0} + + +{item.changesPercentage?.toFixed(2)}% + {:else} + + {item.changesPercentage?.toFixed(2)}% + {/if}
-
- {abbreviateNumber(item?.marketCap,true)} - -
- -
- ${item.price?.toFixed(2)} -
- {#if item.changesPercentage >=0} - - +{item.changesPercentage?.toFixed(2)}% - {:else} - - {item.changesPercentage?.toFixed(2)}% - {/if} -
-
- - -
-
- - - + + {/each} +
-
+ +
- -
- - - - \ No newline at end of file + +
\ No newline at end of file diff --git a/src/routes/list/nasdaq-100-stocks/+page.ts b/src/routes/list/nasdaq-100-stocks/+page.ts index 3f35f5de..63a79d9b 100644 --- a/src/routes/list/nasdaq-100-stocks/+page.ts +++ b/src/routes/list/nasdaq-100-stocks/+page.ts @@ -1,23 +1,7 @@ -import { userRegion, getCache, setCache } from '$lib/store'; +import { getCache, setCache } from '$lib/store'; -const usRegion = ['cle1','iad1','pdx1','sfo1']; - -let apiURL; -let apiKey = import.meta.env.VITE_STOCKNEAR_API_KEY; - - -userRegion.subscribe(value => { - - if (usRegion.includes(value)) { - apiURL = import.meta.env.VITE_USEAST_API_URL; - } else { - apiURL = import.meta.env.VITE_EU_API_URL; - } -}); - - -export const load = async () => { +export const load = async ({parent}) => { const getNasdaqConstituentsStocks = async () => { let output; @@ -27,6 +11,8 @@ export const load = async () => { output = cachedData; } else { + const {apiURL, apiKey} = await parent(); + const postData = {'filterList': 'nasdaqConstituent'} const response = await fetch(apiURL + '/exchange-constituents', { diff --git a/src/routes/list/nasdaq-stocks/+page.svelte b/src/routes/list/nasdaq-stocks/+page.svelte index ed5f09db..4b55321a 100644 --- a/src/routes/list/nasdaq-stocks/+page.svelte +++ b/src/routes/list/nasdaq-stocks/+page.svelte @@ -2,25 +2,29 @@ import { goto } from '$app/navigation'; import { screenWidth } from '$lib/store'; import { abbreviateNumber} from '$lib/utils'; -import InfiniteLoading from '$lib/components/InfiniteLoading.svelte'; +import { onMount } from 'svelte'; + export let data; let rawData = data?.getNasdaqStocks; let marketCapList = rawData?.slice(0,50); -async function infiniteHandler({ detail: { loaded, complete } }) -{ - -if (marketCapList?.length === rawData?.length) { - complete(); - } - else { - const nextIndex = marketCapList?.length; - const newElements= rawData?.slice(nextIndex, nextIndex + 5); - marketCapList = [...marketCapList, ...newElements]; - 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 && marketCapList?.length !== rawData?.length) { + const nextIndex = marketCapList?.length; + const filteredNewResults = rawData?.slice(nextIndex, nextIndex + 50); + marketCapList = [...marketCapList, ...filteredNewResults]; } -} + } + + onMount(async () => { + window.addEventListener('scroll', handleScroll); + return () => { + window.removeEventListener('scroll', handleScroll); + }; + }) let totalMarketCap = rawData?.reduce((total, stock) => total + stock?.marketCap, 0); let totalRevenue = rawData?.reduce((total, stock) => total + stock?.revenue, 0); @@ -38,137 +42,124 @@ $: { } } - -
- - - -
- - A list of all the stocks that are currently listed on the NASDAQ stock exchange in the United States. -
- - -
- -
-
Total Stocks
-
{rawData?.length}
-
- -
-
Total Market Cap
-
{abbreviateNumber(totalMarketCap,true)}
-
- -
-
Total Revenue
-
{abbreviateNumber(totalRevenue,true)}
-
- -
-
Total Profits
-
{abbreviateNumber(totalProfits,true)}
-
- -
- - - - -
- +
+ + +
+ + A list of all the stocks that are currently listed on the NASDAQ stock exchange in the United States. +
+ + +
+ +
+
Total Stocks
+
{rawData?.length}
+
+ +
+
Total Market Cap
+
{abbreviateNumber(totalMarketCap,true)}
+
+ +
+
Total Revenue
+
{abbreviateNumber(totalRevenue,true)}
+
+ +
+
Total Profits
+
{abbreviateNumber(totalProfits,true)}
+
+ +
+ + + + +
+ + + + +
+ + + + + + + + + + + + + + + + {#each marketCapList as item} + + goto("/stocks/"+item?.symbol)} class="sm:hover:bg-[#245073] sm:hover:bg-opacity-[0.2] odd:bg-[#27272A] border-b-[#09090B] shake-ticker cursor-pointer"> + + + + + + + + + + + + + + + +
SymbolCompanyMarket CapRevenueProfitsPrice
+ {item?.symbol} + + {item?.name?.length > charNumber ? item?.name?.slice(0,charNumber) + "..." : item?.name} + + {abbreviateNumber(item?.marketCap,true)} + + {item?.revenue !== null ? abbreviateNumber(item?.revenue,true) : '-'} + + {item?.netIncome !== null ? abbreviateNumber(item?.netIncome,true) : '-'} + +
- -
- - - - - - - - - - - - - - - - {#each marketCapList as item,index} - - goto("/stocks/"+item?.symbol)} class="sm:hover:bg-[#245073] sm:hover:bg-opacity-[0.2] odd:bg-[#27272A] border-b-[#09090B] shake-ticker cursor-pointer"> - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + - {/each} - -
CompanyMarket CapPrice
- -
-
- {item?.symbol} - {item?.name?.length > charNumber ? item?.name?.slice(0,charNumber) + "..." : item?.name} +
+ ${item.price?.toFixed(2)} +
+ {#if item.changesPercentage >=0} + + +{item.changesPercentage?.toFixed(2)}% + {:else} + + {item.changesPercentage?.toFixed(2)}% + {/if}
-
- {abbreviateNumber(item?.marketCap,true)} - -
- -
- ${item.price?.toFixed(2)} -
- {#if item.changesPercentage >=0} - - +{item.changesPercentage?.toFixed(2)}% - {:else} - - {item.changesPercentage?.toFixed(2)}% - {/if} -
-
- - -
-
- - - + + {/each} +
-
+ +
- -
- - - - \ No newline at end of file + +
\ No newline at end of file diff --git a/src/routes/list/nasdaq-stocks/+page.ts b/src/routes/list/nasdaq-stocks/+page.ts index 573e064d..ec7d3db9 100644 --- a/src/routes/list/nasdaq-stocks/+page.ts +++ b/src/routes/list/nasdaq-stocks/+page.ts @@ -1,24 +1,9 @@ -import { userRegion, getCache, setCache } from '$lib/store'; - - -const usRegion = ['cle1','iad1','pdx1','sfo1']; - -let apiURL; -let apiKey = import.meta.env.VITE_STOCKNEAR_API_KEY; - - -userRegion.subscribe(value => { - - if (usRegion.includes(value)) { - apiURL = import.meta.env.VITE_USEAST_API_URL; - } else { - apiURL = import.meta.env.VITE_EU_API_URL; - } -}); +import { getCache, setCache } from '$lib/store'; -export const load = async () => { + +export const load = async ({parent}) => { const getNasdaqStocks = async () => { let output; @@ -28,6 +13,8 @@ export const load = async () => { output = cachedData; } else { + const { apiKey, apiURL } = await parent(); + const postData = {'filterList': 'nasdaq'} const response = await fetch(apiURL + '/filter-stock-list', { diff --git a/src/routes/list/nyse-stocks/+page.svelte b/src/routes/list/nyse-stocks/+page.svelte index 4b7ab36c..205442a7 100644 --- a/src/routes/list/nyse-stocks/+page.svelte +++ b/src/routes/list/nyse-stocks/+page.svelte @@ -2,26 +2,29 @@ import { goto } from '$app/navigation'; import { screenWidth } from '$lib/store'; import { abbreviateNumber} from '$lib/utils'; - - import InfiniteLoading from '$lib/components/InfiniteLoading.svelte'; + import { onMount } from 'svelte'; + export let data; let rawData = data?.getNyseStocks; let marketCapList = rawData?.slice(0,50); - async function infiniteHandler({ detail: { loaded, complete } }) - { - - if (marketCapList?.length === rawData?.length) { - complete(); - } - else { - const nextIndex = marketCapList?.length; - const newElements= rawData?.slice(nextIndex, nextIndex + 5); - marketCapList = [...marketCapList, ...newElements]; - 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 && marketCapList?.length !== rawData?.length) { + const nextIndex = marketCapList?.length; + const filteredNewResults = rawData?.slice(nextIndex, nextIndex + 50); + marketCapList = [...marketCapList, ...filteredNewResults]; } - } + } + + onMount(async () => { + window.addEventListener('scroll', handleScroll); + return () => { + window.removeEventListener('scroll', handleScroll); + }; + }) let totalMarketCap = rawData?.reduce((total, stock) => total + stock?.marketCap, 0); let totalRevenue = rawData?.reduce((total, stock) => total + stock?.revenue, 0); @@ -39,137 +42,124 @@ } } - -
- - - -
- - All of the stocks listed on the NYSE (New York Stock Exchange) in the US. -
- - -
- -
-
Total Stocks
-
{rawData?.length}
-
- -
-
Total Market Cap
-
{abbreviateNumber(totalMarketCap,true)}
-
- -
-
Total Revenue
-
{abbreviateNumber(totalRevenue,true)}
-
- -
-
Total Profits
-
{abbreviateNumber(totalProfits,true)}
-
- -
- - - - -
- +
+ + +
+ + All of the stocks listed on the NYSE (New York Stock Exchange) in the US. +
+ + +
+ +
+
Total Stocks
+
{rawData?.length}
+
+ +
+
Total Market Cap
+
{abbreviateNumber(totalMarketCap,true)}
+
+ +
+
Total Revenue
+
{abbreviateNumber(totalRevenue,true)}
+
+ +
+
Total Profits
+
{abbreviateNumber(totalProfits,true)}
+
+ +
+ + + + +
+ + + + +
+ + + + + + + + + + + + + + + + {#each marketCapList as item} + + goto("/stocks/"+item?.symbol)} class="sm:hover:bg-[#245073] sm:hover:bg-opacity-[0.2] odd:bg-[#27272A] border-b-[#09090B] shake-ticker cursor-pointer"> + + + + + + + + + + + + + + + +
SymbolCompanyMarket CapRevenueProfitsPrice
+ {item?.symbol} + + {item?.name?.length > charNumber ? item?.name?.slice(0,charNumber) + "..." : item?.name} + + {abbreviateNumber(item?.marketCap,true)} + + {item?.revenue !== null ? abbreviateNumber(item?.revenue,true) : '-'} + + {item?.netIncome !== null ? abbreviateNumber(item?.netIncome,true) : '-'} + +
- -
- - - - - - - - - - - - - - - - {#each marketCapList as item,index} - - goto("/stocks/"+item?.symbol)} class="sm:hover:bg-[#245073] sm:hover:bg-opacity-[0.2] odd:bg-[#27272A] border-b-[#09090B] shake-ticker cursor-pointer"> - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + - {/each} - -
CompanyMarket CapPrice
- -
-
- {item?.symbol} - {item?.name?.length > charNumber ? item?.name?.slice(0,charNumber) + "..." : item?.name} +
+ ${item.price?.toFixed(2)} +
+ {#if item.changesPercentage >=0} + + +{item.changesPercentage?.toFixed(2)}% + {:else} + + {item.changesPercentage?.toFixed(2)}% + {/if}
-
- {abbreviateNumber(item?.marketCap,true)} - -
- -
- ${item.price?.toFixed(2)} -
- {#if item.changesPercentage >=0} - - +{item.changesPercentage?.toFixed(2)}% - {:else} - - {item.changesPercentage?.toFixed(2)}% - {/if} -
-
- - -
-
- - - + + {/each} +
-
+ +
- -
- - - - \ No newline at end of file + +
\ No newline at end of file diff --git a/src/routes/list/nyse-stocks/+page.ts b/src/routes/list/nyse-stocks/+page.ts index b250e093..520b2c83 100644 --- a/src/routes/list/nyse-stocks/+page.ts +++ b/src/routes/list/nyse-stocks/+page.ts @@ -1,24 +1,9 @@ -import { userRegion, getCache, setCache } from '$lib/store'; - - -const usRegion = ['cle1','iad1','pdx1','sfo1']; - -let apiURL; -let apiKey = import.meta.env.VITE_STOCKNEAR_API_KEY; - - -userRegion.subscribe(value => { - - if (usRegion.includes(value)) { - apiURL = import.meta.env.VITE_USEAST_API_URL; - } else { - apiURL = import.meta.env.VITE_EU_API_URL; - } -}); +import { getCache, setCache } from '$lib/store'; -export const load = async () => { + +export const load = async ({parent}) => { const getNyseStocks = async () => { let output; @@ -28,6 +13,8 @@ export const load = async () => { output = cachedData; } else { + const { apiURL, apiKey} = await parent(); + const postData = {'filterList': 'nyse'} const response = await fetch(apiURL + '/filter-stock-list', { diff --git a/src/routes/list/sp-500-stocks/+page.svelte b/src/routes/list/sp-500-stocks/+page.svelte index 9e167f08..a757e020 100644 --- a/src/routes/list/sp-500-stocks/+page.svelte +++ b/src/routes/list/sp-500-stocks/+page.svelte @@ -2,26 +2,29 @@ import { goto } from '$app/navigation'; import { screenWidth } from '$lib/store'; import { abbreviateNumber} from '$lib/utils'; - - import InfiniteLoading from '$lib/components/InfiniteLoading.svelte'; + import { onMount } from 'svelte'; + export let data; let rawData = data?.getSPConstituentsStocks; let marketCapList = rawData?.slice(0,50); - async function infiniteHandler({ detail: { loaded, complete } }) - { - - if (marketCapList?.length === rawData?.length) { - complete(); - } - else { - const nextIndex = marketCapList?.length; - const newElements= rawData?.slice(nextIndex, nextIndex + 5); - marketCapList = [...marketCapList, ...newElements]; - 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 && marketCapList?.length !== rawData?.length) { + const nextIndex = marketCapList?.length; + const filteredNewResults = rawData?.slice(nextIndex, nextIndex + 50); + marketCapList = [...marketCapList, ...filteredNewResults]; } - } + } + + onMount(async () => { + window.addEventListener('scroll', handleScroll); + return () => { + window.removeEventListener('scroll', handleScroll); + }; + }) let totalMarketCap = rawData?.reduce((total, stock) => total + stock?.marketCap, 0); let totalRevenue = rawData?.reduce((total, stock) => total + stock?.revenue, 0); @@ -39,137 +42,124 @@ } } - -
- - - -
- - A list of all the stocks in the S&P 500 stock index, which is an index of the top 500 biggest companies listed on stock exchanges in the United States. -
- - -
- -
-
Total Stocks
-
{rawData?.length}
-
- -
-
Total Market Cap
-
{abbreviateNumber(totalMarketCap,true)}
-
- -
-
Total Revenue
-
{abbreviateNumber(totalRevenue,true)}
-
- -
-
Total Profits
-
{abbreviateNumber(totalProfits,true)}
-
- -
- - - - -
- +
+ + +
+ + A list of all the stocks in the S&P 500 stock index, which is an index of the top 500 biggest companies listed on stock exchanges in the United States. +
+ + +
+ +
+
Total Stocks
+
{rawData?.length}
+
+ +
+
Total Market Cap
+
{abbreviateNumber(totalMarketCap,true)}
+
+ +
+
Total Revenue
+
{abbreviateNumber(totalRevenue,true)}
+
+ +
+
Total Profits
+
{abbreviateNumber(totalProfits,true)}
+
+ +
+ + + + +
+ + + + +
+ + + + + + + + + + + + + + + + {#each marketCapList as item} + + goto("/stocks/"+item?.symbol)} class="sm:hover:bg-[#245073] sm:hover:bg-opacity-[0.2] odd:bg-[#27272A] border-b-[#09090B] shake-ticker cursor-pointer"> + + + + + + + + + + + + + + + +
SymbolCompanyMarket CapRevenueProfitsPrice
+ {item?.symbol} + + {item?.name?.length > charNumber ? item?.name?.slice(0,charNumber) + "..." : item?.name} + + {abbreviateNumber(item?.marketCap,true)} + + {item?.revenue !== null ? abbreviateNumber(item?.revenue,true) : '-'} + + {item?.netIncome !== null ? abbreviateNumber(item?.netIncome,true) : '-'} + +
- -
- - - - - - - - - - - - - - - - {#each marketCapList as item,index} - - goto("/stocks/"+item?.symbol)} class="sm:hover:bg-[#245073] sm:hover:bg-opacity-[0.2] odd:bg-[#27272A] border-b-[#09090B] shake-ticker cursor-pointer"> - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + - {/each} - -
CompanyMarket CapPrice
- -
-
- {item?.symbol} - {item?.name?.length > charNumber ? item?.name?.slice(0,charNumber) + "..." : item?.name} +
+ ${item.price?.toFixed(2)} +
+ {#if item.changesPercentage >=0} + + +{item.changesPercentage?.toFixed(2)}% + {:else} + + {item.changesPercentage?.toFixed(2)}% + {/if}
-
- {abbreviateNumber(item?.marketCap,true)} - -
- -
- ${item.price?.toFixed(2)} -
- {#if item.changesPercentage >=0} - - +{item.changesPercentage?.toFixed(2)}% - {:else} - - {item.changesPercentage?.toFixed(2)}% - {/if} -
-
- - -
-
- - - + + {/each} +
-
+ +
- -
- - - - \ No newline at end of file + +
\ No newline at end of file diff --git a/src/routes/list/sp-500-stocks/+page.ts b/src/routes/list/sp-500-stocks/+page.ts index 9080e9f1..0f1705c3 100644 --- a/src/routes/list/sp-500-stocks/+page.ts +++ b/src/routes/list/sp-500-stocks/+page.ts @@ -1,23 +1,10 @@ -import { userRegion, getCache, setCache } from '$lib/store'; +import { getCache, setCache } from '$lib/store'; -const usRegion = ['cle1','iad1','pdx1','sfo1']; - -let apiURL; -let apiKey = import.meta.env.VITE_STOCKNEAR_API_KEY; -userRegion.subscribe(value => { - if (usRegion.includes(value)) { - apiURL = import.meta.env.VITE_USEAST_API_URL; - } else { - apiURL = import.meta.env.VITE_EU_API_URL; - } -}); - - -export const load = async () => { +export const load = async ({parent}) => { const getSPConstituentsStocks = async () => { let output; @@ -27,6 +14,8 @@ export const load = async () => { output = cachedData; } else { + const {apiURL, apiKey} = await parent(); + const postData = {'filterList': 'sp500Constituent'} const response = await fetch(apiURL + '/exchange-constituents', { diff --git a/src/routes/list/xetra-stocks/+page.svelte b/src/routes/list/xetra-stocks/+page.svelte index 10f3eae6..3b2f67e5 100644 --- a/src/routes/list/xetra-stocks/+page.svelte +++ b/src/routes/list/xetra-stocks/+page.svelte @@ -2,25 +2,29 @@ import { goto } from '$app/navigation'; import { screenWidth } from '$lib/store'; import { abbreviateNumber} from '$lib/utils'; - import InfiniteLoading from '$lib/components/InfiniteLoading.svelte'; + import { onMount } from 'svelte'; + export let data; let rawData = data?.getXetraStocks; let marketCapList = rawData?.slice(0,50); - async function infiniteHandler({ detail: { loaded, complete } }) - { - - if (marketCapList?.length === rawData?.length) { - complete(); - } - else { - const nextIndex = marketCapList?.length; - const newElements= rawData?.slice(nextIndex, nextIndex + 5); - marketCapList = [...marketCapList, ...newElements]; - 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 && marketCapList?.length !== rawData?.length) { + const nextIndex = marketCapList?.length; + const filteredNewResults = rawData?.slice(nextIndex, nextIndex + 50); + marketCapList = [...marketCapList, ...filteredNewResults]; } - } + } + + onMount(async () => { + window.addEventListener('scroll', handleScroll); + return () => { + window.removeEventListener('scroll', handleScroll); + }; + }) let totalMarketCap = rawData?.reduce((total, stock) => total + stock?.marketCap, 0); let totalRevenue = rawData?.reduce((total, stock) => total + stock?.revenue, 0); @@ -38,137 +42,124 @@ } } - -
- - - -
- - All of the stocks listed on the XETRA (German Electronic Exchange) in Europe. -
- - -
- -
-
Total Stocks
-
{rawData?.length}
-
- -
-
Total Market Cap
-
{abbreviateNumber(totalMarketCap,true)}
-
- -
-
Total Revenue
-
{abbreviateNumber(totalRevenue,true)}
-
- -
-
Total Profits
-
{abbreviateNumber(totalProfits,true)}
-
- -
- - - - -
- +
+ + +
+ + All of the stocks listed on the XETRA (German Electronic Exchange) in Europe. +
+ + +
+ +
+
Total Stocks
+
{rawData?.length}
+
+ +
+
Total Market Cap
+
{abbreviateNumber(totalMarketCap,true)}
+
+ +
+
Total Revenue
+
{abbreviateNumber(totalRevenue,true)}
+
+ +
+
Total Profits
+
{abbreviateNumber(totalProfits,true)}
+
+ +
+ + + + +
+ + + + +
+ + + + + + + + + + + + + + + + {#each marketCapList as item} + + goto("/stocks/"+item?.symbol)} class="sm:hover:bg-[#245073] sm:hover:bg-opacity-[0.2] odd:bg-[#27272A] border-b-[#09090B] shake-ticker cursor-pointer"> + + + + + + + + + + + + + + + +
SymbolCompanyMarket CapRevenueProfitsPrice
+ {item?.symbol} + + {item?.name?.length > charNumber ? item?.name?.slice(0,charNumber) + "..." : item?.name} + + {abbreviateNumber(item?.marketCap,true)} + + {item?.revenue !== null ? abbreviateNumber(item?.revenue,true) : '-'} + + {item?.netIncome !== null ? abbreviateNumber(item?.netIncome,true) : '-'} + +
- -
- - - - - - - - - - - - - - - - {#each marketCapList as item,index} - - goto("/stocks/"+item?.symbol)} class="sm:hover:bg-[#245073] sm:hover:bg-opacity-[0.2] odd:bg-[#27272A] border-b-[#09090B] shake-ticker cursor-pointer"> - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + - {/each} - -
CompanyMarket CapPrice
- -
-
- {item?.symbol} - {item?.name?.length > charNumber ? item?.name?.slice(0,charNumber) + "..." : item?.name} +
+ ${item.price?.toFixed(2)} +
+ {#if item.changesPercentage >=0} + + +{item.changesPercentage?.toFixed(2)}% + {:else} + + {item.changesPercentage?.toFixed(2)}% + {/if}
-
- {abbreviateNumber(item?.marketCap,true)} - -
- -
- ${item.price?.toFixed(2)} -
- {#if item.changesPercentage >=0} - - +{item.changesPercentage?.toFixed(2)}% - {:else} - - {item.changesPercentage?.toFixed(2)}% - {/if} -
-
- - -
-
- - - + + {/each} +
-
+ +
- -
- - - - \ No newline at end of file + +
\ No newline at end of file diff --git a/src/routes/list/xetra-stocks/+page.ts b/src/routes/list/xetra-stocks/+page.ts index 39c0d29b..535f1555 100644 --- a/src/routes/list/xetra-stocks/+page.ts +++ b/src/routes/list/xetra-stocks/+page.ts @@ -1,24 +1,8 @@ -import { userRegion, getCache, setCache } from '$lib/store'; - - -const usRegion = ['cle1','iad1','pdx1','sfo1']; - -let apiURL; -let apiKey = import.meta.env.VITE_STOCKNEAR_API_KEY; - - -userRegion.subscribe(value => { - - if (usRegion.includes(value)) { - apiURL = import.meta.env.VITE_USEAST_API_URL; - } else { - apiURL = import.meta.env.VITE_EU_API_URL; - } -}); +import {getCache, setCache } from '$lib/store'; -export const load = async () => { +export const load = async ({parent}) => { const getXetraStocks = async () => { let output; @@ -28,6 +12,8 @@ export const load = async () => { output = cachedData; } else { + const { apiKey, apiURL} = await parent(); + const postData = {'filterList': 'xetra'} const response = await fetch(apiURL + '/filter-stock-list', {