clean code

This commit is contained in:
MuslemRahimi 2025-01-13 11:26:17 +01:00
parent 32b987b8e1
commit 52a6ecd2f5
17 changed files with 0 additions and 7703 deletions

View File

@ -1,23 +0,0 @@
export const load = async ({ locals }) => {
const getCryptoList = async () => {
const { apiKey, apiURL } = locals;
const response = await fetch(apiURL + "/all-crypto-tickers", {
method: "GET",
headers: {
"Content-Type": "application/json",
"X-API-KEY": apiKey,
},
});
const output = (await response.json())?.sort(
(a, b) => b?.marketCap - a?.marketCap
);
return output;
};
// Make sure to return a promise
return {
getCryptoList: await getCryptoList(),
};
};

View File

@ -1,283 +0,0 @@
<script lang="ts">
import { goto } from "$app/navigation";
import { numberOfUnreadNotification, screenWidth } from "$lib/store";
import { abbreviateNumber } from "$lib/utils";
import logo from "$lib/images/box_logo.png";
import ArrowLogo from "lucide-svelte/icons/move-up-right";
export let data;
let rawData = data?.getCryptoList;
let symbolList = rawData; //rawData?.slice(0,30);
$: charNumber = $screenWidth < 640 ? 15 : 40;
</script>
<svelte:head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width" />
<title>
{$numberOfUnreadNotification > 0 ? `(${$numberOfUnreadNotification})` : ""} List
of All Crypto Ticker Symbols · Stocknear
</title>
<meta
name="description"
content={`An overview of all the Crypto symbols listed. Explore the Crypto pages to learn about the circulating supply and price changes.`}
/>
<!-- Other meta tags -->
<meta
property="og:title"
content={`List of All Crypto Ticker Symbols · Stocknear`}
/>
<meta
property="og:description"
content={`An overview of all the Crypto symbols listed. Explore the Crypto pages to learn about the circulating supply and price changes.`}
/>
<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={`List of All Crypto Ticker Symbols · Stocknear`}
/>
<meta
name="twitter:description"
content={`An overview of all the Crypto symbols listed. Explore the Crypto pages to learn about the circulating supply and price changes.`}
/>
<!-- Add more Twitter meta tags as needed -->
</svelte:head>
<section
class="w-full max-w-3xl sm:max-w-[1400px] overflow-hidden min-h-screen pt-5 pb-40 lg:px-3"
>
<div class="text-sm sm:text-[1rem] breadcrumbs ml-4">
<ul>
<li><a href="/" class="text-gray-300">Home</a></li>
<li class="text-gray-300">All Cryptos</li>
</ul>
</div>
<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="relative flex justify-center items-start overflow-hidden w-full"
>
<main class="w-full lg:w-3/4 lg:pr-5">
<div
class="w-full m-auto sm:bg-primary sm:rounded-xl 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">
<!-- Start Column -->
<div>
<div class="flex flex-row justify-center items-center">
<h1
class="text-3xl sm:text-4xl text-white text-center font-bold mb-5"
>
Crypto Symbols
</h1>
</div>
<span
class="text-white text-md font-medium text-center flex justify-center items-center"
>
Collection of all Crypto Symbols available
</span>
<!--
<label for="marketMoverInfo" class="cursor-pointer flex justify-center items-center mt-2">
<span class="text-white text-md font-medium">
Learn more
</span>
<svg class="w-6 h-6 inline-block ml-2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg" fill="#000000"><g id="SVGRepo_bgCarrier" stroke-width="0"></g><g id="SVGRepo_tracerCarrier" stroke-linecap="round" stroke-linejoin="round"></g><g id="SVGRepo_iconCarrier"> <title></title> <g id="Complete"> <g id="info-circle"> <g> <circle cx="12" cy="12" data-name="--Circle" fill="none" id="_--Circle" r="10" stroke="#B46266" stroke-linecap="round" stroke-linejoin="round" stroke-width="2"></circle> <line fill="none" stroke="#B46266" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" x1="12" x2="12" y1="12" y2="16"></line> <line fill="none" stroke="#B46266" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" x1="12" x2="12" y1="8" y2="8"></line> </g> </g> </g> </g></svg>
</label>
-->
</div>
<!-- End Column -->
<!-- Start Column -->
<div
class="hidden sm:block relative m-auto mb-5 mt-5 sm:mb-0 sm:mt-0"
>
<svg
class="w-40 -my-5"
viewBox="0 0 200 200"
xmlns="http://www.w3.org/2000/svg"
>
<defs>
<filter id="glow">
<feGaussianBlur stdDeviation="5" result="glow" />
<feMerge>
<feMergeNode in="glow" />
<feMergeNode in="SourceGraphic" />
</feMerge>
</filter>
</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)"
/>
</svg>
<div class="z-1 absolute top-0">
<img class="w-24 ml-9" src={logo} alt="logo" loading="lazy" />
</div>
</div>
<!-- End Column -->
</div>
</div>
<div
class="w-full mt-10 m-auto mb-10 bg-default pl-3 pr-3 overflow-hidden"
>
<!--Start Top Winners/Losers-->
<div class="flex flex-col justify-center items-center">
<div class="ml-4 text-start w-full text-white mb-2">
<span class="font-bold text-2xl">
{rawData?.length} Cryptos
</span>
</div>
<div class="border-b mt-2 border-blue-400 w-full mb-4" />
<div class="w-full overflow-x-scroll">
<table
class="mt-5 table table-sm table-compact rounded-none sm:rounded-md w-full bg-table border border-gray-800 m-auto"
>
<thead>
<tr>
<th
class="text-white font-medium text-sm sm:text-[1rem] text-start"
>Symbol</th
>
<th class="text-white font-medium text-sm sm:text-[1rem]"
>Name</th
>
<th
class="text-white font-medium text-end text-sm sm:text-[1rem]"
>MarketCap</th
>
<th
class="text-white font-medium text-end text-sm sm:text-[1rem]"
>Circulating Supply</th
>
<th
class="text-white font-medium text-end text-sm sm:text-[1rem]"
>Max Supply</th
>
</tr>
</thead>
<tbody>
{#each symbolList as item, index}
<tr
on:click={() => goto("/crypto/" + item?.symbol)}
class="sm:hover:bg-[#245073] sm:hover:bg-opacity-[0.2] odd:bg-odd border-b-[#09090B] shake-ticker cursor-pointer"
>
<td
class="text-blue-400 font-medium text-sm text-start border-b-[#09090B]"
>
{item?.symbol}
</td>
<td
class="text-white whitespace-nowrap text-sm sm:text-[1rem] border-b-[#09090B]"
>
{item?.name?.length > charNumber
? item?.name?.slice(0, charNumber) + "..."
: item?.name}
</td>
<td
class="text-white text-end text-sm sm:text-[1rem] border-b-[#09090B]"
>
{item?.marketCap !== null
? abbreviateNumber(item?.marketCap, true)
: "-"}
</td>
<td
class="text-white border-b-[#09090B] text-end text-sm sm:text-[1rem]"
>
{item?.circulatingSupply !== null
? abbreviateNumber(item?.circulatingSupply, true)
: "-"}
</td>
<td
class="text-white border-b-[#09090B] text-end text-sm sm:text-[1rem]"
>
{item?.maxSupply !== "Uncapped"
? abbreviateNumber(item?.maxSupply, true)
: "Uncapped"}
</td>
</tr>
{/each}
</tbody>
</table>
</div>
</div>
</div>
</main>
<aside class="hidden lg:block relative fixed w-1/4 ml-4">
{#if data?.user?.tier !== "Pro" || data?.user?.freeTrial}
<div
on:click={() => goto("/pricing")}
class="w-full text-white border border-gray-600 rounded-md h-fit pb-4 mt-4 cursor-pointer bg-primary sm:hover:bg-secondary transition ease-out duration-100"
>
<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">
<h2 class="text-start text-xl font-semibold text-white ml-3">
Pro Subscription 🔥
</h2>
<ArrowLogo class="w-8 h-8 mr-3 flex-shrink-0" />
</div>
<span class="text-white p-3 ml-3 mr-3">
Upgrade now for unlimited access to all data and tools
</span>
</div>
</div>
{/if}
<div
on:click={() => goto("/analysts")}
class="w-full text-white border border-gray-600 rounded-md h-fit pb-4 mt-4 cursor-pointer bg-primary sm:hover:bg-secondary transition ease-out duration-100"
>
<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">
<h2 class="text-start text-xl font-semibold text-white ml-3">
Top Analyst 📊
</h2>
<ArrowLogo class="w-8 h-8 mr-3 flex-shrink-0" />
</div>
<span class="text-white p-3 ml-3 mr-3">
Get the latest top Wall Street analyst ratings
</span>
</div>
</div>
<div
on:click={() => goto("/analysts/top-stocks")}
class="w-full text-white border border-gray-600 rounded-md h-fit pb-4 mt-4 cursor-pointer bg-primary sm:hover:bg-secondary transition ease-out duration-100"
>
<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">
<h2 class="text-start text-xl font-semibold text-white ml-3">
Top Stocks Picks ⭐
</h2>
<ArrowLogo class="w-8 h-8 mr-3 flex-shrink-0" />
</div>
<span class="text-white p-3 ml-3 mr-3">
Get the latest top Wall Street analyst ratings.
</span>
</div>
</div>
</aside>
</div>
</div>
</div>
</section>

View File

@ -1,88 +0,0 @@
export const config = {
runtime: "nodejs20.x",
};
let companyName;
const fetchData = async (apiURL, apiKey, endpoint, ticker) => {
const postData = {
ticker: ticker,
};
const response = await fetch(apiURL + endpoint, {
method: "POST",
headers: {
"Content-Type": "application/json",
"X-API-KEY": apiKey,
},
body: JSON.stringify(postData),
});
const output = await response.json();
if (endpoint === "/crypto-profile") {
companyName = output?.name;
}
return output;
};
const fetchWatchlist = async (pb, userId) => {
let output;
try {
output = await pb.collection("watchlist").getFullList({
filter: `user="${userId}"`,
});
} catch (e) {
//console.log(e)
output = [];
}
return output;
};
/*
async function fetchPortfolio(fastifyURL, userId)
{
const postData = {'userId': userId};
const response = await fetch(fastifyURL+'/get-portfolio-data', {
method: 'POST',
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify(postData)
});
const output = (await response.json())?.items;
return output
}
*/
export const load = async ({ params, locals, setHeaders }) => {
const { apiURL, apiKey, pb, user } = locals;
const promises = [
fetchData(apiURL, apiKey, "/crypto-profile", params.tickerID),
fetchData(apiURL, apiKey, "/stock-quote", params.tickerID),
fetchData(apiURL, apiKey, "/one-day-price", params.tickerID),
fetchWatchlist(pb, user?.id),
//fetchPortfolio(fastifyURL, locals?.user?.id)
];
const [getCryptoProfile, getStockQuote, getOneDayPrice, getUserWatchlist] =
await Promise.all(promises);
setHeaders({
"cache-control": "public, max-age=300",
});
return {
getCryptoProfile,
getStockQuote,
getOneDayPrice,
getUserWatchlist,
companyName,
getParams: params.tickerID,
};
};

File diff suppressed because it is too large Load Diff

View File

@ -1,146 +0,0 @@
import { error, fail, redirect } from "@sveltejs/kit";
import { validateData } from "$lib/utils";
import { loginUserSchema, registerUserSchema } from "$lib/schemas";
export const actions = {
login: async ({ request, locals }) => {
const { formData, errors } = await validateData(
await request.formData(),
loginUserSchema,
);
if (errors) {
return fail(400, {
data: formData,
errors: errors.fieldErrors,
});
}
try {
await locals.pb
.collection("users")
.authWithPassword(formData.email, formData.password);
/*
if (!locals.pb?.authStore?.model?.verified) {
locals.pb.authStore.clear();
return {
notVerified: true,
};
}
*/
} catch (err) {
console.log("Error: ", err);
error(err.status, err.message);
}
redirect(302, "/");
},
register: async ({ locals, request }) => {
const { formData, errors } = await validateData(
await request.formData(),
registerUserSchema,
);
if (errors) {
return fail(400, {
data: formData,
errors: errors.fieldErrors,
});
}
try {
let newUser = await locals.pb.collection("users").create(formData);
/*
await locals.pb?.collection('users').update(
newUser?.id, {
'freeTrial' : true,
'tier': 'Pro', //Give new users a free trial for the Pro Subscription
});
*/
await locals.pb.collection("users").requestVerification(formData.email);
} catch (err) {
console.log("Error: ", err);
error(err.status, err.message);
}
try {
await locals.pb
.collection("users")
.authWithPassword(formData.email, formData.password);
} catch (err) {
console.log("Error: ", err);
error(err.status, err.message);
}
redirect(303, "/");
},
oauth2: async ({ url, locals, request, cookies }) => {
const authMethods = (await locals?.pb
?.collection("users")
?.listAuthMethods())?.oauth2;
const data = await request?.formData();
const providerSelected = data?.get("provider");
if (!authMethods) {
return {
authProviderRedirect: "",
authProviderState: "",
};
}
const redirectURL = `${url.origin}/oauth`;
const targetItem = authMethods?.providers?.findIndex(
(item) => item?.name === providerSelected,
);
//console.log("==================")
//console.log(authMethods.authProviders)
//console.log('target item is: ', targetItem)
const provider = authMethods.providers[targetItem];
const authProviderRedirect = `${provider.authUrl}${redirectURL}`;
const state = provider.state;
const verifier = provider.codeVerifier;
cookies.set("state", state, {
httpOnly: true,
sameSite: "lax",
secure: true,
path: "/",
maxAge: 60 * 60,
});
cookies.set("verifier", verifier, {
httpOnly: true,
sameSite: "lax",
secure: true,
path: "/",
maxAge: 60 * 60,
});
cookies.set("provider", providerSelected, {
httpOnly: true,
sameSite: "lax",
secure: true,
path: "/",
maxAge: 60 * 60,
});
cookies.set("path", "/", {
httpOnly: true,
sameSite: "lax",
secure: true,
path: "/",
maxAge: 60,
});
redirect(302, authProviderRedirect);
},
};

File diff suppressed because it is too large Load Diff

View File

@ -1,28 +0,0 @@
export const load = async ({ locals, params }) => {
const getSenateTrading = async () => {
const { apiKey, apiURL } = locals;
const postData = {
ticker: params.tickerID,
};
// make the POST request to the endpoint
const response = await fetch(apiURL + "/congress-trading-ticker", {
method: "POST",
headers: {
"Content-Type": "application/json",
"X-API-KEY": apiKey,
},
body: JSON.stringify(postData),
});
const output = await response.json();
return output;
};
// Make sure to return a promise
return {
getSenateTrading: await getSenateTrading(),
};
};

View File

@ -1,607 +0,0 @@
<script lang="ts">
import { onMount } from "svelte";
import {
displayCompanyName,
numberOfUnreadNotification,
cryptoTicker,
} from "$lib/store";
import republicanBackground from "$lib/images/bg-republican.png";
import democraticBackground from "$lib/images/bg-democratic.png";
import otherBackground from "$lib/images/bg-other.png";
import { getPartyForPoliticians } from "$lib/utils";
export let data;
let rawData = data?.getSenateTrading;
let buySellRatio = 0;
let partyRatio = 0;
let senateTradingList = [];
let displayStructure = "Card";
let isLoaded = false;
let cloudFrontUrl = import.meta.env.VITE_IMAGE_URL;
function backToTop() {
window.scrollTo({
top: 0,
});
}
function changeStructure() {
if (displayStructure === "Card") {
displayStructure = "Table";
} else {
displayStructure = "Card";
}
}
const district = {
Tommy_Tuberville: "Alabama",
Sheldon_Whitehouse: "Rhode Island",
Pat_Toomey: "Pennsylvania",
Tom_Carper: "Delaware",
Pat_Roberts: "Kansas",
Markwayne_Mullin: "Oklahoma",
Shelley_Capito: "West Virginia",
Jerry_Moran: "Kansas",
Dan_Sullivan: "Alaska",
Ron_Wyden: "Oregon",
John_Hickenlooper: "Colorado",
David_Perdue: "Georgia",
Kelly_Loeffler: "Georgia",
Bill_Cassidy: "Louisiana",
};
async function handleScroll() {
const scrollThreshold = document.body.offsetHeight * 0.8; // 80% of the website height
const isBottom = window.innerHeight + window.scrollY >= scrollThreshold;
if (isBottom && senateTradingList?.length !== rawData?.length) {
const nextIndex = senateTradingList?.length;
const filteredNewResults = rawData?.slice(nextIndex, nextIndex + 25);
senateTradingList = [...senateTradingList, ...filteredNewResults];
}
}
onMount(async () => {
rawData.forEach((item) => {
const representative = item?.representative || "";
const fullName = representative
.replace(/(\s(?:Dr\s)?\w(?:\.|(?=\s)))?\s/g, "_")
.trim();
item.representative = fullName.replace(/_/g, " ");
});
rawData = rawData?.map((item) => {
const party = getPartyForPoliticians(item?.representative);
return {
...item,
party: party,
};
});
// Count the occurrences of "Republican" and "Democrat"
const partyCounts = rawData.reduce((counts, item) => {
counts[item?.party] = (counts[item?.party] || 0) + 1;
return counts;
}, {});
const typeCounts = rawData.reduce((counts, item) => {
counts[item?.type] = (counts[item?.type] || 0) + 1;
return counts;
}, {});
partyRatio =
partyCounts["Democratic"] > 0 && partyCounts["Republican"] === undefined
? 1
: partyCounts["Democratic"] === undefined
? 0
: partyCounts["Democratic"] / partyCounts["Republican"];
buySellRatio =
typeCounts["Bought"] > 0 && typeCounts["Sold"] === undefined
? 1
: typeCounts["Bought"] === undefined
? 0
: typeCounts["Bought"] / typeCounts["Sold"];
senateTradingList = rawData.slice(0, 20) ?? [];
isLoaded = true;
if (data?.user?.tier === "Pro") {
window.addEventListener("scroll", handleScroll);
return () => {
window.removeEventListener("scroll", handleScroll);
};
}
});
</script>
<svelte:head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width" />
<title>
{$numberOfUnreadNotification > 0 ? `(${$numberOfUnreadNotification})` : ""}
{$displayCompanyName} ({$cryptoTicker}) US Congress & Senate Trading ·
stocknear
</title>
<meta
name="description"
content={`Get the latest US congress & senate trading of ${$displayCompanyName} (${$cryptoTicker}) from democrates and republicans.`}
/>
<!-- Other meta tags -->
<meta
property="og:title"
content={`${$displayCompanyName} (${$cryptoTicker}) US Congress & Senate Trading · Stocknear`}
/>
<meta
property="og:description"
content={`Get the latest US congress & senate trading of ${$displayCompanyName} (${$cryptoTicker}) from democrates and republicans.`}
/>
<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={`${$displayCompanyName} (${$cryptoTicker}) US Congress & Senate Trading · Stocknear`}
/>
<meta
name="twitter:description"
content={`Get the latest US congress & senate trading of ${$displayCompanyName} (${$cryptoTicker}) from democrates and republicans.`}
/>
<!-- Add more Twitter meta tags as needed -->
</svelte:head>
<section
class="w-full bg-default overflow-hidden text-white h-full mb-40 sm:mb-0"
>
<div class="h-full overflow-hidden">
<div class="relative flex justify-center items-center overflow-hidden">
<div class="sm:p-7 w-full mt-2 sm:mt-0">
<div class="mb-6">
<h1 class="text-xl sm:text-2xl text-white font-bold mb-4">
Congress Trading
</h1>
<div
class="text-white p-3 sm:p-5 mb-10 rounded-md sm:flex sm:flex-row sm:items-center border border-gray-600 text-sm sm:text-[1rem]"
>
<svg
class="w-6 h-6 flex-shrink-0 inline-block sm:mr-2"
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 256 256"
><path
fill="#fff"
d="M128 24a104 104 0 1 0 104 104A104.11 104.11 0 0 0 128 24m-4 48a12 12 0 1 1-12 12a12 12 0 0 1 12-12m12 112a16 16 0 0 1-16-16v-40a8 8 0 0 1 0-16a16 16 0 0 1 16 16v40a8 8 0 0 1 0 16"
/></svg
>
Get detailed insights of Corrupt US Politician 🇺🇸 who bought or sold
{$displayCompanyName} and the amounts involved!
</div>
</div>
{#if isLoaded}
{#if senateTradingList?.length !== 0}
<h3 class="text-white text-xl font-semibold pt-5">
Congress Statistics
</h3>
<!--Start Widget-->
<div
class="w-full mt-5 mb-10 m-auto flex justify-center items-center"
>
<div
class="w-full grid grid-cols-2 sm:grid-cols-3 gap-y-3 lg:gap-y-3 gap-x-3"
>
<!--Start Buy/Sell-->
<div
class="flex flex-row items-center flex-wrap w-full px-3 sm:px-4 bg-[#262626] shadow-lg rounded-md h-20"
>
<div class="flex flex-col items-start">
<span
class="font-semibold text-gray-200 text-sm sm:text-[1rem]"
>Buy/Sell</span
>
<span
class="text-start text-sm sm:text-[1rem] font-medium text-white"
>
{buySellRatio?.toFixed(3)}
</span>
</div>
<!-- Circular Progress -->
<div class="relative size-14 ml-auto">
<svg
class="size-full w-14 h-14"
viewBox="0 0 36 36"
xmlns="http://www.w3.org/2000/svg"
>
<!-- Background Circle -->
<circle
cx="18"
cy="18"
r="16"
fill="none"
class="stroke-current text-[#3E3E3E]"
stroke-width="3"
></circle>
<!-- Progress Circle inside a group with rotation -->
<g class="origin-center -rotate-90 transform">
<circle
cx="18"
cy="18"
r="16"
fill="none"
class="stroke-current {buySellRatio >= 0.5
? 'text-[#00FC50]'
: 'text-[#EE5365]'} "
stroke-width="3"
stroke-dasharray="100"
stroke-dashoffset={100 - buySellRatio * 100 >= 0
? 100 - (buySellRatio * 100)?.toFixed(2)
: 0}
></circle>
</g>
</svg>
<!-- Percentage Text -->
<div
class="absolute top-1/2 start-1/2 transform -translate-y-1/2 -translate-x-1/2"
>
<span
class="text-center text-white text-sm sm:text-[1rem]"
>{buySellRatio?.toFixed(2)}</span
>
</div>
</div>
<!-- End Circular Progress -->
</div>
<!--End Buy/Sell-->
<!--Start Dem/Rep-->
<div
class="flex flex-row items-center flex-wrap w-full px-3 sm:px-4 bg-[#262626] shadow-lg rounded-md h-20"
>
<div class="flex flex-col items-start">
<span
class="font-semibold text-gray-200 text-sm sm:text-[1rem]"
>Dem/Rep</span
>
<span
class="text-start text-sm sm:text-[1rem] font-medium text-white"
>
{partyRatio?.toFixed(3)}
</span>
</div>
<!-- Circular Progress -->
<div class="relative size-14 ml-auto">
<svg
class="size-full w-14 h-14"
viewBox="0 0 36 36"
xmlns="http://www.w3.org/2000/svg"
>
<!-- Background Circle -->
<circle
cx="18"
cy="18"
r="16"
fill="none"
class="stroke-current text-[#3E3E3E]"
stroke-width="3"
></circle>
<!-- Progress Circle inside a group with rotation -->
<g class="origin-center -rotate-90 transform">
<circle
cx="18"
cy="18"
r="16"
fill="none"
class="stroke-current text-blue-500"
stroke-width="3"
stroke-dasharray="100"
stroke-dashoffset={100 - partyRatio * 100 >= 0
? 100 - (partyRatio * 100)?.toFixed(2)
: 0}
></circle>
</g>
</svg>
<!-- Percentage Text -->
<div
class="absolute top-1/2 start-1/2 transform -translate-y-1/2 -translate-x-1/2"
>
<span
class="text-center text-white text-sm sm:text-[1rem]"
>{partyRatio?.toFixed(2)}</span
>
</div>
</div>
<!-- End Circular Progress -->
</div>
<!--End Put/Call-->
</div>
</div>
<!--End Widget-->
<label
on:click={changeStructure}
class="sm:hidden w-24 sm:ml-3 mr-2 sm:mr-0 cursor-pointer bg-primary px-4 py-2 rounded-md shadow-md"
>
<span class="m-auto mr-0.5 text-white text-sm">
Switch To: {displayStructure}
</span>
</label>
{#if displayStructure === "Card"}
<div
class="mt-6 flex justify-start items-center w-full m-auto rounded-none sm:rounded-md mb-4 overflow-x-scroll"
>
<table
class="table table-sm sm:table-md table-compact rounded-none sm:rounded-md w-full bg-table border border-gray-800 m-auto"
>
<thead>
<tr class="bg-default">
<th
class="shadow-md text-start bg-default text-white text-sm font-semibold"
>
Person
</th>
<th
class="shadow-md text-end bg-default text-white text-sm font-semibold"
>
Transaction Date
</th>
<th
class="shadow-md text-end bg-default text-white text-sm font-semibold"
>
Amount
</th>
<th
class="shadow-md text-white font-semibold text-end text-sm"
>Type</th
>
</tr>
</thead>
<tbody>
{#each senateTradingList as item}
<tr
class="odd:bg-odd sm:hover:bg-[#245073] sm:hover:bg-opacity-[0.2] bg-default border-b-[#09090B]"
>
<td
class="text-white text-sm sm:text-[1rem] whitespace-nowrap pb-3 border-b border-b-[#09090B]"
>
<div class="flex flex-row items-center">
<div
class="flex-shrink-0 rounded-full border border-slate-700 w-10 h-10 sm:w-12 sm:h-12 relative {item?.party ===
'Republican'
? 'bg-[#98272B]'
: item?.party === 'Democratic'
? 'bg-[#295AC7]'
: 'bg-[#4E2153]'} flex items-center justify-center"
>
<img
style="clip-path: circle(50%);"
class="avatar rounded-full w-7 sm:w-9"
src={`${cloudFrontUrl}/assets/senator/${item?.representative?.replace(/\s+/g, "_")}.png`}
loading="lazy"
/>
</div>
<div class="flex flex-col ml-3">
<a
href={`/politicians/${item?.id}`}
class="sm:hover:text-white text-blue-400"
>{item?.representative?.replace("_", " ")}</a
>
<span class="">{item?.party}</span>
</div>
</div>
<!--{item?.firstName} {item?.lastName}-->
</td>
<td
class="text-end text-sm sm:text-[1rem] whitespace-nowrap text-white border-b border-b-[#09090B]"
>
{new Date(item?.transactionDate)?.toLocaleString(
"en-US",
{
month: "short",
day: "numeric",
year: "numeric",
daySuffix: "2-digit",
},
)}
</td>
<td
class="text-end text-sm sm:text-[1rem] whitespace-nowrap text-white border-b border-b-[#09090B]"
>
{item?.amount}
</td>
<td
class="text-end text-sm sm:text-[1rem] whitespace-nowrap text-white border-b border-b-[#09090B]"
>
{#if item?.type === "Bought"}
<span class="text-[#00FC50]">Bought</span>
{:else if item?.type === "Sold"}
<span class="text-[#FF2F1F]">Sold</span>
{:else if item?.type === "Exchange"}
<span class="text-[#C6A755]">Exchange</span>
{/if}
</td>
</tr>
{/each}
</tbody>
</table>
</div>
{:else}
<div class="relative w-full mt-10">
{#each senateTradingList as item}
<div
class="w-full bg-default border border-gray-600 shadow-lg h-auto pb-4 pt-4 mb-7"
>
<div class="flex flex-col relative">
{#if item?.party === "Republican"}
<img
class="absolute -mt-4 w-full m-auto"
src={republicanBackground}
/>
{:else if item?.party === "Democratic"}
<img
class="absolute -mt-4 w-[500px] m-auto"
src={democraticBackground}
/>
{:else}
<img
class="absolute -mt-4 w-[500px] m-auto"
src={otherBackground}
/>
{/if}
<div
class="flex flex-col justify-center items-center rounded-md"
>
<div
class="-mt-3 shadow-lg rounded-full border border-slate-600 w-20 h-20 relative {item?.party ===
'Republican'
? 'bg-[#98272B]'
: item?.party === 'Democratic'
? 'bg-[#295AC7]'
: 'bg-[#20202E]'} flex items-center justify-center"
>
<img
style="clip-path: circle(50%);"
class="rounded-full w-16"
src={`${cloudFrontUrl}/assets/senator/${item?.representative?.replace(/\s+/g, "_")}.png`}
loading="lazy"
/>
</div>
<span class="text-white text-lg font-medium mt-2 mb-2">
{item?.representative?.replace("_", " ")}
</span>
<span class="text-white text-md mb-8">
{item?.party ?? "n/a"} / {district[
item?.representative
] ?? "n/a"}
</span>
</div>
<div class="flex flex-row items-center pr-4 pl-4">
<div class="flex flex-col justify-start items-start">
<span class="font-medium text-white">Owner</span>
<span
class="text-white text-opacity-[0.8] text-sm text-end"
>
{item?.owner?.length !== 0 ? item?.owner : "-"}
</span>
</div>
</div>
<div
class="border-1 border-b border-gray-600 w-full mt-5 mb-5"
/>
<div class="flex flex-row items-center pr-4 pl-4">
<div class="flex flex-col w-40">
<span class="font-medium text-white"
>Transaction Date</span
>
<span class="text-slate-300 text-sm">
{new Date(item?.transactionDate)?.toLocaleString(
"en-US",
{
month: "short",
day: "numeric",
year: "numeric",
daySuffix: "2-digit",
},
)}
</span>
</div>
<div
class="flex flex-col justify-end items-end ml-auto"
>
<span class="font-medium text-white"
>Disclosure Date</span
>
<span
class="text-white text-opacity-[0.8] text-sm text-end"
>
{new Date(item?.disclosureDate)?.toLocaleString(
"en-US",
{
month: "short",
day: "numeric",
year: "numeric",
daySuffix: "2-digit",
},
)}
</span>
</div>
</div>
<div
class="border-1 border-b border-gray-600 w-full mt-5 mb-5"
/>
<div class="flex flex-row items-center pr-4 pl-4">
<div class="flex flex-col w-40">
<span class="font-medium text-white">Amount</span>
<span class="text-slate-300 text-sm font-medium">
{item?.amount?.replace(
"$1,000,001 - $5,000,000",
"$1Mio - $5Mio",
)}
</span>
</div>
<div
class="flex flex-col justify-end items-end ml-auto"
>
<span class="font-medium text-slate-300 text-ends"
>Type</span
>
<span class="text-white font-medium text-end">
{#if item?.type === "Bought"}
<span class="text-[#00FC50]">Bought</span>
{:else if item?.type === "Sold"}
<span class="text-[#FF2F1F]">Sold</span>
{:else if item?.type === "Exchange"}
<span class="text-[#C6A755]">Exchange</span>
{/if}
</span>
</div>
</div>
</div>
</div>
{/each}
</div>
{#if rawData?.length >= 20}
<label
on:click={backToTop}
class="w-32 py-1.5 mt-10 hover:bg-white hover:bg-opacity-[0.05] cursor-pointer m-auto flex justify-center items-center border border-gray-600 rounded-full"
>
Back to top
</label>
{/if}
{/if}
{:else}
<h2
class="pl-4 pr-4 flex justify-center items-center text-md sm:text-lg text-center text-slate-200"
>
No trading history available for {$displayCompanyName}. Likely no
corrupt politican has interest in this stock.
</h2>
{/if}
{:else}
<div class="flex justify-center items-center h-80">
<div class="relative">
<label
class="bg-secondary rounded-md 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>
</div>
</div>
{/if}
</div>
</div>
</div>
</section>

View File

@ -1,85 +0,0 @@
<script lang="ts">
import { stockTicker, screenWidth } from "$lib/store";
import { onDestroy } from "svelte";
import { page } from "$app/stores";
let displaySubSection = "overview";
if (displaySubSection) {
const parts = $page?.url?.pathname.split("/");
const sectionMap = {
overview: "overview",
ai: "ai",
analyst: "analyst",
};
const foundSection = parts?.find((part) =>
Object?.values(sectionMap)?.includes(part),
);
displaySubSection =
Object?.keys(sectionMap)?.find(
(key) => sectionMap[key] === foundSection,
) || "overview";
}
function changeSubSection(state) {
const subSectionMap = {
overview: "/forecast",
ai: "/forecast/ai",
analyst: "/forecast/analyst",
};
if (state !== "overview" && subSectionMap[state]) {
displaySubSection = state;
//goto(`/stocks/${$stockTicker}${subSectionMap[state]}`);
} else {
displaySubSection = state;
//goto(`/stocks/${$stockTicker}/stats`);
}
}
const unsubscribe = page.subscribe(($page) => {
const splitRoute = $page.url.pathname.split("/");
const routeState =
splitRoute[splitRoute.length - 1] !== "forecast"
? splitRoute[splitRoute.length - 1]
: "overview";
changeSubSection(routeState);
});
onDestroy(() => {
unsubscribe();
});
</script>
<section
class="w-auto max-w-5xl bg-default overflow-hidden text-black h-full mb-40"
>
<div class="m-auto h-full overflow-hidden">
<slot />
</div>
</section>
<style>
.scrollbar {
display: grid;
grid-gap: 18px;
grid-template-columns: repeat(auto-fill, minmax(90px, 1fr));
grid-auto-flow: column;
overflow-x: auto;
scrollbar-width: thin; /* Hide the default scrollbar in Firefox */
scrollbar-color: transparent transparent; /* Hide the default scrollbar in Firefox */
}
/* Custom scrollbar for Webkit (Chrome, Safari) */
.scrollbar::-webkit-scrollbar {
width: 0; /* Hide the width of the scrollbar */
height: 0; /* Hide the height of the scrollbar */
}
.scrollbar::-webkit-scrollbar-thumb {
background: transparent; /* Make the thumb transparent */
}
</style>

View File

@ -1,54 +0,0 @@
export const load = async ({ locals, params }) => {
const { apiURL, apiKey } = locals;
const postData = {
ticker: params.tickerID,
};
const getAnalystInsight = async () => {
const response = await fetch(apiURL + "/analyst-insight", {
method: "POST",
headers: {
"Content-Type": "application/json",
"X-API-KEY": apiKey,
},
body: JSON.stringify(postData),
});
const output = await response.json();
return output;
};
const getPriceAnalysis = async () => {
const response = await fetch(apiURL + "/price-analysis", {
method: "POST",
headers: {
"Content-Type": "application/json",
"X-API-KEY": apiKey,
},
body: JSON.stringify(postData),
});
const output = await response.json();
return output;
};
const getSentimentAnalysis = async () => {
const response = await fetch(apiURL + "/sentiment-analysis", {
method: "POST",
headers: {
"Content-Type": "application/json",
"X-API-KEY": apiKey,
},
body: JSON.stringify(postData),
});
const output = await response.json();
return output;
};
// Make sure to return a promise
return {
getAnalystInsight: await getAnalystInsight(),
getPriceAnalysis: await getPriceAnalysis(),
getSentimentAnalysis: await getSentimentAnalysis(),
};
};

View File

@ -1,100 +0,0 @@
<script lang="ts">
import {
numberOfUnreadNotification,
displayCompanyName,
stockTicker,
sentimentComponent,
priceAnalysisComponent,
} from "$lib/store";
import PriceAnalysis from "$lib/components/PriceAnalysis.svelte";
import SentimentAnalysis from "$lib/components/SentimentAnalysis.svelte";
import AnalystInsight from "$lib/components/AnalystInsight.svelte";
import Lazy from "$lib/components/Lazy.svelte";
export let data;
</script>
<svelte:head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width" />
<title>
{$numberOfUnreadNotification > 0 ? `(${$numberOfUnreadNotification})` : ""}
{$displayCompanyName} ({$stockTicker}) Forecast AI · Stocknear
</title>
<meta
name="description"
content={`A list of analyst ratings for Advanced Micro Devices (AMD) stock. See upgrades, downgrades, price targets and more from top Wall Street stock analysts.`}
/>
<!-- Other meta tags -->
<meta
property="og:title"
content={`${$displayCompanyName} (${$stockTicker}) Forecast AI · Stocknear`}
/>
<meta
property="og:description"
content={`A list of analyst ratings for Advanced Micro Devices (AMD) stock. See upgrades, downgrades, price targets and more from top Wall Street stock analysts.`}
/>
<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={`${$displayCompanyName} (${$stockTicker}) Forecast AI · Stocknear`}
/>
<meta
name="twitter:description"
content={`A list of analyst ratings for Advanced Micro Devices (AMD) stock. See upgrades, downgrades, price targets and more from top Wall Street stock analysts.`}
/>
<!-- Add more Twitter meta tags as needed -->
</svelte:head>
<section
class="bg-default overflow-hidden text-white h-full mb-40 sm:mb-0 w-full"
>
<div class="flex justify-center m-auto h-full overflow-hidden w-full">
<div
class="relative flex justify-center items-center overflow-hidden w-full"
>
<div class="sm:p-7 w-full m-auto mt-2 sm:mt-0">
<Lazy>
<div
class="w-full mt-10 sm:mt-0 m-auto sm:pt-6 {Object?.keys(
data?.getAnalystInsight,
)?.length === 0
? 'hidden'
: ''}"
>
<AnalystInsight {data} />
</div>
</Lazy>
<Lazy>
<div
class="w-full mt-10 sm:mt-5 m-auto sm:pb-6 sm:pt-6 {Object?.keys(
data?.getPriceAnalysis,
)?.length === 0
? 'hidden'
: ''}"
>
<PriceAnalysis {data} />
</div>
</Lazy>
<Lazy>
<div
class="w-full mt-10 sm:mt-5 m-auto sm:pb-6 sm:pt-6 {data
?.getSentimentAnalysis?.length === 0
? 'hidden'
: ''}"
>
<SentimentAnalysis {data} />
</div>
</Lazy>
</div>
</div>
</div>
</section>

View File

@ -1,28 +0,0 @@
export const load = async ({ locals, params }) => {
const getStockNews = async () => {
const { apiKey, apiURL } = locals;
const postData = {
ticker: params.tickerID,
};
// make the POST request to the endpoint
const response = await fetch(apiURL + "/stock-news", {
method: "POST",
headers: {
"Content-Type": "application/json",
"X-API-KEY": apiKey,
},
body: JSON.stringify(postData),
});
const output = await response.json();
return output;
};
// Make sure to return a promise
return {
getStockNews: await getStockNews(),
};
};

View File

@ -1,192 +0,0 @@
<script lang="ts">
import {
numberOfUnreadNotification,
displayCompanyName,
cryptoTicker,
} from "$lib/store";
export let data;
const formatDate = (dateString) => {
// Create a date object for the input dateString
const inputDate = new Date(dateString);
// Create a date object for the current time in New York City
const nycTime = new Date().toLocaleString("en-US", {
timeZone: "America/New_York",
});
const currentNYCDate = new Date(nycTime);
// Calculate the difference in milliseconds
const difference = inputDate.getTime() - currentNYCDate.getTime();
// Convert the difference to minutes
const minutes = Math.abs(Math.round(difference / (1000 * 60)));
if (minutes < 60) {
return `${minutes} minutes`;
} else if (minutes < 1440) {
const hours = Math.round(minutes / 60);
return `${hours} hour${hours !== 1 ? "s" : ""}`;
} else {
const days = Math.round(minutes / 1440);
return `${days} day${days !== 1 ? "s" : ""}`;
}
};
let rawNews = data?.getStockNews;
let newsList = rawNews?.slice(0, 20) ?? [];
let videoId = null;
function checkIfYoutubeVideo(link) {
const url = new URL(link);
if (url?.hostname === "www.youtube.com") {
const searchParams = url.searchParams;
searchParams.delete("t"); // Remove the "t" parameter
const videoIdMatch = url?.search?.match(/v=([^&]+)/);
if (videoIdMatch) {
return videoIdMatch[1];
}
} else {
return null;
}
}
function loadMoreData() {
const nextIndex = newsList?.length;
const newArticles = rawNews?.slice(nextIndex, nextIndex + 20);
newsList = [...newsList, ...newArticles];
}
</script>
<svelte:head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width" />
<title>
{$numberOfUnreadNotification > 0 ? `(${$numberOfUnreadNotification})` : ""}
{$displayCompanyName} ({$cryptoTicker}) latest Stock Market News and
Breaking Stories · Stocknear
</title>
<meta
name="description"
content={`Get the latest stock market news and breaking stories of ${$displayCompanyName} (${$cryptoTicker}).`}
/>
<!-- Other meta tags -->
<meta
property="og:title"
content={`${$displayCompanyName} (${$cryptoTicker}) latest Stock Market News and Breaking Stories · Stocknear`}
/>
<meta
property="og:description"
content={`Get the latest stock market news and breaking stories of ${$displayCompanyName} (${$cryptoTicker}).`}
/>
<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={`${$displayCompanyName} (${$cryptoTicker}) latest Stock Market News and Breaking Stories · Stocknear`}
/>
<meta
name="twitter:description"
content={`Get the latest stock market news and breaking stories of ${$displayCompanyName} (${$cryptoTicker}).`}
/>
<!-- Add more Twitter meta tags as needed -->
</svelte:head>
<section
class="w-auto max-w-4xl bg-default overflow-hidden text-black h-full mb-40"
>
<div class="m-auto h-full overflow-hidden">
<main class="">
<div class="sm:p-7 m-auto mt-2 sm:mt-0">
<div class="mb-6">
<h1 class="text-2xl sm:text-3xl text-white font-bold">News</h1>
</div>
{#if newsList?.length !== 0}
<div class="grid grid-cols-1 gap-2 pb-5">
{#each newsList as item}
<div class="w-full flex flex-col bg-default rounded-md m-auto">
{#if (videoId = checkIfYoutubeVideo(item.url))}
<iframe
class="w-full h-96 rounded-md border border-gray-800"
src={`https://www.youtube.com/embed/${videoId}`}
frameborder="0"
allow="clipboard-write; encrypted-media; gyroscope; picture-in-picture"
allowfullscreen
></iframe>
{:else}
<a
href={item?.url}
rel="noopener noreferrer"
target="_blank"
class="border border-gray-800 rounded-md"
>
<div class="flex-shrink-0 m-auto">
<img
src={item?.image}
class=" w-full rounded-md"
alt="news image"
loading="lazy"
/>
</div>
</a>
{/if}
<div class="mb-1 w-full">
<h3
class="text-sm sm:text-md text-white text-opacity-60 truncate mb-2 mt-3"
>
{item?.site} · {formatDate(item?.publishedDate)} ago
</h3>
<a
href={item?.url}
rel="noopener noreferrer"
target="_blank"
class="text-lg font-bold text-white"
>
{item?.title}
<p class="text-white text-sm mt-2 font-normal">
{item?.text}
</p>
</a>
</div>
</div>
<hr class="border-blue-400 w-full m-auto mt-5 mb-5" />
{/each}
</div>
{#if newsList?.length !== rawNews?.length}
<label
on:click={loadMoreData}
class="shadow-lg rounded-md cursor-pointer w-5/6 sm:w-3/5 sm:max-w-3xl flex justify-center items-center py-3 h-full text-sm sm:text-[1rem] text-center font-semibold text-white m-auto hover:bg-[#fff] bg-[#fff] bg-opacity-[0.6]"
>
Load More News
</label>
{/if}
{:else}
<div
class="w-screen max-w-xl sm:flex sm:flex-row sm:items-center justify-center m-auto text-gray-100 font-medium bg-default sm:rounded-md h-auto p-5 mb-4"
>
<svg
class="w-5 h-5 inline-block sm:mr-2 flex-shrink-0"
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 256 256"
><path
fill="#fff"
d="M128 24a104 104 0 1 0 104 104A104.11 104.11 0 0 0 128 24m-4 48a12 12 0 1 1-12 12a12 12 0 0 1 12-12m12 112a16 16 0 0 1-16-16v-40a8 8 0 0 1 0-16a16 16 0 0 1 16 16v40a8 8 0 0 1 0 16"
/></svg
>
No news article published yet!
</div>
{/if}
</div>
</main>
</div>
</section>

View File

@ -1,27 +0,0 @@
export const load = async ({ locals, params }) => {
const getQuantStats = async () => {
const { apiKey, apiURL } = locals;
const postData = {
ticker: params.tickerID,
};
// make the POST request to the endpoint
const response = await fetch(apiURL + "/get-quant-stats", {
method: "POST",
headers: {
"Content-Type": "application/json",
"X-API-KEY": apiKey,
},
body: JSON.stringify(postData),
});
const output = await response.json();
return output;
};
// Make sure to return a promise
return {
getQuantStats: await getQuantStats(),
};
};

File diff suppressed because it is too large Load Diff

View File

@ -1,28 +0,0 @@
export const load = async ({ locals, params }) => {
const getQuantStats = async () => {
const { apiKey, apiURL } = locals;
const postData = {
ticker: params.tickerID,
};
// make the POST request to the endpoint
const response = await fetch(apiURL + "/get-quant-stats", {
method: "POST",
headers: {
"Content-Type": "application/json",
"X-API-KEY": apiKey,
},
body: JSON.stringify(postData),
});
const output = await response.json();
return output;
};
// Make sure to return a promise
return {
getQuantStats: await getQuantStats(),
};
};

File diff suppressed because it is too large Load Diff