clean code

This commit is contained in:
MuslemRahimi 2024-10-17 13:59:09 +02:00
parent a1835f8a1c
commit 5d1449e5da

View File

@ -1,39 +1,56 @@
<script lang='ts'> <script lang="ts">
import { goto } from '$app/navigation'; import { goto } from "$app/navigation";
import { screenWidth, numberOfUnreadNotification } from '$lib/store'; import { screenWidth, numberOfUnreadNotification } from "$lib/store";
import logo from '$lib/images/top_winner_logo.png'; import logo from "$lib/images/top_winner_logo.png";
import { abbreviateNumber } from '$lib/utils'; import { abbreviateNumber } from "$lib/utils";
import MiniPlot from '$lib/components/MiniPlot.svelte'; import MiniPlot from "$lib/components/MiniPlot.svelte";
import { onMount } from 'svelte'; import { onMount } from "svelte";
import ArrowLogo from "lucide-svelte/icons/move-up-right"; import ArrowLogo from "lucide-svelte/icons/move-up-right";
import TableHeader from "$lib/components/Table/TableHeader.svelte";
export let data; export let data;
let isLoaded = false; let isLoaded = false;
const rawData = data?.getMiniPlotsIndex; const rawData = data?.getMiniPlotsIndex;
let timePeriod = '1D' let timePeriod = "1D";
let priceDataSP500; let priceDataSP500;
let priceDataNasdaq; let priceDataNasdaq;
let priceDataDowJones; let priceDataDowJones;
let priceDataRussel2000; let priceDataRussel2000;
let changeSP500, changeNasdaq, changeDowJones, changeRussel2000; let changeSP500, changeNasdaq, changeDowJones, changeRussel2000;
let previousCloseSP500, previousCloseNasdaq, previousCloseDowJones, previousCloseRussel2000; let previousCloseSP500,
previousCloseNasdaq,
previousCloseDowJones,
previousCloseRussel2000;
function getCurrentDateFormatted() { function getCurrentDateFormatted() {
// Get current date // Get current date
let date = new Date(); let date = new Date();
// If today is Saturday or Sunday, move to the previous Friday // If today is Saturday or Sunday, move to the previous Friday
if (date.getDay() === 6) { // Saturday if (date.getDay() === 6) {
// Saturday
date.setDate(date.getDate() - 1); date.setDate(date.getDate() - 1);
} else if (date.getDay() === 0) { // Sunday } else if (date.getDay() === 0) {
// Sunday
date.setDate(date.getDate() - 2); date.setDate(date.getDate() - 2);
} }
// Define months array for formatting // Define months array for formatting
const months = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]; const months = [
"Jan",
"Feb",
"Mar",
"Apr",
"May",
"Jun",
"Jul",
"Aug",
"Sep",
"Oct",
"Nov",
"Dec",
];
// Get formatted date components // Get formatted date components
const month = months[date.getMonth()]; const month = months[date.getMonth()];
@ -44,31 +61,63 @@ function getCurrentDateFormatted() {
return `${month} ${day}, ${year}`; return `${month} ${day}, ${year}`;
} }
// Assign values based on the symbol // Assign values based on the symbol
rawData?.forEach(({ symbol, priceData, changesPercentage, previousClose }) => { rawData?.forEach(
({ symbol, priceData, changesPercentage, previousClose }) => {
switch (symbol) { switch (symbol) {
case "SPY": case "SPY":
priceDataSP500 = priceData?.map(({ time, value }) => ({ time: Date?.parse(time), value})); priceDataSP500 = priceData?.map(({ time, value }) => ({
priceDataSP500 = priceDataSP500?.filter(item => item.value !== 0 && item.value !== null && item.value !== undefined) time: Date?.parse(time),
value,
}));
priceDataSP500 = priceDataSP500?.filter(
(item) =>
item.value !== 0 &&
item.value !== null &&
item.value !== undefined,
);
changeSP500 = changesPercentage; changeSP500 = changesPercentage;
previousCloseSP500 = previousClose; previousCloseSP500 = previousClose;
break; break;
case "QQQ": case "QQQ":
priceDataNasdaq = priceData?.map(({ time, value }) => ({ time: Date?.parse(time), value})); priceDataNasdaq = priceData?.map(({ time, value }) => ({
priceDataNasdaq = priceDataNasdaq?.filter(item => item.value !== 0 && item.value !== null && item.value !== undefined) time: Date?.parse(time),
value,
}));
priceDataNasdaq = priceDataNasdaq?.filter(
(item) =>
item.value !== 0 &&
item.value !== null &&
item.value !== undefined,
);
changeNasdaq = changesPercentage; changeNasdaq = changesPercentage;
previousCloseNasdaq = previousClose; previousCloseNasdaq = previousClose;
break; break;
case "DIA": case "DIA":
priceDataDowJones = priceData?.map(({ time, value }) => ({ time: Date?.parse(time), value})); priceDataDowJones = priceData?.map(({ time, value }) => ({
priceDataDowJones = priceDataDowJones?.filter(item => item.value !== 0 && item.value !== null && item.value !== undefined) time: Date?.parse(time),
changeDowJones = changesPercentage value,
}));
priceDataDowJones = priceDataDowJones?.filter(
(item) =>
item.value !== 0 &&
item.value !== null &&
item.value !== undefined,
);
changeDowJones = changesPercentage;
previousCloseDowJones = previousClose; previousCloseDowJones = previousClose;
break; break;
case "IWM": case "IWM":
priceDataRussel2000 = priceData?.map(({ time, value }) => ({ time: Date?.parse(time), value})); priceDataRussel2000 = priceData?.map(({ time, value }) => ({
priceDataRussel2000 = priceDataRussel2000?.filter(item => item.value !== 0 && item.value !== null && item.value !== undefined) time: Date?.parse(time),
value,
}));
priceDataRussel2000 = priceDataRussel2000?.filter(
(item) =>
item.value !== 0 &&
item.value !== null &&
item.value !== undefined,
);
changeRussel2000 = changesPercentage; changeRussel2000 = changesPercentage;
previousCloseRussel2000 = previousClose; previousCloseRussel2000 = previousClose;
break; break;
@ -76,14 +125,13 @@ rawData?.forEach(({ symbol, priceData, changesPercentage, previousClose }) => {
// Handle unknown symbol // Handle unknown symbol
break; break;
} }
}); },
);
let outputList = data?.getDailyGainerLoserActive; let outputList = data?.getDailyGainerLoserActive;
let gainerLoserActive = outputList?.gainers[timePeriod] let gainerLoserActive = outputList?.gainers[timePeriod];
let buttonText = 'Top Winners';
let buttonText = "Top Winners";
const tabs = [ const tabs = [
{ {
@ -101,167 +149,177 @@ let activeIdx = 0;
function changeSection(index) { function changeSection(index) {
activeIdx = index; activeIdx = index;
sortOrders = {
if (index === 0) 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" },
};
if (index === 0) {
gainerLoserActive = outputList?.gainers[timePeriod]; gainerLoserActive = outputList?.gainers[timePeriod];
buttonText = 'Top Winners' buttonText = "Top Winners";
} } else if (index === 1) {
else if (index === 1)
{
gainerLoserActive = outputList?.losers[timePeriod]; gainerLoserActive = outputList?.losers[timePeriod];
buttonText = 'Top Losers' buttonText = "Top Losers";
} } else if (index === 2) {
else if (index === 2)
{
gainerLoserActive = outputList?.active[timePeriod]; gainerLoserActive = outputList?.active[timePeriod];
buttonText = 'Most Active' buttonText = "Most Active";
} }
} }
function selectTimeInterval(event) { function selectTimeInterval(event) {
timePeriod =
event.target.value === "oneDay"
? "1D"
: event.target.value === "oneWeek"
? "1W"
: event.target.value === "oneMonth"
? "1M"
: event.target.value === "threeMonths"
? "3M"
: "6M";
if (buttonText === "Top Winners") {
timePeriod = event.target.value === 'oneDay' ? '1D' : event.target.value === 'oneWeek' ? '1W' : event.target.value === 'oneMonth' ? '1M' : event.target.value === 'threeMonths' ? '3M' : '6M';
if (buttonText === 'Top Winners')
{
gainerLoserActive = outputList?.gainers[timePeriod]; gainerLoserActive = outputList?.gainers[timePeriod];
} } else if (buttonText === "Top Losers") {
else if (buttonText === 'Top Losers')
{
gainerLoserActive = outputList?.losers[timePeriod]; gainerLoserActive = outputList?.losers[timePeriod];
} } else if (buttonText === "Most Active") {
else if (buttonText === 'Most Active')
{
gainerLoserActive = outputList?.active[timePeriod]; gainerLoserActive = outputList?.active[timePeriod];
} }
} }
onMount(() => { onMount(() => {
isLoaded = true; isLoaded = true;
}) });
let columns = [
{ 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 = { let sortOrders = {
symbol: 'none', symbol: { order: "none", type: "string" },
name: 'none', name: { order: "none", type: "string" },
change: 'none', changesPercentage: { order: "none", type: "number" },
price: 'none', price: { order: "none", type: "number" },
marketCap: 'none', marketCap: { order: "none", type: "number" },
volume: 'none', volume: { order: "none", type: "number" },
}; };
// Generalized sorting function const sortData = (key) => {
function sortData(key) {
// Reset all other keys to 'none' except the current key // Reset all other keys to 'none' except the current key
for (const k in sortOrders) { for (const k in sortOrders) {
if (k !== key) { if (k !== key) {
sortOrders[k] = 'none'; sortOrders[k].order = "none";
} }
} }
// Cycle through 'none', 'asc', 'desc' for the clicked key // Cycle through 'none', 'asc', 'desc' for the clicked key
const orderCycle = ['none', 'asc', 'desc']; const orderCycle = ["none", "asc", "desc"];
let originalData = []; let originalData = [];
if (buttonText === 'Top Winners') if (buttonText === "Top Winners") {
{ originalData = data?.getDailyGainerLoserActive?.gainers[timePeriod];
originalData = data?.getDailyGainerLoserActive?.gainers[timePeriod] } else if (buttonText === "Top Losers") {
} originalData = data?.getDailyGainerLoserActive?.losers[timePeriod];
else if (buttonText === 'Top Losers') } else if (buttonText === "Most Active") {
{ originalData = data?.getDailyGainerLoserActive?.active[timePeriod];
originalData = data?.getDailyGainerLoserActive?.losers[timePeriod]
}
else if (buttonText === 'Most Active')
{
originalData = data?.getDailyGainerLoserActive?.active[timePeriod]
} }
const currentOrderIndex = orderCycle.indexOf(sortOrders[key]); const currentOrderIndex = orderCycle.indexOf(sortOrders[key].order);
sortOrders[key] = orderCycle[(currentOrderIndex + 1) % orderCycle.length]; sortOrders[key].order =
orderCycle[(currentOrderIndex + 1) % orderCycle.length];
const sortOrder = sortOrders[key]; const sortOrder = sortOrders[key].order;
// Reset to original data when 'none' and stop further sorting // Reset to original data when 'none' and stop further sorting
if (sortOrder === 'none') { if (sortOrder === "none") {
gainerLoserActive = [...originalData]; // Reset to original data (spread to avoid mutation) gainerLoserActive = [...originalData]; // Reset to original data (spread to avoid mutation)
return; return;
} }
// Define comparison functions for each key // Define a generic comparison function
const compareFunctions = { const compareValues = (a, b) => {
symbol: (a, b) => { const { type } = sortOrders[key];
const symbolA = a.symbol.toUpperCase(); let valueA, valueB;
const symbolB = b.symbol.toUpperCase();
return sortOrder === 'asc' ? symbolA.localeCompare(symbolB) : symbolB.localeCompare(symbolA);
},
name: (a, b) => {
const nameA = a.name.toUpperCase();
const nameB = b.name.toUpperCase();
return sortOrder === 'asc' ? nameA.localeCompare(nameB) : nameB.localeCompare(nameA);
},
change: (a, b) => {
const numA = parseFloat(a?.changesPercentage);
const numB = parseFloat(b?.changesPercentage);
return sortOrder === 'asc' ? numA - numB : numB - numA;
},
price: (a, b) => {
const numA = parseFloat(a?.price);
const numB = parseFloat(b?.price);
return sortOrder === 'asc' ? numA - numB : numB - numA;
},
marketCap: (a, b) => {
const numA = parseFloat(a.marketCap);
const numB = parseFloat(b.marketCap);
return sortOrder === 'asc' ? numA - numB : numB - numA;
},
volume: (a, b) => {
const numA = parseFloat(a.volume);
const numB = parseFloat(b.volume);
return sortOrder === 'asc' ? numA - numB : numB - numA;
},
};
// Sort using the appropriate comparison function switch (type) {
gainerLoserActive = [...originalData].sort(compareFunctions[key]); 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
gainerLoserActive = [...originalData].sort(compareValues);
};
$: charNumber = $screenWidth < 640 ? 20 : 30; $: charNumber = $screenWidth < 640 ? 20 : 30;
</script> </script>
<svelte:head> <svelte:head>
<meta charset="utf-8" /> <meta charset="utf-8" />
<meta name="viewport" content="width=device-width" /> <meta name="viewport" content="width=device-width" />
<title> <title>
{$numberOfUnreadNotification > 0 ? `(${$numberOfUnreadNotification})` : ''} Today's Top Stock Gainers, Losers and Most Active · stocknear {$numberOfUnreadNotification > 0 ? `(${$numberOfUnreadNotification})` : ""} Today's
Top Stock Gainers, Losers and Most Active · stocknear
</title> </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.`} /> <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 --> <!-- Other meta tags -->
<meta property="og:title" content={`Today's Top Stock Gainers, Losers and Most Active · stocknear`}/> <meta
<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.`} /> property="og:title"
content={`Today's Top Stock Gainers, Losers and Most 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" /> <meta property="og:type" content="website" />
<!-- Add more Open Graph meta tags as needed --> <!-- Add more Open Graph meta tags as needed -->
<!-- Twitter specific meta tags --> <!-- Twitter specific meta tags -->
<meta name="twitter:card" content="summary_large_image" /> <meta name="twitter:card" content="summary_large_image" />
<meta name="twitter:title" content={`Today's Top Stock Gainers, Losers and Most Active · stocknear`}/> <meta
<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.`} /> name="twitter:title"
content={`Today's Top Stock Gainers, Losers and Most 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 --> <!-- Add more Twitter meta tags as needed -->
</svelte:head> </svelte:head>
<section class="w-full max-w-3xl sm:max-w-screen-2xl overflow-hidden min-h-screen pt-5 pb-40 lg:px-3"> <section
class="w-full max-w-3xl sm:max-w-screen-2xl overflow-hidden min-h-screen pt-5 pb-40 lg:px-3"
>
<div class="text-sm sm:text-[1rem] breadcrumbs ml-4"> <div class="text-sm sm:text-[1rem] breadcrumbs ml-4">
<ul> <ul>
<li><a href="/" class="text-gray-300">Home</a></li> <li><a href="/" class="text-gray-300">Home</a></li>
@ -270,36 +328,43 @@ $: charNumber = $screenWidth < 640 ? 20 : 30;
</div> </div>
<div class="w-full overflow-hidden m-auto mt-5"> <div class="w-full overflow-hidden m-auto mt-5">
<div class="sm:p-0 flex justify-center w-full m-auto overflow-hidden"> <div class="sm:p-0 flex justify-center w-full m-auto overflow-hidden">
<div class="relative flex justify-center items-start overflow-hidden w-full"> <div
class="relative flex justify-center items-start overflow-hidden w-full"
>
<main class="w-full lg:w-3/4 lg:pr-5"> <main class="w-full lg:w-3/4 lg:pr-5">
<div
class="w-full m-auto sm:bg-[#27272A] h-auto pl-10 pr-10 pt-5 sm:pb-10 sm:pt-10 mt-3 mb-8"
<div class="w-full m-auto sm:bg-[#27272A] h-auto pl-10 pr-10 pt-5 sm:pb-10 sm:pt-10 mt-3 mb-8"> >
<div class="grid grid-cols-1 sm:grid-cols-2 gap-10"> <div class="grid grid-cols-1 sm:grid-cols-2 gap-10">
<!-- Start Column --> <!-- Start Column -->
<div> <div>
<div class="flex flex-row justify-center items-center"> <div class="flex flex-row justify-center items-center">
<h1 class="text-3xl sm:text-4xl text-white text-center font-bold mb-5"> <h1
class="text-3xl sm:text-4xl text-white text-center font-bold mb-5"
>
Market Movers Market Movers
</h1> </h1>
</div> </div>
<span class="hidden sm:block text-white text-md font-semibold text-center flex justify-center items-center "> <span
Explore top-performing, underperforming & most active traded stocks across different time frames. class="hidden sm:block text-white text-md font-semibold text-center flex justify-center items-center"
>
Explore top-performing, underperforming & most active traded
stocks across different time frames.
</span> </span>
</div> </div>
<!-- End Column --> <!-- End Column -->
<!-- Start Column --> <!-- Start Column -->
<div class="hidden sm:block relative m-auto mb-5 mt-5 md:mb-0 md:mt-0"> <div
<svg class="w-32 -my-4" viewBox="0 0 200 200" xmlns="http://www.w3.org/2000/svg"> class="hidden sm:block relative m-auto mb-5 mt-5 md:mb-0 md:mt-0"
>
<svg
class="w-32 -my-4"
viewBox="0 0 200 200"
xmlns="http://www.w3.org/2000/svg"
>
<defs> <defs>
<filter id="glow"> <filter id="glow">
<feGaussianBlur stdDeviation="5" result="glow" /> <feGaussianBlur stdDeviation="5" result="glow" />
@ -309,44 +374,73 @@ $: charNumber = $screenWidth < 640 ? 20 : 30;
</feMerge> </feMerge>
</filter> </filter>
</defs> </defs>
<path fill="#1E40AF" d="M57.6,-58.7C72.7,-42.6,81.5,-21.3,82,0.5C82.5,22.3,74.7,44.6,59.7,60.1C44.6,75.6,22.3,84.3,0,84.3C-22.3,84.2,-44.6,75.5,-61.1,60.1C-77.6,44.6,-88.3,22.3,-87.6,0.7C-86.9,-20.8,-74.7,-41.6,-58.2,-57.7C-41.6,-73.8,-20.8,-85.2,0.2,-85.4C21.3,-85.6,42.6,-74.7,57.6,-58.7Z" transform="translate(100 100)" filter="url(#glow)" /> <path
fill="#1E40AF"
d="M57.6,-58.7C72.7,-42.6,81.5,-21.3,82,0.5C82.5,22.3,74.7,44.6,59.7,60.1C44.6,75.6,22.3,84.3,0,84.3C-22.3,84.2,-44.6,75.5,-61.1,60.1C-77.6,44.6,-88.3,22.3,-87.6,0.7C-86.9,-20.8,-74.7,-41.6,-58.2,-57.7C-41.6,-73.8,-20.8,-85.2,0.2,-85.4C21.3,-85.6,42.6,-74.7,57.6,-58.7Z"
transform="translate(100 100)"
filter="url(#glow)"
/>
</svg> </svg>
<div class="z-1 absolute -top-3 right-1"> <div class="z-1 absolute -top-3 right-1">
<img class="w-28" src={logo} alt="logo" loading="lazy"> <img class="w-28" src={logo} alt="logo" loading="lazy" />
</div> </div>
</div> </div>
<!-- End Column --> <!-- End Column -->
</div> </div>
</div> </div>
{#if isLoaded} {#if isLoaded}
<div
<div class="sm:hidden text-white text-xs sm:text-sm pb-5 sm:pb-2 pl-3 sm:pl-0"> class="sm:hidden text-white text-xs sm:text-sm pb-5 sm:pb-2 pl-3 sm:pl-0"
>
Stock Indexes - {getCurrentDateFormatted()} Stock Indexes - {getCurrentDateFormatted()}
</div> </div>
<div class="w-full sm:hidden -mt-4 sm:mt-0 mb-8 m-auto flex justify-start sm:justify-center items-center p-3 sm:p-0"> <div
<div class="w-full grid grid-cols-2 md:grid-cols-3 gap-y-3 gap-x-3 "> class="w-full sm:hidden -mt-4 sm:mt-0 mb-8 m-auto flex justify-start sm:justify-center items-center p-3 sm:p-0"
<MiniPlot title="S&P500" priceData = {priceDataSP500} changesPercentage={changeSP500} previousClose={previousCloseSP500}/> >
<MiniPlot title="Nasdaq" priceData = {priceDataNasdaq} changesPercentage={changeNasdaq} previousClose={previousCloseNasdaq}/> <div
<MiniPlot title="Dow" priceData = {priceDataDowJones} changesPercentage={changeDowJones} previousClose={previousCloseDowJones}/> class="w-full grid grid-cols-2 md:grid-cols-3 gap-y-3 gap-x-3"
<MiniPlot title="Russel" priceData = {priceDataRussel2000} changesPercentage={changeRussel2000} previousClose={previousCloseRussel2000}/> >
<MiniPlot
title="S&P500"
priceData={priceDataSP500}
changesPercentage={changeSP500}
previousClose={previousCloseSP500}
/>
<MiniPlot
title="Nasdaq"
priceData={priceDataNasdaq}
changesPercentage={changeNasdaq}
previousClose={previousCloseNasdaq}
/>
<MiniPlot
title="Dow"
priceData={priceDataDowJones}
changesPercentage={changeDowJones}
previousClose={previousCloseDowJones}
/>
<MiniPlot
title="Russel"
priceData={priceDataRussel2000}
changesPercentage={changeRussel2000}
previousClose={previousCloseRussel2000}
/>
</div> </div>
</div> </div>
<div
<div class="w-full m-auto mb-10 sm:mb-5 bg-[#09090B] pl-3 pr-3 sm:pl-0 sm:pr-0"> class="w-full m-auto mb-10 sm:mb-5 bg-[#09090B] pl-3 pr-3 sm:pl-0 sm:pr-0"
>
<div
class="bg-[#313131] w-fit relative m-auto sm:m-0 sm:mr-auto flex sm:flex-wrap items-center justify-center rounded-lg p-1 -mt-3"
<div class="bg-[#313131] w-fit relative m-auto sm:m-0 sm:mr-auto flex sm:flex-wrap items-center justify-center rounded-lg p-1 -mt-3"> >
{#each tabs as item, i} {#each tabs as item, i}
<label <label
on:click={() => (changeSection(i))} on:click={() => changeSection(i)}
class="cursor-pointer group relative z-[1] rounded-full px-6 py-1 {activeIdx === i class="cursor-pointer group relative z-[1] rounded-full px-6 py-1 {activeIdx ===
i
? 'z-0' ? 'z-0'
: ''} " : ''} "
> >
@ -355,28 +449,31 @@ $: charNumber = $screenWidth < 640 ? 20 : 30;
class="absolute inset-0 rounded-lg bg-purple-600" class="absolute inset-0 rounded-lg bg-purple-600"
></div> ></div>
{/if} {/if}
<span class="relative text-[1rem] sm:text-lg block font-semibold duration-200 text-white"> <span
class="relative text-[1rem] sm:text-lg block font-semibold duration-200 text-white"
>
{item.title} {item.title}
</span> </span>
</label> </label>
{/each} {/each}
</div> </div>
</div> </div>
<!--Start Top Winners/Losers--> <!--Start Top Winners/Losers-->
<div class="flex flex-col justify-center items-center overflow-hidden"> <div
class="flex flex-col justify-center items-center overflow-hidden"
>
<div
<div class="w-full flex justify-start sm:justify-end items-center mb-10 ml-5 sm:ml-0"> class="w-full flex justify-start sm:justify-end items-center mb-10 ml-5 sm:ml-0"
>
<div class="relative flex flex-col items-start"> <div class="relative flex flex-col items-start">
<span class="sm:hidden text-white text-sm mb-3"> <span class="sm:hidden text-white text-sm mb-3">
Time Period: Time Period:
</span> </span>
<select class="w-32 text-white select select-bordered select-sm p-0 pl-5 overflow-y-auto bg-[#2A303C]" on:change={selectTimeInterval}> <select
class="w-32 text-white select select-bordered select-sm p-0 pl-5 overflow-y-auto bg-[#2A303C]"
on:change={selectTimeInterval}
>
<option disabled>Choose a time period</option> <option disabled>Choose a time period</option>
<option value="oneDay" selected>1 Day</option> <option value="oneDay" selected>1 Day</option>
<option value="oneWeek">1 Week</option> <option value="oneWeek">1 Week</option>
@ -387,106 +484,104 @@ $: charNumber = $screenWidth < 640 ? 20 : 30;
</div> </div>
</div> </div>
<div class="w-full overflow-x-scroll no-scrollbar"> <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]"> <table
class="table table-sm table-compact rounded-none sm:rounded-md w-full bg-[#09090B] border-bg-[#09090B]"
>
<thead> <thead>
<tr class="border-b border-[#27272A]"> <TableHeader {columns} {sortOrders} {sortData} />
<th on:click={() => sortData('symbol')} class="cursor-pointer select-none text-white font-semibold text-[1rem] whitespace-nowrap">
Symbol
<svg class="flex-shrink-0 w-4 h-4 inline-block {sortOrders['symbol'] === 'asc' ? 'rotate-180' : sortOrders['symbol'] === 'desc' ? '' : 'hidden'} " viewBox="0 0 20 20" fill="currentColor" style="max-width:50px"><path fill-rule="evenodd" d="M5.293 7.293a1 1 0 011.414 0L10 10.586l3.293-3.293a1 1 0 111.414 1.414l-4 4a1 1 0 01-1.414 0l-4-4a1 1 0 010-1.414z" clip-rule="evenodd"></path></svg>
</th>
<th on:click={() => sortData('name')} class="cursor-pointer select-none text-white font-semibold text-[1rem] whitespace-nowrap">
Name
<svg class="flex-shrink-0 w-4 h-4 inline-block {sortOrders['name'] === 'asc' ? 'rotate-180' : sortOrders['name'] === 'desc' ? '' : 'hidden'} " viewBox="0 0 20 20" fill="currentColor" style="max-width:50px"><path fill-rule="evenodd" d="M5.293 7.293a1 1 0 011.414 0L10 10.586l3.293-3.293a1 1 0 111.414 1.414l-4 4a1 1 0 01-1.414 0l-4-4a1 1 0 010-1.414z" clip-rule="evenodd"></path></svg>
</th>
<th on:click={() => sortData('change')} class="cursor-pointer select-none text-end text-white font-semibold text-[1rem] whitespace-nowrap">
% Change
<svg class="flex-shrink-0 w-4 h-4 inline-block {sortOrders['change'] === 'asc' ? 'rotate-180' : sortOrders['change'] === 'desc' ? '' : 'hidden'} " viewBox="0 0 20 20" fill="currentColor" style="max-width:50px"><path fill-rule="evenodd" d="M5.293 7.293a1 1 0 011.414 0L10 10.586l3.293-3.293a1 1 0 111.414 1.414l-4 4a1 1 0 01-1.414 0l-4-4a1 1 0 010-1.414z" clip-rule="evenodd"></path></svg>
</th>
<th on:click={() => sortData('price')} class="cursor-pointer select-none text-end text-white font-semibold text-[1rem] whitespace-nowrap">
Price
<svg class="flex-shrink-0 w-4 h-4 inline-block {sortOrders['price'] === 'asc' ? 'rotate-180' : sortOrders['price'] === 'desc' ? '' : 'hidden'} " viewBox="0 0 20 20" fill="currentColor" style="max-width:50px"><path fill-rule="evenodd" d="M5.293 7.293a1 1 0 011.414 0L10 10.586l3.293-3.293a1 1 0 111.414 1.414l-4 4a1 1 0 01-1.414 0l-4-4a1 1 0 010-1.414z" clip-rule="evenodd"></path></svg>
</th>
<th on:click={() => sortData('marketCap')} class="cursor-pointer select-none text-end text-white font-semibold text-[1rem] whitespace-nowrap">
Market Cap
<svg class="flex-shrink-0 w-4 h-4 inline-block {sortOrders['marketCap'] === 'asc' ? 'rotate-180' : sortOrders['marketCap'] === 'desc' ? '' : 'hidden'} " viewBox="0 0 20 20" fill="currentColor" style="max-width:50px"><path fill-rule="evenodd" d="M5.293 7.293a1 1 0 011.414 0L10 10.586l3.293-3.293a1 1 0 111.414 1.414l-4 4a1 1 0 01-1.414 0l-4-4a1 1 0 010-1.414z" clip-rule="evenodd"></path></svg>
</th>
<th on:click={() => sortData('volume')} class="cursor-pointer select-none text-end text-white font-semibold text-[1rem] whitespace-nowrap">
Volume
<svg class="flex-shrink-0 w-4 h-4 inline-block {sortOrders['volume'] === 'asc' ? 'rotate-180' : sortOrders['volume'] === 'desc' ? '' : 'hidden'} " viewBox="0 0 20 20" fill="currentColor" style="max-width:50px"><path fill-rule="evenodd" d="M5.293 7.293a1 1 0 011.414 0L10 10.586l3.293-3.293a1 1 0 111.414 1.414l-4 4a1 1 0 01-1.414 0l-4-4a1 1 0 010-1.414z" clip-rule="evenodd"></path></svg>
</th>
</tr>
</thead> </thead>
<tbody> <tbody>
{#each gainerLoserActive as item} {#each gainerLoserActive as item}
<tr class="border-b border-[#27272A] sm:hover:bg-[#245073] sm:hover:bg-opacity-[0.2] odd:bg-[#27272A]"> <tr
class="border-b border-[#27272A] sm:hover:bg-[#245073] sm:hover:bg-opacity-[0.2] odd:bg-[#27272A]"
<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"> <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} {item?.symbol}
</a> </a>
</td> </td>
<td class="border-b-[#09090B] text-sm sm:text-[1rem] whitespace-nowrap text-white"> <td
{item?.name?.length > charNumber ? item?.name?.slice(0,charNumber) + "..." : item?.name} 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>
<td class="text-white text-end text-sm sm:text-[1rem] font-medium border-b-[#09090B]"> <td
class="text-white text-end text-sm sm:text-[1rem] font-medium border-b-[#09090B]"
>
{#if item?.changesPercentage >= 0} {#if item?.changesPercentage >= 0}
<span class="text-[#37C97D]">+{item?.changesPercentage >= 1000 ? abbreviateNumber(item?.changesPercentage) : item?.changesPercentage?.toFixed(2)}%</span> <span class="text-[#37C97D]"
>+{item?.changesPercentage >= 1000
? abbreviateNumber(item?.changesPercentage)
: item?.changesPercentage?.toFixed(2)}%</span
>
{:else} {:else}
<span class="text-[#FF2F1F]">{item?.changesPercentage <= -1000 ? abbreviateNumber(item?.changesPercentage) : item?.changesPercentage?.toFixed(2)}% </span> <span class="text-[#FF2F1F]"
>{item?.changesPercentage <= -1000
? abbreviateNumber(item?.changesPercentage)
: item?.changesPercentage?.toFixed(2)}%
</span>
{/if} {/if}
</td> </td>
<td class="text-white text-sm sm:text-[1rem] text-end border-b-[#09090B]"> <td
class="text-white text-sm sm:text-[1rem] text-end border-b-[#09090B]"
>
{item?.price?.toFixed(2)} {item?.price?.toFixed(2)}
</td> </td>
<td class="text-white text-sm sm:text-[1rem] border-b-[#09090B] text-end"> <td
{item?.marketCap !== null ? abbreviateNumber(item?.marketCap) : '-'} class="text-white text-sm sm:text-[1rem] border-b-[#09090B] text-end"
>
{item?.marketCap !== null
? abbreviateNumber(item?.marketCap)
: "-"}
</td> </td>
<td class="text-white text-sm sm:text-[1rem] border-b-[#09090B] text-end"> <td
{item?.volume !== null ? abbreviateNumber(item?.volume) : '-'} class="text-white text-sm sm:text-[1rem] border-b-[#09090B] text-end"
>
{item?.volume !== null
? abbreviateNumber(item?.volume)
: "-"}
</td> </td>
</tr> </tr>
{/each} {/each}
</tbody> </tbody>
</table> </table>
</div> </div>
</div> </div>
{:else} {:else}
<div class="flex justify-center items-center h-80"> <div class="flex justify-center items-center h-80">
<div class="relative"> <div class="relative">
<label class="bg-[#09090B] rounded-lg h-14 w-14 flex justify-center items-center absolute top-1/2 left-1/2 transform -translate-x-1/2 -translate-y-1/2"> <label
<span class="loading loading-spinner loading-md text-gray-400"></span> class="bg-[#09090B] rounded-lg h-14 w-14 flex justify-center items-center absolute top-1/2 left-1/2 transform -translate-x-1/2 -translate-y-1/2"
>
<span class="loading loading-spinner loading-md text-gray-400"
></span>
</label> </label>
</div> </div>
</div> </div>
{/if} {/if}
</main> </main>
<aside class="hidden lg:block relative fixed w-1/4 ml-4"> <aside class="hidden lg:block relative fixed w-1/4 ml-4">
{#if data?.user?.tier !== "Pro" || data?.user?.freeTrial}
{#if data?.user?.tier !== 'Pro' || data?.user?.freeTrial} <div
<div on:click={() => goto('/pricing')} class="w-full bg-[#141417] duration-100 ease-out sm:hover:text-white text-gray-400 sm:hover:border-gray-700 border border-gray-800 rounded-lg h-fit pb-4 mt-4 cursor-pointer"> on:click={() => goto("/pricing")}
<div class="w-auto lg:w-full p-1 flex flex-col m-auto px-2 sm:px-0"> class="w-full bg-[#141417] duration-100 ease-out sm:hover:text-white text-gray-400 sm:hover:border-gray-700 border border-gray-800 rounded-lg h-fit pb-4 mt-4 cursor-pointer"
>
<div
class="w-auto lg:w-full p-1 flex flex-col m-auto px-2 sm:px-0"
>
<div class="w-full flex justify-between items-center p-3 mt-3"> <div class="w-full flex justify-between items-center p-3 mt-3">
<h2 class="text-start text-xl font-semibold text-white ml-3"> <h2 class="text-start text-xl font-semibold text-white ml-3">
Pro Subscription Pro Subscription
@ -500,7 +595,10 @@ $: charNumber = $screenWidth < 640 ? 20 : 30;
</div> </div>
{/if} {/if}
<div on:click={() => goto('/analysts')} class="w-full bg-[#141417] duration-100 ease-out sm:hover:text-white text-gray-400 sm:hover:border-gray-700 border border-gray-800 rounded-lg h-fit pb-4 mt-4 cursor-pointer"> <div
on:click={() => goto("/analysts")}
class="w-full bg-[#141417] duration-100 ease-out sm:hover:text-white text-gray-400 sm:hover:border-gray-700 border border-gray-800 rounded-lg h-fit pb-4 mt-4 cursor-pointer"
>
<div class="w-auto lg:w-full p-1 flex flex-col m-auto px-2 sm:px-0"> <div class="w-auto lg:w-full p-1 flex flex-col m-auto px-2 sm:px-0">
<div class="w-full flex justify-between items-center p-3 mt-3"> <div class="w-full flex justify-between items-center p-3 mt-3">
<h2 class="text-start text-xl font-semibold text-white ml-3"> <h2 class="text-start text-xl font-semibold text-white ml-3">
@ -514,7 +612,10 @@ $: charNumber = $screenWidth < 640 ? 20 : 30;
</div> </div>
</div> </div>
<div on:click={() => goto('/politicians')} class="w-full bg-[#141417] duration-100 ease-out sm:hover:text-white text-gray-400 sm:hover:border-gray-700 border border-gray-800 rounded-lg h-fit pb-4 mt-4 cursor-pointer"> <div
on:click={() => goto("/politicians")}
class="w-full bg-[#141417] duration-100 ease-out sm:hover:text-white text-gray-400 sm:hover:border-gray-700 border border-gray-800 rounded-lg h-fit pb-4 mt-4 cursor-pointer"
>
<div class="w-auto lg:w-full p-1 flex flex-col m-auto px-2 sm:px-0"> <div class="w-auto lg:w-full p-1 flex flex-col m-auto px-2 sm:px-0">
<div class="w-full flex justify-between items-center p-3 mt-3"> <div class="w-full flex justify-between items-center p-3 mt-3">
<h2 class="text-start text-xl font-semibold text-white ml-3"> <h2 class="text-start text-xl font-semibold text-white ml-3">
@ -527,16 +628,8 @@ $: charNumber = $screenWidth < 640 ? 20 : 30;
</span> </span>
</div> </div>
</div> </div>
</aside> </aside>
</div> </div>
</div> </div>
</div> </div>
</section> </section>