refactor code
This commit is contained in:
parent
809ec0cb27
commit
fc8e4ec0b8
@ -402,7 +402,7 @@ const handleTwitchMessage = (event) => {
|
|||||||
class="w-full bg-[#141417] hover:bg-[#141417]"
|
class="w-full bg-[#141417] hover:bg-[#141417]"
|
||||||
>
|
>
|
||||||
<a
|
<a
|
||||||
href="/market-mover"
|
href="/market-mover/gainers"
|
||||||
class="text-start w-full text-[1rem] text-white ml-4 mt-4"
|
class="text-start w-full text-[1rem] text-white ml-4 mt-4"
|
||||||
>Market Mover</a
|
>Market Mover</a
|
||||||
>
|
>
|
||||||
@ -988,7 +988,7 @@ const handleTwitchMessage = (event) => {
|
|||||||
>Stock Screener</a
|
>Stock Screener</a
|
||||||
>
|
>
|
||||||
<a
|
<a
|
||||||
href="/market-mover"
|
href="/market-mover/gainers"
|
||||||
class="text-[1rem] text-white ml-4 mt-4"
|
class="text-[1rem] text-white ml-4 mt-4"
|
||||||
>Market Mover</a
|
>Market Mover</a
|
||||||
>
|
>
|
||||||
|
|||||||
@ -237,7 +237,7 @@
|
|||||||
<div class="flex flex-row w-full items-center">
|
<div class="flex flex-row w-full items-center">
|
||||||
<Card.Title
|
<Card.Title
|
||||||
><a
|
><a
|
||||||
href={`/market-mover/${marketStatus === 0 ? "" : marketStatus === 1 ? "premarket" : "afterhours"}`}
|
href={`/market-mover/${marketStatus === 0 ? "gainers" : marketStatus === 1 ? "premarket" : "afterhours"}`}
|
||||||
class="text-xl sm:text-2xl tex-white font-semibold cursor-pointer sm:hover:underline sm:hover:underline-offset-4"
|
class="text-xl sm:text-2xl tex-white font-semibold cursor-pointer sm:hover:underline sm:hover:underline-offset-4"
|
||||||
>
|
>
|
||||||
{marketStatus === 0
|
{marketStatus === 0
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
export const load = async ({ locals }) => {
|
export const load = async ({ locals, params }) => {
|
||||||
const { apiURL, apiKey } = locals;
|
const { apiURL, apiKey } = locals;
|
||||||
|
|
||||||
const getMarketMover = async () => {
|
const getMarketMover = async () => {
|
||||||
@ -14,22 +14,12 @@ export const load = async ({ locals }) => {
|
|||||||
|
|
||||||
return output;
|
return output;
|
||||||
};
|
};
|
||||||
/*
|
const getParams = async () => {
|
||||||
const getMiniPlotsIndex = async () => {
|
return params.slug;
|
||||||
const response = await fetch(apiURL + "/mini-plots-index", {
|
|
||||||
method: "GET",
|
|
||||||
headers: {
|
|
||||||
"Content-Type": "application/json",
|
|
||||||
"X-API-KEY": apiKey,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
const output = await response.json();
|
|
||||||
|
|
||||||
return output;
|
|
||||||
};
|
};
|
||||||
*/
|
|
||||||
return {
|
return {
|
||||||
getMarketMover: await getMarketMover(),
|
getMarketMover: await getMarketMover(),
|
||||||
|
getParams: await getParams(),
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|||||||
@ -8,7 +8,7 @@
|
|||||||
const tabs = [
|
const tabs = [
|
||||||
{
|
{
|
||||||
title: "Gainers",
|
title: "Gainers",
|
||||||
path: "/market-mover",
|
path: "/market-mover/gainers",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: "Losers",
|
title: "Losers",
|
||||||
@ -31,7 +31,7 @@
|
|||||||
let activeIdx = 0;
|
let activeIdx = 0;
|
||||||
|
|
||||||
// Subscribe to the $page store to reactively update the activeIdx based on the URL
|
// Subscribe to the $page store to reactively update the activeIdx based on the URL
|
||||||
$: if ($page.url.pathname === "/market-mover") {
|
$: if ($page.url.pathname === "/market-mover/gainers") {
|
||||||
activeIdx = 0;
|
activeIdx = 0;
|
||||||
} else if ($page.url.pathname.startsWith("/market-mover/losers")) {
|
} else if ($page.url.pathname.startsWith("/market-mover/losers")) {
|
||||||
activeIdx = 1;
|
activeIdx = 1;
|
||||||
|
|||||||
@ -1,319 +1,328 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { screenWidth, numberOfUnreadNotification } from "$lib/store";
|
import { screenWidth, numberOfUnreadNotification } from "$lib/store";
|
||||||
import { abbreviateNumber, getLastTradingDay } from "$lib/utils";
|
import { abbreviateNumber, getLastTradingDay } from "$lib/utils";
|
||||||
import TableHeader from "$lib/components/Table/TableHeader.svelte";
|
import TableHeader from "$lib/components/Table/TableHeader.svelte";
|
||||||
|
import { afterUpdate } from "svelte";
|
||||||
export let data;
|
export let data;
|
||||||
let isLoaded = false;
|
let timePeriod = "1D";
|
||||||
let timePeriod = "1D";
|
const lastTradingDay = new Date(getLastTradingDay() ?? null)?.toLocaleString(
|
||||||
|
"en-US",
|
||||||
const lastTradingDay = new Date(getLastTradingDay() ?? null)?.toLocaleString(
|
{
|
||||||
"en-US",
|
month: "short",
|
||||||
{
|
day: "numeric",
|
||||||
month: "short",
|
year: "numeric",
|
||||||
day: "numeric",
|
},
|
||||||
year: "numeric",
|
);
|
||||||
},
|
const displayTitle = {
|
||||||
);
|
"1D": "title Today",
|
||||||
|
"1W": "Week title",
|
||||||
const displayTitle = {
|
"1M": "Month title",
|
||||||
"1D": "Gainers Today",
|
"1Y": "1 Year title",
|
||||||
"1W": "Week Gainers",
|
"3Y": "3 Year title",
|
||||||
"1M": "Month Gainers",
|
"5Y": "5 Year title",
|
||||||
"1Y": "1 Year Gainers",
|
};
|
||||||
"3Y": "3 Year Gainers",
|
let rawData = data?.getMarketMover[data?.getParams];
|
||||||
"5Y": "5 Year Gainers",
|
let stockList = rawData[timePeriod];
|
||||||
};
|
|
||||||
|
function selectTimeInterval(state) {
|
||||||
let rawData = data?.getMarketMover?.gainers;
|
timePeriod = state;
|
||||||
let stockList = rawData[timePeriod];
|
stockList = rawData[timePeriod];
|
||||||
|
}
|
||||||
function selectTimeInterval(state) {
|
|
||||||
timePeriod = state;
|
let columns = [
|
||||||
stockList = rawData[timePeriod];
|
{ key: "rank", label: "Rank", align: "center" },
|
||||||
}
|
{ key: "symbol", label: "Symbol", align: "left" },
|
||||||
|
{ key: "name", label: "Name", align: "left" },
|
||||||
let columns = [
|
{ key: "changesPercentage", label: "% Change", align: "right" },
|
||||||
{ key: "rank", label: "Rank", align: "center" },
|
{ key: "price", label: "Price", align: "right" },
|
||||||
{ key: "symbol", label: "Symbol", align: "left" },
|
{ key: "marketCap", label: "Market Cap", align: "right" },
|
||||||
{ key: "name", label: "Name", align: "left" },
|
{ key: "volume", label: "Volume", align: "right" },
|
||||||
{ key: "changesPercentage", label: "% Change", align: "right" },
|
];
|
||||||
{ key: "price", label: "Price", align: "right" },
|
|
||||||
{ key: "marketCap", label: "Market Cap", align: "right" },
|
let sortOrders = {
|
||||||
{ key: "volume", label: "Volume", align: "right" },
|
rank: { order: "none", type: "number" },
|
||||||
];
|
symbol: { order: "none", type: "string" },
|
||||||
|
name: { order: "none", type: "string" },
|
||||||
let sortOrders = {
|
changesPercentage: { order: "none", type: "number" },
|
||||||
rank: { order: "none", type: "number" },
|
price: { order: "none", type: "number" },
|
||||||
symbol: { order: "none", type: "string" },
|
marketCap: { order: "none", type: "number" },
|
||||||
name: { order: "none", type: "string" },
|
volume: { order: "none", type: "number" },
|
||||||
changesPercentage: { order: "none", type: "number" },
|
};
|
||||||
price: { order: "none", type: "number" },
|
|
||||||
marketCap: { order: "none", type: "number" },
|
const sortData = (key) => {
|
||||||
volume: { order: "none", type: "number" },
|
// Reset all other keys to 'none' except the current key
|
||||||
};
|
for (const k in sortOrders) {
|
||||||
|
if (k !== key) {
|
||||||
const sortData = (key) => {
|
sortOrders[k].order = "none";
|
||||||
// Reset all other keys to 'none' except the current key
|
}
|
||||||
for (const k in sortOrders) {
|
}
|
||||||
if (k !== key) {
|
|
||||||
sortOrders[k].order = "none";
|
// Cycle through 'none', 'asc', 'desc' for the clicked key
|
||||||
}
|
const orderCycle = ["none", "asc", "desc"];
|
||||||
}
|
const currentOrderIndex = orderCycle.indexOf(sortOrders[key].order);
|
||||||
|
sortOrders[key].order =
|
||||||
// Cycle through 'none', 'asc', 'desc' for the clicked key
|
orderCycle[(currentOrderIndex + 1) % orderCycle.length];
|
||||||
const orderCycle = ["none", "asc", "desc"];
|
|
||||||
|
const sortOrder = sortOrders[key].order;
|
||||||
let originalData = [];
|
|
||||||
|
// Reset to original data when 'none' and stop further sorting
|
||||||
originalData = rawData[timePeriod];
|
if (sortOrder === "none") {
|
||||||
|
stockList = [...rawData[timePeriod]]; // Reset to original data (spread to avoid mutation)
|
||||||
const currentOrderIndex = orderCycle.indexOf(sortOrders[key].order);
|
return;
|
||||||
sortOrders[key].order =
|
}
|
||||||
orderCycle[(currentOrderIndex + 1) % orderCycle.length];
|
|
||||||
const sortOrder = sortOrders[key].order;
|
// Define a generic comparison function
|
||||||
|
const compareValues = (a, b) => {
|
||||||
// Reset to original data when 'none' and stop further sorting
|
const { type } = sortOrders[key];
|
||||||
if (sortOrder === "none") {
|
let valueA, valueB;
|
||||||
stockList = [...originalData]; // Reset to original data (spread to avoid mutation)
|
switch (type) {
|
||||||
return;
|
case "date":
|
||||||
}
|
valueA = new Date(a[key]);
|
||||||
|
valueB = new Date(b[key]);
|
||||||
// Define a generic comparison function
|
break;
|
||||||
const compareValues = (a, b) => {
|
case "string":
|
||||||
const { type } = sortOrders[key];
|
valueA = a[key].toUpperCase();
|
||||||
let valueA, valueB;
|
valueB = b[key].toUpperCase();
|
||||||
|
return sortOrder === "asc"
|
||||||
switch (type) {
|
? valueA.localeCompare(valueB)
|
||||||
case "date":
|
: valueB.localeCompare(valueA);
|
||||||
valueA = new Date(a[key]);
|
case "number":
|
||||||
valueB = new Date(b[key]);
|
default:
|
||||||
break;
|
valueA = parseFloat(a[key]);
|
||||||
case "string":
|
valueB = parseFloat(b[key]);
|
||||||
valueA = a[key].toUpperCase();
|
break;
|
||||||
valueB = b[key].toUpperCase();
|
}
|
||||||
return sortOrder === "asc"
|
if (sortOrder === "asc") {
|
||||||
? valueA.localeCompare(valueB)
|
return valueA < valueB ? -1 : valueA > valueB ? 1 : 0;
|
||||||
: valueB.localeCompare(valueA);
|
} else {
|
||||||
case "number":
|
return valueA > valueB ? -1 : valueA < valueB ? 1 : 0;
|
||||||
default:
|
}
|
||||||
valueA = parseFloat(a[key]);
|
};
|
||||||
valueB = parseFloat(b[key]);
|
|
||||||
break;
|
// Sort using the generic comparison function
|
||||||
}
|
stockList = [...rawData[timePeriod]].sort(compareValues);
|
||||||
|
};
|
||||||
if (sortOrder === "asc") {
|
|
||||||
return valueA < valueB ? -1 : valueA > valueB ? 1 : 0;
|
let previousTimePeriod;
|
||||||
} else {
|
let previousPage = data?.getParams;
|
||||||
return valueA > valueB ? -1 : valueA < valueB ? 1 : 0;
|
let title;
|
||||||
}
|
|
||||||
};
|
afterUpdate(() => {
|
||||||
|
if (timePeriod !== previousTimePeriod || previousPage !== data?.getParams) {
|
||||||
// Sort using the generic comparison function
|
previousTimePeriod = timePeriod;
|
||||||
stockList = [...originalData].sort(compareValues);
|
previousPage = data?.getParams;
|
||||||
};
|
rawData = data?.getMarketMover[data?.getParams];
|
||||||
$: charNumber = $screenWidth < 640 ? 20 : 30;
|
stockList = rawData[timePeriod];
|
||||||
</script>
|
title =
|
||||||
|
data?.getParams?.charAt(0)?.toUpperCase() + data?.getParams?.slice(1);
|
||||||
<svelte:head>
|
}
|
||||||
<meta charset="utf-8" />
|
});
|
||||||
<meta name="viewport" content="width=device-width" />
|
|
||||||
<title>
|
$: charNumber = $screenWidth < 640 ? 20 : 30;
|
||||||
{$numberOfUnreadNotification > 0 ? `(${$numberOfUnreadNotification})` : ""} Today's
|
</script>
|
||||||
Top Stock Gainers · stocknear
|
|
||||||
</title>
|
<svelte:head>
|
||||||
<meta
|
<meta charset="utf-8" />
|
||||||
name="description"
|
<meta name="viewport" content="width=device-width" />
|
||||||
content={`A list of the stocks with the highest percentage gain, highest percentage loss and most active today. See stock price, volume, market cap and more.`}
|
<title>
|
||||||
/>
|
{$numberOfUnreadNotification > 0 ? `(${$numberOfUnreadNotification})` : ""} Today's
|
||||||
|
Top Stock {title} · stocknear
|
||||||
<!-- Other meta tags -->
|
</title>
|
||||||
<meta property="og:title" content={`Today's Top Stock Gainers · stocknear`} />
|
<meta
|
||||||
<meta
|
name="description"
|
||||||
property="og:description"
|
content={`A list of the stocks with the highest percentage gain, highest percentage loss and most active today. See stock price, volume, market cap and more.`}
|
||||||
content={`A list of the stocks with the highest percentage gain, highest percentage loss and most active today. See stock price, volume, market cap and more.`}
|
/>
|
||||||
/>
|
|
||||||
<meta property="og:type" content="website" />
|
<!-- Other meta tags -->
|
||||||
<!-- Add more Open Graph meta tags as needed -->
|
<meta
|
||||||
|
property="og:title"
|
||||||
<!-- Twitter specific meta tags -->
|
content={`Today's Top Stock ${title} · stocknear`}
|
||||||
<meta name="twitter:card" content="summary_large_image" />
|
/>
|
||||||
<meta
|
<meta
|
||||||
name="twitter:title"
|
property="og:description"
|
||||||
content={`Today's Top Stock Gainers · stocknear`}
|
content={`A list of the stocks with the highest percentage gain, highest percentage loss and most active today. See stock price, volume, market cap and more.`}
|
||||||
/>
|
/>
|
||||||
<meta
|
<meta property="og:type" content="website" />
|
||||||
name="twitter:description"
|
<!-- Add more Open Graph meta tags as needed -->
|
||||||
content={`A list of the stocks with the highest percentage gain, highest percentage loss and most active today. See stock price, volume, market cap and more.`}
|
|
||||||
/>
|
<!-- Twitter specific meta tags -->
|
||||||
<!-- Add more Twitter meta tags as needed -->
|
<meta name="twitter:card" content="summary_large_image" />
|
||||||
</svelte:head>
|
<meta
|
||||||
|
name="twitter:title"
|
||||||
<section class="w-full overflow-hidden m-auto">
|
content={`Today's Top Stock ${title} · stocknear`}
|
||||||
<div class="flex justify-center w-full m-auto overflow-hidden">
|
/>
|
||||||
<div
|
<meta
|
||||||
class="w-full relative flex justify-center items-center overflow-hidden"
|
name="twitter:description"
|
||||||
>
|
content={`A list of the stocks with the highest percentage gain, highest percentage loss and most active today. See stock price, volume, market cap and more.`}
|
||||||
<main class="w-full">
|
/>
|
||||||
<!--Start Top Winners/Losers-->
|
<!-- Add more Twitter meta tags as needed -->
|
||||||
|
</svelte:head>
|
||||||
<nav class=" pt-1 overflow-x-scroll whitespace-nowrap">
|
|
||||||
<ul
|
<section class="w-full overflow-hidden m-auto">
|
||||||
class="flex flex-row items-center w-full text-sm sm:text-[1rem] text-white"
|
<div class="flex justify-center w-full m-auto overflow-hidden">
|
||||||
>
|
<div
|
||||||
<li
|
class="w-full relative flex justify-center items-center overflow-hidden"
|
||||||
on:click={() => selectTimeInterval("1D")}
|
>
|
||||||
class="p-2 px-5 cursor-pointer {timePeriod === '1D'
|
<main class="w-full">
|
||||||
? 'text-white bg-[#27272A] sm:hover:bg-opacity-[0.95]'
|
<!--Start Top Winners/Losers-->
|
||||||
: 'text-gray-400 sm:hover:text-white sm:hover:bg-[#27272A] sm:hover:bg-opacity-[0.95]'}"
|
|
||||||
>
|
<nav class=" pt-1 overflow-x-scroll whitespace-nowrap">
|
||||||
Today
|
<ul
|
||||||
</li>
|
class="flex flex-row items-center w-full text-sm sm:text-[1rem] text-white"
|
||||||
<li
|
>
|
||||||
on:click={() => selectTimeInterval("1W")}
|
<li
|
||||||
class="p-2 px-5 cursor-pointer {timePeriod === '1W'
|
on:click={() => selectTimeInterval("1D")}
|
||||||
? 'text-white bg-[#27272A] sm:hover:bg-opacity-[0.95]'
|
class="p-2 px-5 cursor-pointer {timePeriod === '1D'
|
||||||
: 'text-gray-400 sm:hover:text-white sm:hover:bg-[#27272A] sm:hover:bg-opacity-[0.95]'}"
|
? 'text-white bg-[#27272A] sm:hover:bg-opacity-[0.95]'
|
||||||
>
|
: 'text-gray-400 sm:hover:text-white sm:hover:bg-[#27272A] sm:hover:bg-opacity-[0.95]'}"
|
||||||
Week
|
>
|
||||||
</li>
|
Today
|
||||||
<li
|
</li>
|
||||||
on:click={() => selectTimeInterval("1M")}
|
<li
|
||||||
class="p-2 px-5 cursor-pointer {timePeriod === '1M'
|
on:click={() => selectTimeInterval("1W")}
|
||||||
? 'text-white bg-[#27272A] sm:hover:bg-opacity-[0.95]'
|
class="p-2 px-5 cursor-pointer {timePeriod === '1W'
|
||||||
: 'text-gray-400 sm:hover:text-white sm:hover:bg-[#27272A] sm:hover:bg-opacity-[0.95]'}"
|
? 'text-white bg-[#27272A] sm:hover:bg-opacity-[0.95]'
|
||||||
>
|
: 'text-gray-400 sm:hover:text-white sm:hover:bg-[#27272A] sm:hover:bg-opacity-[0.95]'}"
|
||||||
Month
|
>
|
||||||
</li>
|
Week
|
||||||
<li
|
</li>
|
||||||
on:click={() => selectTimeInterval("1Y")}
|
<li
|
||||||
class="p-2 px-5 cursor-pointer {timePeriod === '1Y'
|
on:click={() => selectTimeInterval("1M")}
|
||||||
? 'text-white bg-[#27272A] sm:hover:bg-opacity-[0.95]'
|
class="p-2 px-5 cursor-pointer {timePeriod === '1M'
|
||||||
: 'text-gray-400 sm:hover:text-white sm:hover:bg-[#27272A] sm:hover:bg-opacity-[0.95]'}"
|
? 'text-white bg-[#27272A] sm:hover:bg-opacity-[0.95]'
|
||||||
>
|
: 'text-gray-400 sm:hover:text-white sm:hover:bg-[#27272A] sm:hover:bg-opacity-[0.95]'}"
|
||||||
Year
|
>
|
||||||
</li>
|
Month
|
||||||
<li
|
</li>
|
||||||
on:click={() => selectTimeInterval("3Y")}
|
<li
|
||||||
class="p-2 px-5 cursor-pointer {timePeriod === '3Y'
|
on:click={() => selectTimeInterval("1Y")}
|
||||||
? 'text-white bg-[#27272A] sm:hover:bg-opacity-[0.95]'
|
class="p-2 px-5 cursor-pointer {timePeriod === '1Y'
|
||||||
: 'text-gray-400 sm:hover:text-white sm:hover:bg-[#27272A] sm:hover:bg-opacity-[0.95]'}"
|
? 'text-white bg-[#27272A] sm:hover:bg-opacity-[0.95]'
|
||||||
>
|
: 'text-gray-400 sm:hover:text-white sm:hover:bg-[#27272A] sm:hover:bg-opacity-[0.95]'}"
|
||||||
3 Years
|
>
|
||||||
</li>
|
Year
|
||||||
<li
|
</li>
|
||||||
on:click={() => selectTimeInterval("5Y")}
|
<li
|
||||||
class="p-2 px-5 cursor-pointer {timePeriod === '5Y'
|
on:click={() => selectTimeInterval("3Y")}
|
||||||
? 'text-white bg-[#27272A] sm:hover:bg-opacity-[0.95]'
|
class="p-2 px-5 cursor-pointer {timePeriod === '3Y'
|
||||||
: 'text-gray-400 sm:hover:text-white sm:hover:bg-[#27272A] sm:hover:bg-opacity-[0.95]'}"
|
? 'text-white bg-[#27272A] sm:hover:bg-opacity-[0.95]'
|
||||||
>
|
: 'text-gray-400 sm:hover:text-white sm:hover:bg-[#27272A] sm:hover:bg-opacity-[0.95]'}"
|
||||||
5 Years
|
>
|
||||||
</li>
|
3 Years
|
||||||
</ul>
|
</li>
|
||||||
</nav>
|
<li
|
||||||
|
on:click={() => selectTimeInterval("5Y")}
|
||||||
<div
|
class="p-2 px-5 cursor-pointer {timePeriod === '5Y'
|
||||||
class="flex flex-col justify-center items-center overflow-hidden mt-10"
|
? 'text-white bg-[#27272A] sm:hover:bg-opacity-[0.95]'
|
||||||
>
|
: 'text-gray-400 sm:hover:text-white sm:hover:bg-[#27272A] sm:hover:bg-opacity-[0.95]'}"
|
||||||
<div class="controls groups w-full">
|
>
|
||||||
<div
|
5 Years
|
||||||
class="title-group flex flex-row items-center justify-start mb-3"
|
</li>
|
||||||
>
|
</ul>
|
||||||
<h1 class="text-white text-xl sm:text-2xl font-semibold">
|
</nav>
|
||||||
{displayTitle[timePeriod]}
|
|
||||||
</h1>
|
<div
|
||||||
|
class="flex flex-col justify-center items-center overflow-hidden mt-10"
|
||||||
<div
|
>
|
||||||
class="mb-0 ml-3 mt-1 whitespace-nowrap text-sm font-semiboldt text-white"
|
<div class="controls groups w-full">
|
||||||
>
|
<div
|
||||||
<span class="hidden lg:inline">Updated</span>
|
class="title-group flex flex-row items-center justify-start mb-3"
|
||||||
{lastTradingDay}
|
>
|
||||||
</div>
|
<h1 class="text-white text-xl sm:text-2xl font-semibold">
|
||||||
</div>
|
{displayTitle[timePeriod]?.replace("title", title)}
|
||||||
</div>
|
</h1>
|
||||||
|
|
||||||
<div class="w-full overflow-x-scroll no-scrollbar">
|
<div
|
||||||
<table
|
class="mb-0 ml-3 mt-1 whitespace-nowrap text-sm font-semiboldt text-white"
|
||||||
class="table table-sm table-compact rounded-none sm:rounded-md w-full bg-[#09090B] border-bg-[#09090B]"
|
>
|
||||||
>
|
<span class="hidden lg:inline">Updated</span>
|
||||||
<thead>
|
{lastTradingDay}
|
||||||
<TableHeader {columns} {sortOrders} {sortData} />
|
</div>
|
||||||
</thead>
|
</div>
|
||||||
<tbody>
|
</div>
|
||||||
{#each stockList as item}
|
|
||||||
<tr
|
<div class="w-full overflow-x-scroll no-scrollbar">
|
||||||
class="border-b border-[#27272A] sm:hover:bg-[#245073] sm:hover:bg-opacity-[0.2] odd:bg-[#27272A]"
|
<table
|
||||||
>
|
class="table table-sm table-compact rounded-none sm:rounded-md w-full bg-[#09090B] border-bg-[#09090B]"
|
||||||
<td
|
>
|
||||||
class="text-white text-sm sm:text-[1rem] text-center border-b-[#09090B]"
|
<thead>
|
||||||
>
|
<TableHeader {columns} {sortOrders} {sortData} />
|
||||||
{item?.rank}
|
</thead>
|
||||||
</td>
|
<tbody>
|
||||||
|
{#each stockList as item}
|
||||||
<td
|
<tr
|
||||||
class="border-b-[#09090B] text-sm sm:text-[1rem] whitespace-nowrap"
|
class="border-b border-[#27272A] sm:hover:bg-[#245073] sm:hover:bg-opacity-[0.2] odd:bg-[#27272A]"
|
||||||
>
|
>
|
||||||
<a
|
<td
|
||||||
href={"/stocks/" + item?.symbol}
|
class="text-white text-sm sm:text-[1rem] text-center border-b-[#09090B]"
|
||||||
class="sm:hover:text-white text-blue-400"
|
>
|
||||||
>
|
{item?.rank}
|
||||||
{item?.symbol}
|
</td>
|
||||||
</a>
|
|
||||||
</td>
|
<td
|
||||||
<td
|
class="border-b-[#09090B] text-sm sm:text-[1rem] whitespace-nowrap"
|
||||||
class="border-b-[#09090B] text-sm sm:text-[1rem] whitespace-nowrap text-white"
|
>
|
||||||
>
|
<a
|
||||||
{item?.name?.length > charNumber
|
href={"/stocks/" + item?.symbol}
|
||||||
? item?.name?.slice(0, charNumber) + "..."
|
class="sm:hover:text-white text-blue-400"
|
||||||
: item?.name}
|
>
|
||||||
</td>
|
{item?.symbol}
|
||||||
|
</a>
|
||||||
<td
|
</td>
|
||||||
class="text-white text-end text-sm sm:text-[1rem] font-medium border-b-[#09090B]"
|
<td
|
||||||
>
|
class="border-b-[#09090B] text-sm sm:text-[1rem] whitespace-nowrap text-white"
|
||||||
{#if item?.changesPercentage >= 0}
|
>
|
||||||
<span class="text-[#00FC50]"
|
{item?.name?.length > charNumber
|
||||||
>+{item?.changesPercentage >= 1000
|
? item?.name?.slice(0, charNumber) + "..."
|
||||||
? abbreviateNumber(item?.changesPercentage)
|
: item?.name}
|
||||||
: item?.changesPercentage?.toFixed(2)}%</span
|
</td>
|
||||||
>
|
|
||||||
{:else}
|
<td
|
||||||
<span class="text-[#FF2F1F]"
|
class="text-white text-end text-sm sm:text-[1rem] font-medium border-b-[#09090B]"
|
||||||
>{item?.changesPercentage <= -1000
|
>
|
||||||
? abbreviateNumber(item?.changesPercentage)
|
{#if item?.changesPercentage >= 0}
|
||||||
: item?.changesPercentage?.toFixed(2)}%
|
<span class="text-[#00FC50]"
|
||||||
</span>
|
>+{item?.changesPercentage >= 1000
|
||||||
{/if}
|
? abbreviateNumber(item?.changesPercentage)
|
||||||
</td>
|
: item?.changesPercentage?.toFixed(2)}%</span
|
||||||
|
>
|
||||||
<td
|
{:else}
|
||||||
class="text-white text-sm sm:text-[1rem] text-end border-b-[#09090B]"
|
<span class="text-[#FF2F1F]"
|
||||||
>
|
>{item?.changesPercentage <= -1000
|
||||||
{item?.price?.toFixed(2)}
|
? abbreviateNumber(item?.changesPercentage)
|
||||||
</td>
|
: item?.changesPercentage?.toFixed(2)}%
|
||||||
|
</span>
|
||||||
<td
|
{/if}
|
||||||
class="text-white text-sm sm:text-[1rem] border-b-[#09090B] text-end"
|
</td>
|
||||||
>
|
|
||||||
{item?.marketCap !== null
|
<td
|
||||||
? abbreviateNumber(item?.marketCap)
|
class="text-white text-sm sm:text-[1rem] text-end border-b-[#09090B]"
|
||||||
: "-"}
|
>
|
||||||
</td>
|
{item?.price?.toFixed(2)}
|
||||||
|
</td>
|
||||||
<td
|
|
||||||
class="text-white text-sm sm:text-[1rem] border-b-[#09090B] text-end"
|
<td
|
||||||
>
|
class="text-white text-sm sm:text-[1rem] border-b-[#09090B] text-end"
|
||||||
{item?.volume !== null
|
>
|
||||||
? abbreviateNumber(item?.volume)
|
{item?.marketCap !== null
|
||||||
: "-"}
|
? abbreviateNumber(item?.marketCap)
|
||||||
</td>
|
: "-"}
|
||||||
</tr>
|
</td>
|
||||||
{/each}
|
|
||||||
</tbody>
|
<td
|
||||||
</table>
|
class="text-white text-sm sm:text-[1rem] border-b-[#09090B] text-end"
|
||||||
</div>
|
>
|
||||||
</div>
|
{item?.volume !== null
|
||||||
</main>
|
? abbreviateNumber(item?.volume)
|
||||||
</div>
|
: "-"}
|
||||||
</div>
|
</td>
|
||||||
</section>
|
</tr>
|
||||||
|
{/each}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</main>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
@ -1,315 +0,0 @@
|
|||||||
<script lang="ts">
|
|
||||||
import { screenWidth, numberOfUnreadNotification } from "$lib/store";
|
|
||||||
import { abbreviateNumber, getLastTradingDay } from "$lib/utils";
|
|
||||||
import TableHeader from "$lib/components/Table/TableHeader.svelte";
|
|
||||||
|
|
||||||
export let data;
|
|
||||||
let timePeriod = "1D";
|
|
||||||
|
|
||||||
const lastTradingDay = new Date(getLastTradingDay() ?? null)?.toLocaleString(
|
|
||||||
"en-US",
|
|
||||||
{
|
|
||||||
month: "short",
|
|
||||||
day: "numeric",
|
|
||||||
year: "numeric",
|
|
||||||
},
|
|
||||||
);
|
|
||||||
|
|
||||||
const displayTitle = {
|
|
||||||
"1D": "Active Today",
|
|
||||||
"1W": "Week Active",
|
|
||||||
"1M": "Month Active",
|
|
||||||
"1Y": "1 Year Active",
|
|
||||||
"3Y": "3 Year Active",
|
|
||||||
"5Y": "5 Year Active",
|
|
||||||
};
|
|
||||||
|
|
||||||
let rawData = data?.getMarketMover?.active;
|
|
||||||
let stockList = rawData[timePeriod];
|
|
||||||
|
|
||||||
function selectTimeInterval(state) {
|
|
||||||
timePeriod = state;
|
|
||||||
stockList = rawData[timePeriod];
|
|
||||||
}
|
|
||||||
|
|
||||||
let columns = [
|
|
||||||
{ key: "rank", label: "Rank", align: "center" },
|
|
||||||
{ key: "symbol", label: "Symbol", align: "left" },
|
|
||||||
{ key: "name", label: "Name", align: "left" },
|
|
||||||
{ key: "changesPercentage", label: "% Change", align: "right" },
|
|
||||||
{ key: "price", label: "Price", align: "right" },
|
|
||||||
{ key: "marketCap", label: "Market Cap", align: "right" },
|
|
||||||
{ key: "volume", label: "Volume", align: "right" },
|
|
||||||
];
|
|
||||||
|
|
||||||
let sortOrders = {
|
|
||||||
rank: { order: "none", type: "number" },
|
|
||||||
symbol: { order: "none", type: "string" },
|
|
||||||
name: { order: "none", type: "string" },
|
|
||||||
changesPercentage: { order: "none", type: "number" },
|
|
||||||
price: { order: "none", type: "number" },
|
|
||||||
marketCap: { order: "none", type: "number" },
|
|
||||||
volume: { order: "none", type: "number" },
|
|
||||||
};
|
|
||||||
|
|
||||||
const sortData = (key) => {
|
|
||||||
// Reset all other keys to 'none' except the current key
|
|
||||||
for (const k in sortOrders) {
|
|
||||||
if (k !== key) {
|
|
||||||
sortOrders[k].order = "none";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Cycle through 'none', 'asc', 'desc' for the clicked key
|
|
||||||
const orderCycle = ["none", "asc", "desc"];
|
|
||||||
|
|
||||||
let originalData = [];
|
|
||||||
|
|
||||||
originalData = rawData[timePeriod];
|
|
||||||
|
|
||||||
const currentOrderIndex = orderCycle.indexOf(sortOrders[key].order);
|
|
||||||
sortOrders[key].order =
|
|
||||||
orderCycle[(currentOrderIndex + 1) % orderCycle.length];
|
|
||||||
const sortOrder = sortOrders[key].order;
|
|
||||||
|
|
||||||
// Reset to original data when 'none' and stop further sorting
|
|
||||||
if (sortOrder === "none") {
|
|
||||||
stockList = [...originalData]; // Reset to original data (spread to avoid mutation)
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Define a generic comparison function
|
|
||||||
const compareValues = (a, b) => {
|
|
||||||
const { type } = sortOrders[key];
|
|
||||||
let valueA, valueB;
|
|
||||||
|
|
||||||
switch (type) {
|
|
||||||
case "date":
|
|
||||||
valueA = new Date(a[key]);
|
|
||||||
valueB = new Date(b[key]);
|
|
||||||
break;
|
|
||||||
case "string":
|
|
||||||
valueA = a[key].toUpperCase();
|
|
||||||
valueB = b[key].toUpperCase();
|
|
||||||
return sortOrder === "asc"
|
|
||||||
? valueA.localeCompare(valueB)
|
|
||||||
: valueB.localeCompare(valueA);
|
|
||||||
case "number":
|
|
||||||
default:
|
|
||||||
valueA = parseFloat(a[key]);
|
|
||||||
valueB = parseFloat(b[key]);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (sortOrder === "asc") {
|
|
||||||
return valueA < valueB ? -1 : valueA > valueB ? 1 : 0;
|
|
||||||
} else {
|
|
||||||
return valueA > valueB ? -1 : valueA < valueB ? 1 : 0;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
// Sort using the generic comparison function
|
|
||||||
stockList = [...originalData].sort(compareValues);
|
|
||||||
};
|
|
||||||
$: charNumber = $screenWidth < 640 ? 20 : 30;
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<svelte:head>
|
|
||||||
<meta charset="utf-8" />
|
|
||||||
<meta name="viewport" content="width=device-width" />
|
|
||||||
<title>
|
|
||||||
{$numberOfUnreadNotification > 0 ? `(${$numberOfUnreadNotification})` : ""}
|
|
||||||
Top Stock Active · stocknear
|
|
||||||
</title>
|
|
||||||
<meta
|
|
||||||
name="description"
|
|
||||||
content={`A list of the stocks with the highest percentage gain, highest percentage loss and most active today. See stock price, volume, market cap and more.`}
|
|
||||||
/>
|
|
||||||
|
|
||||||
<!-- Other meta tags -->
|
|
||||||
<meta property="og:title" content={`Today's Top Stock Active · stocknear`} />
|
|
||||||
<meta
|
|
||||||
property="og:description"
|
|
||||||
content={`A list of the stocks with the highest percentage gain, highest percentage loss and most active today. See stock price, volume, market cap and more.`}
|
|
||||||
/>
|
|
||||||
<meta property="og:type" content="website" />
|
|
||||||
<!-- Add more Open Graph meta tags as needed -->
|
|
||||||
|
|
||||||
<!-- Twitter specific meta tags -->
|
|
||||||
<meta name="twitter:card" content="summary_large_image" />
|
|
||||||
<meta name="twitter:title" content={`Today's Top Stock Active · stocknear`} />
|
|
||||||
<meta
|
|
||||||
name="twitter:description"
|
|
||||||
content={`A list of the stocks with the highest percentage gain, highest percentage loss and most active today. See stock price, volume, market cap and more.`}
|
|
||||||
/>
|
|
||||||
<!-- Add more Twitter meta tags as needed -->
|
|
||||||
</svelte:head>
|
|
||||||
|
|
||||||
<section class="w-full overflow-hidden m-auto">
|
|
||||||
<div class="flex justify-center w-full m-auto overflow-hidden">
|
|
||||||
<div
|
|
||||||
class="w-full relative flex justify-center items-center overflow-hidden"
|
|
||||||
>
|
|
||||||
<main class="w-full">
|
|
||||||
<!--Start Top Winners/Losers-->
|
|
||||||
|
|
||||||
<nav class=" pt-1 overflow-x-scroll whitespace-nowrap">
|
|
||||||
<ul
|
|
||||||
class="flex flex-row items-center w-full text-sm sm:text-[1rem] text-white"
|
|
||||||
>
|
|
||||||
<li
|
|
||||||
on:click={() => selectTimeInterval("1D")}
|
|
||||||
class="p-2 px-5 cursor-pointer {timePeriod === '1D'
|
|
||||||
? 'text-white bg-[#27272A] sm:hover:bg-opacity-[0.95]'
|
|
||||||
: 'text-gray-400 sm:hover:text-white sm:hover:bg-[#27272A] sm:hover:bg-opacity-[0.95]'}"
|
|
||||||
>
|
|
||||||
Today
|
|
||||||
</li>
|
|
||||||
<li
|
|
||||||
on:click={() => selectTimeInterval("1W")}
|
|
||||||
class="p-2 px-5 cursor-pointer {timePeriod === '1W'
|
|
||||||
? 'text-white bg-[#27272A] sm:hover:bg-opacity-[0.95]'
|
|
||||||
: 'text-gray-400 sm:hover:text-white sm:hover:bg-[#27272A] sm:hover:bg-opacity-[0.95]'}"
|
|
||||||
>
|
|
||||||
Week
|
|
||||||
</li>
|
|
||||||
<li
|
|
||||||
on:click={() => selectTimeInterval("1M")}
|
|
||||||
class="p-2 px-5 cursor-pointer {timePeriod === '1M'
|
|
||||||
? 'text-white bg-[#27272A] sm:hover:bg-opacity-[0.95]'
|
|
||||||
: 'text-gray-400 sm:hover:text-white sm:hover:bg-[#27272A] sm:hover:bg-opacity-[0.95]'}"
|
|
||||||
>
|
|
||||||
Month
|
|
||||||
</li>
|
|
||||||
<li
|
|
||||||
on:click={() => selectTimeInterval("1Y")}
|
|
||||||
class="p-2 px-5 cursor-pointer {timePeriod === '1Y'
|
|
||||||
? 'text-white bg-[#27272A] sm:hover:bg-opacity-[0.95]'
|
|
||||||
: 'text-gray-400 sm:hover:text-white sm:hover:bg-[#27272A] sm:hover:bg-opacity-[0.95]'}"
|
|
||||||
>
|
|
||||||
Year
|
|
||||||
</li>
|
|
||||||
<li
|
|
||||||
on:click={() => selectTimeInterval("3Y")}
|
|
||||||
class="p-2 px-5 cursor-pointer {timePeriod === '3Y'
|
|
||||||
? 'text-white bg-[#27272A] sm:hover:bg-opacity-[0.95]'
|
|
||||||
: 'text-gray-400 sm:hover:text-white sm:hover:bg-[#27272A] sm:hover:bg-opacity-[0.95]'}"
|
|
||||||
>
|
|
||||||
3 Years
|
|
||||||
</li>
|
|
||||||
<li
|
|
||||||
on:click={() => selectTimeInterval("5Y")}
|
|
||||||
class="p-2 px-5 cursor-pointer {timePeriod === '5Y'
|
|
||||||
? 'text-white bg-[#27272A] sm:hover:bg-opacity-[0.95]'
|
|
||||||
: 'text-gray-400 sm:hover:text-white sm:hover:bg-[#27272A] sm:hover:bg-opacity-[0.95]'}"
|
|
||||||
>
|
|
||||||
5 Years
|
|
||||||
</li>
|
|
||||||
</ul>
|
|
||||||
</nav>
|
|
||||||
|
|
||||||
<div
|
|
||||||
class="flex flex-col justify-center items-center overflow-hidden mt-10"
|
|
||||||
>
|
|
||||||
<div class="controls groups w-full">
|
|
||||||
<div
|
|
||||||
class="title-group flex flex-row items-center justify-start mb-3"
|
|
||||||
>
|
|
||||||
<h1 class="text-white text-xl sm:text-2xl font-semibold">
|
|
||||||
{displayTitle[timePeriod]}
|
|
||||||
</h1>
|
|
||||||
|
|
||||||
<div
|
|
||||||
class="mb-0 ml-3 mt-1 whitespace-nowrap text-sm font-semiboldt text-white"
|
|
||||||
>
|
|
||||||
<span class="hidden lg:inline">Updated</span>
|
|
||||||
{lastTradingDay}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="w-full overflow-x-scroll no-scrollbar">
|
|
||||||
<table
|
|
||||||
class="table table-sm table-compact rounded-none sm:rounded-md w-full bg-[#09090B] border-bg-[#09090B]"
|
|
||||||
>
|
|
||||||
<thead>
|
|
||||||
<TableHeader {columns} {sortOrders} {sortData} />
|
|
||||||
</thead>
|
|
||||||
<tbody>
|
|
||||||
{#each stockList as item}
|
|
||||||
<tr
|
|
||||||
class="border-b border-[#27272A] sm:hover:bg-[#245073] sm:hover:bg-opacity-[0.2] odd:bg-[#27272A]"
|
|
||||||
>
|
|
||||||
<td
|
|
||||||
class="text-white text-sm sm:text-[1rem] text-center border-b-[#09090B]"
|
|
||||||
>
|
|
||||||
{item?.rank}
|
|
||||||
</td>
|
|
||||||
|
|
||||||
<td
|
|
||||||
class="border-b-[#09090B] text-sm sm:text-[1rem] whitespace-nowrap"
|
|
||||||
>
|
|
||||||
<a
|
|
||||||
href={"/stocks/" + item?.symbol}
|
|
||||||
class="sm:hover:text-white text-blue-400"
|
|
||||||
>
|
|
||||||
{item?.symbol}
|
|
||||||
</a>
|
|
||||||
</td>
|
|
||||||
<td
|
|
||||||
class="border-b-[#09090B] text-sm sm:text-[1rem] whitespace-nowrap text-white"
|
|
||||||
>
|
|
||||||
{item?.name?.length > charNumber
|
|
||||||
? item?.name?.slice(0, charNumber) + "..."
|
|
||||||
: item?.name}
|
|
||||||
</td>
|
|
||||||
|
|
||||||
<td
|
|
||||||
class="text-white text-end text-sm sm:text-[1rem] font-medium border-b-[#09090B]"
|
|
||||||
>
|
|
||||||
{#if item?.changesPercentage >= 0}
|
|
||||||
<span class="text-[#00FC50]"
|
|
||||||
>+{item?.changesPercentage >= 1000
|
|
||||||
? abbreviateNumber(item?.changesPercentage)
|
|
||||||
: item?.changesPercentage?.toFixed(2)}%</span
|
|
||||||
>
|
|
||||||
{:else}
|
|
||||||
<span class="text-[#FF2F1F]"
|
|
||||||
>{item?.changesPercentage <= -1000
|
|
||||||
? abbreviateNumber(item?.changesPercentage)
|
|
||||||
: item?.changesPercentage?.toFixed(2)}%
|
|
||||||
</span>
|
|
||||||
{/if}
|
|
||||||
</td>
|
|
||||||
|
|
||||||
<td
|
|
||||||
class="text-white text-sm sm:text-[1rem] text-end border-b-[#09090B]"
|
|
||||||
>
|
|
||||||
{item?.price?.toFixed(2)}
|
|
||||||
</td>
|
|
||||||
|
|
||||||
<td
|
|
||||||
class="text-white text-sm sm:text-[1rem] border-b-[#09090B] text-end"
|
|
||||||
>
|
|
||||||
{item?.marketCap !== null
|
|
||||||
? abbreviateNumber(item?.marketCap)
|
|
||||||
: "-"}
|
|
||||||
</td>
|
|
||||||
|
|
||||||
<td
|
|
||||||
class="text-white text-sm sm:text-[1rem] border-b-[#09090B] text-end"
|
|
||||||
>
|
|
||||||
{item?.volume !== null
|
|
||||||
? abbreviateNumber(item?.volume)
|
|
||||||
: "-"}
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
{/each}
|
|
||||||
</tbody>
|
|
||||||
</table>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</main>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</section>
|
|
||||||
@ -1,315 +0,0 @@
|
|||||||
<script lang="ts">
|
|
||||||
import { screenWidth, numberOfUnreadNotification } from "$lib/store";
|
|
||||||
import { abbreviateNumber, getLastTradingDay } from "$lib/utils";
|
|
||||||
import TableHeader from "$lib/components/Table/TableHeader.svelte";
|
|
||||||
|
|
||||||
export let data;
|
|
||||||
let timePeriod = "1D";
|
|
||||||
|
|
||||||
const lastTradingDay = new Date(getLastTradingDay() ?? null)?.toLocaleString(
|
|
||||||
"en-US",
|
|
||||||
{
|
|
||||||
month: "short",
|
|
||||||
day: "numeric",
|
|
||||||
year: "numeric",
|
|
||||||
},
|
|
||||||
);
|
|
||||||
|
|
||||||
const displayTitle = {
|
|
||||||
"1D": "Losers Today",
|
|
||||||
"1W": "Week Losers",
|
|
||||||
"1M": "Month Losers",
|
|
||||||
"1Y": "1 Year Losers",
|
|
||||||
"3Y": "3 Year Losers",
|
|
||||||
"5Y": "5 Year Losers",
|
|
||||||
};
|
|
||||||
|
|
||||||
let rawData = data?.getMarketMover?.losers;
|
|
||||||
let stockList = rawData[timePeriod];
|
|
||||||
|
|
||||||
function selectTimeInterval(state) {
|
|
||||||
timePeriod = state;
|
|
||||||
stockList = rawData[timePeriod];
|
|
||||||
}
|
|
||||||
|
|
||||||
let columns = [
|
|
||||||
{ key: "rank", label: "Rank", align: "center" },
|
|
||||||
{ key: "symbol", label: "Symbol", align: "left" },
|
|
||||||
{ key: "name", label: "Name", align: "left" },
|
|
||||||
{ key: "changesPercentage", label: "% Change", align: "right" },
|
|
||||||
{ key: "price", label: "Price", align: "right" },
|
|
||||||
{ key: "marketCap", label: "Market Cap", align: "right" },
|
|
||||||
{ key: "volume", label: "Volume", align: "right" },
|
|
||||||
];
|
|
||||||
|
|
||||||
let sortOrders = {
|
|
||||||
rank: { order: "none", type: "number" },
|
|
||||||
symbol: { order: "none", type: "string" },
|
|
||||||
name: { order: "none", type: "string" },
|
|
||||||
changesPercentage: { order: "none", type: "number" },
|
|
||||||
price: { order: "none", type: "number" },
|
|
||||||
marketCap: { order: "none", type: "number" },
|
|
||||||
volume: { order: "none", type: "number" },
|
|
||||||
};
|
|
||||||
|
|
||||||
const sortData = (key) => {
|
|
||||||
// Reset all other keys to 'none' except the current key
|
|
||||||
for (const k in sortOrders) {
|
|
||||||
if (k !== key) {
|
|
||||||
sortOrders[k].order = "none";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Cycle through 'none', 'asc', 'desc' for the clicked key
|
|
||||||
const orderCycle = ["none", "asc", "desc"];
|
|
||||||
|
|
||||||
let originalData = [];
|
|
||||||
|
|
||||||
originalData = rawData[timePeriod];
|
|
||||||
|
|
||||||
const currentOrderIndex = orderCycle.indexOf(sortOrders[key].order);
|
|
||||||
sortOrders[key].order =
|
|
||||||
orderCycle[(currentOrderIndex + 1) % orderCycle.length];
|
|
||||||
const sortOrder = sortOrders[key].order;
|
|
||||||
|
|
||||||
// Reset to original data when 'none' and stop further sorting
|
|
||||||
if (sortOrder === "none") {
|
|
||||||
stockList = [...originalData]; // Reset to original data (spread to avoid mutation)
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Define a generic comparison function
|
|
||||||
const compareValues = (a, b) => {
|
|
||||||
const { type } = sortOrders[key];
|
|
||||||
let valueA, valueB;
|
|
||||||
|
|
||||||
switch (type) {
|
|
||||||
case "date":
|
|
||||||
valueA = new Date(a[key]);
|
|
||||||
valueB = new Date(b[key]);
|
|
||||||
break;
|
|
||||||
case "string":
|
|
||||||
valueA = a[key].toUpperCase();
|
|
||||||
valueB = b[key].toUpperCase();
|
|
||||||
return sortOrder === "asc"
|
|
||||||
? valueA.localeCompare(valueB)
|
|
||||||
: valueB.localeCompare(valueA);
|
|
||||||
case "number":
|
|
||||||
default:
|
|
||||||
valueA = parseFloat(a[key]);
|
|
||||||
valueB = parseFloat(b[key]);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (sortOrder === "asc") {
|
|
||||||
return valueA < valueB ? -1 : valueA > valueB ? 1 : 0;
|
|
||||||
} else {
|
|
||||||
return valueA > valueB ? -1 : valueA < valueB ? 1 : 0;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
// Sort using the generic comparison function
|
|
||||||
stockList = [...originalData].sort(compareValues);
|
|
||||||
};
|
|
||||||
$: charNumber = $screenWidth < 640 ? 20 : 30;
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<svelte:head>
|
|
||||||
<meta charset="utf-8" />
|
|
||||||
<meta name="viewport" content="width=device-width" />
|
|
||||||
<title>
|
|
||||||
{$numberOfUnreadNotification > 0 ? `(${$numberOfUnreadNotification})` : ""}
|
|
||||||
Top Stock Losers · stocknear
|
|
||||||
</title>
|
|
||||||
<meta
|
|
||||||
name="description"
|
|
||||||
content={`A list of the stocks with the highest percentage gain, highest percentage loss and most active today. See stock price, volume, market cap and more.`}
|
|
||||||
/>
|
|
||||||
|
|
||||||
<!-- Other meta tags -->
|
|
||||||
<meta property="og:title" content={`Today's Top Stock Losers · stocknear`} />
|
|
||||||
<meta
|
|
||||||
property="og:description"
|
|
||||||
content={`A list of the stocks with the highest percentage gain, highest percentage loss and most active today. See stock price, volume, market cap and more.`}
|
|
||||||
/>
|
|
||||||
<meta property="og:type" content="website" />
|
|
||||||
<!-- Add more Open Graph meta tags as needed -->
|
|
||||||
|
|
||||||
<!-- Twitter specific meta tags -->
|
|
||||||
<meta name="twitter:card" content="summary_large_image" />
|
|
||||||
<meta name="twitter:title" content={`Today's Top Stock Losers · stocknear`} />
|
|
||||||
<meta
|
|
||||||
name="twitter:description"
|
|
||||||
content={`A list of the stocks with the highest percentage gain, highest percentage loss and most active today. See stock price, volume, market cap and more.`}
|
|
||||||
/>
|
|
||||||
<!-- Add more Twitter meta tags as needed -->
|
|
||||||
</svelte:head>
|
|
||||||
|
|
||||||
<section class="w-full overflow-hidden m-auto">
|
|
||||||
<div class="flex justify-center w-full m-auto overflow-hidden">
|
|
||||||
<div
|
|
||||||
class="w-full relative flex justify-center items-center overflow-hidden"
|
|
||||||
>
|
|
||||||
<main class="w-full">
|
|
||||||
<!--Start Top Winners/Losers-->
|
|
||||||
|
|
||||||
<nav class=" pt-1 overflow-x-scroll whitespace-nowrap">
|
|
||||||
<ul
|
|
||||||
class="flex flex-row items-center w-full text-sm sm:text-[1rem] text-white"
|
|
||||||
>
|
|
||||||
<li
|
|
||||||
on:click={() => selectTimeInterval("1D")}
|
|
||||||
class="p-2 px-5 cursor-pointer {timePeriod === '1D'
|
|
||||||
? 'text-white bg-[#27272A] sm:hover:bg-opacity-[0.95]'
|
|
||||||
: 'text-gray-400 sm:hover:text-white sm:hover:bg-[#27272A] sm:hover:bg-opacity-[0.95]'}"
|
|
||||||
>
|
|
||||||
Today
|
|
||||||
</li>
|
|
||||||
<li
|
|
||||||
on:click={() => selectTimeInterval("1W")}
|
|
||||||
class="p-2 px-5 cursor-pointer {timePeriod === '1W'
|
|
||||||
? 'text-white bg-[#27272A] sm:hover:bg-opacity-[0.95]'
|
|
||||||
: 'text-gray-400 sm:hover:text-white sm:hover:bg-[#27272A] sm:hover:bg-opacity-[0.95]'}"
|
|
||||||
>
|
|
||||||
Week
|
|
||||||
</li>
|
|
||||||
<li
|
|
||||||
on:click={() => selectTimeInterval("1M")}
|
|
||||||
class="p-2 px-5 cursor-pointer {timePeriod === '1M'
|
|
||||||
? 'text-white bg-[#27272A] sm:hover:bg-opacity-[0.95]'
|
|
||||||
: 'text-gray-400 sm:hover:text-white sm:hover:bg-[#27272A] sm:hover:bg-opacity-[0.95]'}"
|
|
||||||
>
|
|
||||||
Month
|
|
||||||
</li>
|
|
||||||
<li
|
|
||||||
on:click={() => selectTimeInterval("1Y")}
|
|
||||||
class="p-2 px-5 cursor-pointer {timePeriod === '1Y'
|
|
||||||
? 'text-white bg-[#27272A] sm:hover:bg-opacity-[0.95]'
|
|
||||||
: 'text-gray-400 sm:hover:text-white sm:hover:bg-[#27272A] sm:hover:bg-opacity-[0.95]'}"
|
|
||||||
>
|
|
||||||
Year
|
|
||||||
</li>
|
|
||||||
<li
|
|
||||||
on:click={() => selectTimeInterval("3Y")}
|
|
||||||
class="p-2 px-5 cursor-pointer {timePeriod === '3Y'
|
|
||||||
? 'text-white bg-[#27272A] sm:hover:bg-opacity-[0.95]'
|
|
||||||
: 'text-gray-400 sm:hover:text-white sm:hover:bg-[#27272A] sm:hover:bg-opacity-[0.95]'}"
|
|
||||||
>
|
|
||||||
3 Years
|
|
||||||
</li>
|
|
||||||
<li
|
|
||||||
on:click={() => selectTimeInterval("5Y")}
|
|
||||||
class="p-2 px-5 cursor-pointer {timePeriod === '5Y'
|
|
||||||
? 'text-white bg-[#27272A] sm:hover:bg-opacity-[0.95]'
|
|
||||||
: 'text-gray-400 sm:hover:text-white sm:hover:bg-[#27272A] sm:hover:bg-opacity-[0.95]'}"
|
|
||||||
>
|
|
||||||
5 Years
|
|
||||||
</li>
|
|
||||||
</ul>
|
|
||||||
</nav>
|
|
||||||
|
|
||||||
<div
|
|
||||||
class="flex flex-col justify-center items-center overflow-hidden mt-10"
|
|
||||||
>
|
|
||||||
<div class="controls groups w-full">
|
|
||||||
<div
|
|
||||||
class="title-group flex flex-row items-center justify-start mb-3"
|
|
||||||
>
|
|
||||||
<h1 class="text-white text-xl sm:text-2xl font-semibold">
|
|
||||||
{displayTitle[timePeriod]}
|
|
||||||
</h1>
|
|
||||||
|
|
||||||
<div
|
|
||||||
class="mb-0 ml-3 mt-1 whitespace-nowrap text-sm font-semiboldt text-white"
|
|
||||||
>
|
|
||||||
<span class="hidden lg:inline">Updated</span>
|
|
||||||
{lastTradingDay}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="w-full overflow-x-scroll no-scrollbar">
|
|
||||||
<table
|
|
||||||
class="table table-sm table-compact rounded-none sm:rounded-md w-full bg-[#09090B] border-bg-[#09090B]"
|
|
||||||
>
|
|
||||||
<thead>
|
|
||||||
<TableHeader {columns} {sortOrders} {sortData} />
|
|
||||||
</thead>
|
|
||||||
<tbody>
|
|
||||||
{#each stockList as item}
|
|
||||||
<tr
|
|
||||||
class="border-b border-[#27272A] sm:hover:bg-[#245073] sm:hover:bg-opacity-[0.2] odd:bg-[#27272A]"
|
|
||||||
>
|
|
||||||
<td
|
|
||||||
class="text-white text-sm sm:text-[1rem] text-center border-b-[#09090B]"
|
|
||||||
>
|
|
||||||
{item?.rank}
|
|
||||||
</td>
|
|
||||||
|
|
||||||
<td
|
|
||||||
class="border-b-[#09090B] text-sm sm:text-[1rem] whitespace-nowrap"
|
|
||||||
>
|
|
||||||
<a
|
|
||||||
href={"/stocks/" + item?.symbol}
|
|
||||||
class="sm:hover:text-white text-blue-400"
|
|
||||||
>
|
|
||||||
{item?.symbol}
|
|
||||||
</a>
|
|
||||||
</td>
|
|
||||||
<td
|
|
||||||
class="border-b-[#09090B] text-sm sm:text-[1rem] whitespace-nowrap text-white"
|
|
||||||
>
|
|
||||||
{item?.name?.length > charNumber
|
|
||||||
? item?.name?.slice(0, charNumber) + "..."
|
|
||||||
: item?.name}
|
|
||||||
</td>
|
|
||||||
|
|
||||||
<td
|
|
||||||
class="text-white text-end text-sm sm:text-[1rem] font-medium border-b-[#09090B]"
|
|
||||||
>
|
|
||||||
{#if item?.changesPercentage >= 0}
|
|
||||||
<span class="text-[#00FC50]"
|
|
||||||
>+{item?.changesPercentage >= 1000
|
|
||||||
? abbreviateNumber(item?.changesPercentage)
|
|
||||||
: item?.changesPercentage?.toFixed(2)}%</span
|
|
||||||
>
|
|
||||||
{:else}
|
|
||||||
<span class="text-[#FF2F1F]"
|
|
||||||
>{item?.changesPercentage <= -1000
|
|
||||||
? abbreviateNumber(item?.changesPercentage)
|
|
||||||
: item?.changesPercentage?.toFixed(2)}%
|
|
||||||
</span>
|
|
||||||
{/if}
|
|
||||||
</td>
|
|
||||||
|
|
||||||
<td
|
|
||||||
class="text-white text-sm sm:text-[1rem] text-end border-b-[#09090B]"
|
|
||||||
>
|
|
||||||
{item?.price?.toFixed(2)}
|
|
||||||
</td>
|
|
||||||
|
|
||||||
<td
|
|
||||||
class="text-white text-sm sm:text-[1rem] border-b-[#09090B] text-end"
|
|
||||||
>
|
|
||||||
{item?.marketCap !== null
|
|
||||||
? abbreviateNumber(item?.marketCap)
|
|
||||||
: "-"}
|
|
||||||
</td>
|
|
||||||
|
|
||||||
<td
|
|
||||||
class="text-white text-sm sm:text-[1rem] border-b-[#09090B] text-end"
|
|
||||||
>
|
|
||||||
{item?.volume !== null
|
|
||||||
? abbreviateNumber(item?.volume)
|
|
||||||
: "-"}
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
{/each}
|
|
||||||
</tbody>
|
|
||||||
</table>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</main>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</section>
|
|
||||||
@ -66,7 +66,11 @@ const pages = [
|
|||||||
{ title: "/economic-calendar" },
|
{ title: "/economic-calendar" },
|
||||||
{ title: "/dividends-calendar" },
|
{ title: "/dividends-calendar" },
|
||||||
{ title: "/stock-splits-calendar" },
|
{ title: "/stock-splits-calendar" },
|
||||||
{ title: "/market-mover" },
|
{ title: "/market-mover/gainers" },
|
||||||
|
{ title: "/market-mover/losers" },
|
||||||
|
{ title: "/market-mover/active" },
|
||||||
|
{ title: "/market-mover/premarket" },
|
||||||
|
{ title: "/market-mover/afterhours" },
|
||||||
{ title: "/community" },
|
{ title: "/community" },
|
||||||
{ title: "/community/create-post" },
|
{ title: "/community/create-post" },
|
||||||
{ title: "/hedge-funds" },
|
{ title: "/hedge-funds" },
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user