update notification page
This commit is contained in:
parent
6ba32d0979
commit
bd92a82458
25
src/routes/api/update-notification/+server.ts
Normal file
25
src/routes/api/update-notification/+server.ts
Normal file
@ -0,0 +1,25 @@
|
||||
import type { RequestHandler } from "./$types";
|
||||
|
||||
export const POST: RequestHandler = async ({ request, locals }) => {
|
||||
const data = await request.json();
|
||||
const { pb } = locals;
|
||||
|
||||
const notificationList = data?.unreadList;
|
||||
let output;
|
||||
|
||||
try {
|
||||
const itemsToUpdate = notificationList?.filter((item) => !item.readed);
|
||||
// Perform updates in parallel
|
||||
await Promise.all(
|
||||
itemsToUpdate.map((item) =>
|
||||
pb.collection("notifications").update(item, { readed: "true" }),
|
||||
),
|
||||
);
|
||||
|
||||
output = "success";
|
||||
} catch (e) {
|
||||
output = "failure";
|
||||
}
|
||||
|
||||
return new Response(JSON.stringify(output));
|
||||
};
|
||||
@ -1,22 +1,25 @@
|
||||
import { redirect, error } from "@sveltejs/kit";
|
||||
|
||||
export const load = async ({ locals }) => {
|
||||
if (!locals.pb.authStore.isValid) {
|
||||
const { pb, user } = locals;
|
||||
|
||||
if (!pb.authStore.isValid) {
|
||||
redirect(303, "/login");
|
||||
}
|
||||
|
||||
async function getNotifications() {
|
||||
const postData = { userId: locals?.user?.id };
|
||||
let output;
|
||||
|
||||
const response = await fetch(locals?.fastifyURL + "/get-notifications", {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
body: JSON.stringify(postData),
|
||||
});
|
||||
|
||||
const output = (await response.json())?.items;
|
||||
try {
|
||||
output = await pb.collection("notifications")?.getFullList({
|
||||
filter: `opUser="${user?.id}" `,
|
||||
expand: "user,post,comment",
|
||||
sort: "-created",
|
||||
});
|
||||
} catch (e) {
|
||||
console.log(e);
|
||||
output = [];
|
||||
}
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
@ -1,197 +1,215 @@
|
||||
<script lang='ts'>
|
||||
import {getImageURL, formatDate} from '$lib/utils';
|
||||
import { goto } from '$app/navigation';
|
||||
import InfiniteLoading from '$lib/components/InfiniteLoading.svelte';
|
||||
<script lang="ts">
|
||||
import { getImageURL, formatDate } from "$lib/utils";
|
||||
import ArrowLogo from "lucide-svelte/icons/move-up-right";
|
||||
import { goto } from "$app/navigation";
|
||||
import { onMount } from "svelte";
|
||||
import { numberOfUnreadNotification } from "$lib/store";
|
||||
import defaultAvatar from "$lib/images/default_avatar.png";
|
||||
|
||||
import { onMount } from 'svelte';
|
||||
import {numberOfUnreadNotification, scrollToComment } from '$lib/store';
|
||||
export let data;
|
||||
export let form;
|
||||
|
||||
export let data;
|
||||
export let form;
|
||||
let rawData = data?.getNotifications;
|
||||
let notificationList = rawData?.slice(0, 20);
|
||||
|
||||
let rawData = data?.getNotifications;
|
||||
let notificationList = rawData?.slice(0,20);
|
||||
|
||||
let isLoaded = false;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
async function updateNotifications()
|
||||
{
|
||||
|
||||
let notificationIdList = [];
|
||||
|
||||
for(let i = 0; i < notificationList?.length; i++)
|
||||
{
|
||||
if(notificationList[i]?.readed == false)
|
||||
{
|
||||
notificationIdList?.push(notificationList[i]?.id)
|
||||
async function handleScroll() {
|
||||
const scrollThreshold = document.body.offsetHeight * 0.8; // 80% of the website height
|
||||
const isBottom = window.innerHeight + window.scrollY >= scrollThreshold;
|
||||
if (isBottom && notificationList?.length !== rawData?.length) {
|
||||
const nextIndex = notificationList?.length;
|
||||
const filteredNewResults = rawData?.slice(nextIndex, nextIndex + 25);
|
||||
notificationList = [...notificationList, ...filteredNewResults];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async function updateNotifications() {
|
||||
let notificationIdList = [];
|
||||
|
||||
if (notificationIdList.length !== 0)
|
||||
{
|
||||
const postData = {'unreadList': notificationIdList, 'path': 'update-notifications'};
|
||||
for (let i = 0; i < notificationList?.length; i++) {
|
||||
if (notificationList[i]?.readed == false) {
|
||||
notificationIdList?.push(notificationList[i]?.id);
|
||||
}
|
||||
}
|
||||
|
||||
await fetch('/api/fastify-post-data', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
"Content-Type": "application/json"
|
||||
},
|
||||
body: JSON.stringify(postData)
|
||||
if (notificationIdList.length !== 0) {
|
||||
const postData = {
|
||||
unreadList: notificationIdList,
|
||||
};
|
||||
|
||||
});
|
||||
await fetch("/api/update-notification", {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
body: JSON.stringify(postData),
|
||||
});
|
||||
|
||||
$numberOfUnreadNotification = 0;
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
function goToPost(item) {
|
||||
if (item?.comment && item?.notifyType === 'vote') {
|
||||
$scrollToComment = item?.comment;
|
||||
$numberOfUnreadNotification = 0;
|
||||
}
|
||||
}
|
||||
goto("/community/post/"+item?.post)
|
||||
}
|
||||
|
||||
async function infiniteHandler({ detail: { loaded, complete } })
|
||||
{
|
||||
if (notificationList?.length === rawData?.length) {
|
||||
complete();
|
||||
} else {
|
||||
const nextIndex = notificationList?.length;
|
||||
const newArticles = rawData?.slice(nextIndex, nextIndex + 20);
|
||||
notificationList = [...notificationList, ...newArticles];
|
||||
console.log(notificationList)
|
||||
loaded();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
onMount(async () => {
|
||||
|
||||
onMount(async () => {
|
||||
await updateNotifications();
|
||||
isLoaded = true;
|
||||
|
||||
})
|
||||
window.addEventListener("scroll", handleScroll);
|
||||
return () => {
|
||||
window.removeEventListener("scroll", handleScroll);
|
||||
};
|
||||
});
|
||||
</script>
|
||||
|
||||
|
||||
|
||||
|
||||
<svelte:head>
|
||||
<title> {$numberOfUnreadNotification > 0 ? `(${$numberOfUnreadNotification})` : ''} Notifications · stocknear</title>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width" />
|
||||
<title>
|
||||
{$numberOfUnreadNotification > 0 ? `(${$numberOfUnreadNotification})` : ""} Notifications
|
||||
· stocknear</title
|
||||
>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width" />
|
||||
|
||||
<meta name="description" content="Free Stock Analysis">
|
||||
<!-- Other meta tags -->
|
||||
<meta property="og:title" content="Notifications · stocknear"/>
|
||||
<meta property="og:description" content="Free Stock Analysis">
|
||||
<meta property="og:image" content="https://stocknear-pocketbase.s3.amazonaws.com/logo/meta_logo.jpg"/>
|
||||
<meta property="og:type" content="website"/>
|
||||
<!-- Add more Open Graph meta tags as needed -->
|
||||
<meta name="description" content="Free Stock Analysis" />
|
||||
<!-- Other meta tags -->
|
||||
<meta property="og:title" content="Notifications · stocknear" />
|
||||
<meta property="og:description" content="Free Stock Analysis" />
|
||||
<meta
|
||||
property="og:image"
|
||||
content="https://stocknear-pocketbase.s3.amazonaws.com/logo/meta_logo.jpg"
|
||||
/>
|
||||
<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="Notifications · stocknear"/>
|
||||
<meta name="twitter:description" content="Free Stock Analysis">
|
||||
<meta name="twitter:image" content="https://stocknear-pocketbase.s3.amazonaws.com/logo/meta_logo.jpg"/>
|
||||
<!-- Add more Twitter meta tags as needed -->
|
||||
<!-- Twitter specific meta tags -->
|
||||
<meta name="twitter:card" content="summary_large_image" />
|
||||
<meta name="twitter:title" content="Notifications · stocknear" />
|
||||
<meta name="twitter:description" content="Free Stock Analysis" />
|
||||
<meta
|
||||
name="twitter:image"
|
||||
content="https://stocknear-pocketbase.s3.amazonaws.com/logo/meta_logo.jpg"
|
||||
/>
|
||||
<!-- Add more Twitter meta tags as needed -->
|
||||
</svelte:head>
|
||||
|
||||
|
||||
<section class="w-full max-w-5xl overflow-hidden m-auto min-h-screen sm:pt-5 sm:pb-40 bg-[#09090B]">
|
||||
|
||||
|
||||
|
||||
<div class="w-full max-w-3xl m-auto min-h-screen bg-[#09090B] sm:rounded-lg sm:border sm:border-gray-700 overflow-hidden sm:overflow-y-scroll scroller sm:max-h-[1100px] pt-5 sm:pb-10 sm:pt-10 sm:mt-3 sm:mb-8">
|
||||
|
||||
<h1 class="pl-5 text-2xl text-white font-semibold mt-2 sm:mt-0">
|
||||
Notifications
|
||||
</h1>
|
||||
|
||||
|
||||
<div class="w-full m-auto mb-10 bg-[#09090B] mt-10">
|
||||
<div class="flex flex-col sm:flex-row items-center w-full">
|
||||
|
||||
|
||||
|
||||
|
||||
{#if isLoaded }
|
||||
<section
|
||||
class="w-full max-w-3xl sm:max-w-screen-2xl overflow-hidden min-h-screen pb-20 pt-5 px-4 lg:px-3"
|
||||
>
|
||||
<div class="text-sm sm:text-[1rem] breadcrumbs">
|
||||
<ul>
|
||||
<li><a href="/" class="text-gray-300">Home</a></li>
|
||||
<li class="text-gray-300">Notifications</li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
{#if notificationList?.length !== 0}
|
||||
<!-- svelte-ignore a11y-click-events-have-key-events -->
|
||||
<!-- svelte-ignore a11y-no-noninteractive-element-interactions -->
|
||||
<!-- svelte-ignore a11y-no-noninteractive-element-interactions -->
|
||||
<div class="flex flex-col items-start w-full text-white">
|
||||
{#each notificationList as item}
|
||||
<!-- svelte-ignore a11y-click-events-have-key-events -->
|
||||
<div on:click={()=> goToPost(item)} class="hover:bg-[#2B2B2B] p-3 mb-3 ml-1 text-gray-200 w-full {!item?.readed ? 'bg-[#F9AB00] bg-opacity-[0.1]' : ''} cursor-pointer">
|
||||
<div class="flex flex-row items-center w-full">
|
||||
<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="mb-6 border-b-[2px]">
|
||||
<h1 class="mb-1 text-white text-2xl sm:text-3xl font-bold">
|
||||
Notification
|
||||
</h1>
|
||||
</div>
|
||||
|
||||
<!-- svelte-ignore a11y-label-has-associated-control -->
|
||||
<label on:click|stopPropagation={()=> goto("/community/user/"+item?.expand?.user?.id)} class="avatar w-8 h-8 sm:w-11 sm:h-11 flex-shrink-0 cursor-pointer mr-4">
|
||||
<img style="clip-path: circle(50%);" class="flex-shrink-0 w-8 h-8 sm:w-11 sm:h-11 rounded-full inline-block"
|
||||
src={item?.expand?.user?.avatar
|
||||
? getImageURL(item?.expand?.user?.collectionId, item?.expand?.user?.id, item?.expand?.user?.avatar)
|
||||
: `https://avatar.vercel.sh/${item?.expand?.user?.username}`}
|
||||
alt="User avatar"
|
||||
/>
|
||||
</label>
|
||||
|
||||
<div class="text-white text-sm sm:text-[1rem]">
|
||||
{#if item?.notifyType === 'vote'}
|
||||
<div class="flex flex-col items-start">
|
||||
<div>
|
||||
<label on:click|stopPropagation={()=> goto("/community/user/"+item?.expand?.user?.id)} class="text-blue-400 cursor-pointer">
|
||||
{item?.expand?.user?.username}
|
||||
</label>
|
||||
<span class="text-white text-xs sm:text-sm">
|
||||
upvoted your {item?.comment ? 'comment' : 'post'}
|
||||
</span>
|
||||
</div>
|
||||
<span class="text-xs sm:text-sm text-[#A6ADBB0">{formatDate(item?.created)} ago</span>
|
||||
</div>
|
||||
{:else if item?.notifyType === 'priceAlert'}
|
||||
<!-- svelte-ignore a11y-click-events-have-key-events -->
|
||||
<!-- svelte-ignore a11y-label-has-associated-control -->
|
||||
<div class="flex flex-col items-start">
|
||||
<div>
|
||||
<label on:click|stopPropagation={()=> goto(`/${item?.liveResults?.assetType === 'stock' ? 'stocks' : 'etf'}/${item?.liveResults?.symbol}`)} class="flex flex-col items-start cursor-pointer">
|
||||
<div class="text-md mt-0.5">
|
||||
Price Alert triggered for <span class="text-blue-400">${item?.liveResults?.symbol}</span>
|
||||
{#if notificationList?.length !== 0}
|
||||
<div class="flex flex-col items-start w-full text-white">
|
||||
{#each notificationList as item}
|
||||
<!-- svelte-ignore a11y-click-events-have-key-events -->
|
||||
<div
|
||||
class="sm:hover:bg-[#2B2B2B] pb-3 sm:p-3 mb-6 sm:mb-3 text-gray-200 w-full {!item?.readed
|
||||
? 'bg-[#F9AB00] bg-opacity-[0.1]'
|
||||
: ''} "
|
||||
>
|
||||
<div class="flex flex-row items-center w-full">
|
||||
<!-- svelte-ignore a11y-label-has-associated-control -->
|
||||
<a
|
||||
href={"/community/user/" + item?.expand?.user?.id}
|
||||
class="avatar w-11 h-11 flex-shrink-0 cursor-pointer mr-4"
|
||||
>
|
||||
<img
|
||||
style="clip-path: circle(50%);"
|
||||
class="flex-shrink-0 w-11 h-11 rounded-full inline-block"
|
||||
src={item?.expand?.user?.avatar
|
||||
? getImageURL(
|
||||
item?.expand?.user?.collectionId,
|
||||
item?.expand?.user?.id,
|
||||
item?.expand?.user?.avatar,
|
||||
)
|
||||
: defaultAvatar}
|
||||
alt="User avatar"
|
||||
/>
|
||||
</a>
|
||||
|
||||
<div class="text-white text-sm sm:text-[1rem]">
|
||||
{#if item?.notifyType === "vote"}
|
||||
<div class="flex flex-col items-start">
|
||||
<div>
|
||||
<a
|
||||
href={"/community/user/" + item?.expand?.user?.id}
|
||||
class="sm:hover:text-white text-blue-400 cursor-pointer"
|
||||
>
|
||||
{item?.expand?.user?.username}
|
||||
</a>
|
||||
<span class="text-white text-sm sm:text-[1rem]">
|
||||
upvoted your {item?.comment ? "comment" : "post"}
|
||||
</span>
|
||||
</div>
|
||||
<span class="text-sm sm:text-[1rem] text-[#A6ADBB0"
|
||||
>{formatDate(item?.created)} ago</span
|
||||
>
|
||||
</div>
|
||||
<div class="text-md mt-0.5">
|
||||
The price of <span class="font-bold">${item?.liveResults?.currentPrice}</span> is {item?.liveResults?.condition} your target of <span class="font-bold">${item?.liveResults?.targetPrice}</span>
|
||||
{:else if item?.notifyType === "priceAlert"}
|
||||
<!-- svelte-ignore a11y-click-events-have-key-events -->
|
||||
<!-- svelte-ignore a11y-label-has-associated-control -->
|
||||
<div class="flex flex-col items-start">
|
||||
<div>
|
||||
<a
|
||||
href={`/${item?.liveResults?.assetType === "stock" ? "stocks" : "etf"}/${item?.liveResults?.symbol}`}
|
||||
class="flex flex-col items-start cursor-pointer"
|
||||
>
|
||||
<div class="text-md mt-0.5">
|
||||
Price Alert triggered for <span
|
||||
class="sm:hover:text-white text-blue-400"
|
||||
>${item?.liveResults?.symbol}</span
|
||||
>
|
||||
</div>
|
||||
<div class="text-md mt-0.5">
|
||||
The price of <span class="font-bold"
|
||||
>${item?.liveResults?.currentPrice}</span
|
||||
>
|
||||
is {item?.liveResults?.condition} your target of
|
||||
<span class="font-bold"
|
||||
>${item?.liveResults?.targetPrice}</span
|
||||
>
|
||||
</div>
|
||||
</a>
|
||||
</div>
|
||||
<span class="text-sm sm:text-[1rem] text-[#A6ADBB0"
|
||||
>{formatDate(item?.created)} ago</span
|
||||
>
|
||||
</div>
|
||||
</label>
|
||||
{:else if item?.notifyType === "comment"}
|
||||
<div class="flex flex-col items-start">
|
||||
<div>
|
||||
<a
|
||||
href={"/community/user/" + item?.expand?.user?.id}
|
||||
class="sm:hover:text-white text-blue-400 cursor-pointer"
|
||||
>
|
||||
{item?.expand?.user?.username}
|
||||
</a>
|
||||
<span class="text-white text-sm sm:text-[1rem]">
|
||||
commented on your post:
|
||||
</span>
|
||||
{@html item?.expand?.comment?.comment?.length > 30
|
||||
? item?.expand?.comment?.comment?.slice(0, 30) +
|
||||
"..."
|
||||
: item?.expand?.comment?.comment}
|
||||
</div>
|
||||
<span class="text-sm sm:text-[1rem] text-[#A6ADBB0"
|
||||
>{formatDate(item?.created)} ago</span
|
||||
>
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
<span class="text-xs sm:text-sm text-[#A6ADBB0">{formatDate(item?.created)} ago</span>
|
||||
</div>
|
||||
|
||||
{:else if item?.notifyType === 'comment'}
|
||||
<div class="flex flex-col items-start">
|
||||
<div>
|
||||
<label on:click={() => goto("/community/user/"+item?.expand?.user?.id)} class="text-blue-400 hover:underline cursor-pointer">
|
||||
{item?.expand?.user?.username}
|
||||
</label>
|
||||
<span class="text-white text-xs sm:text-sm">
|
||||
commented on your post:
|
||||
</span>
|
||||
{@html item?.expand?.comment?.comment?.length > 30 ? item?.expand?.comment?.comment?.slice(0, 30) + "..." : item?.expand?.comment?.comment}
|
||||
</div>
|
||||
<span class="text-xs sm:text-sm text-[#A6ADBB0">{formatDate(item?.created)} ago</span>
|
||||
</div>
|
||||
|
||||
{/if}
|
||||
</div>
|
||||
<!--
|
||||
<!--
|
||||
{#if item?.expand?.post?.thumbnail}
|
||||
<img
|
||||
src="{getImageURL(item?.expand?.post?.collectionId, item?.expand?.post?.id, item?.expand?.post?.thumbnail)}"
|
||||
@ -200,49 +218,89 @@ onMount(async () => {
|
||||
/>
|
||||
{/if}
|
||||
-->
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{/each}
|
||||
</div>
|
||||
{/each}
|
||||
{:else}
|
||||
<div
|
||||
class="mt-5 text-white font-semibold text-[1rem] justify-center items-center m-auto"
|
||||
>
|
||||
Empty just like our souls...
|
||||
<svg
|
||||
class="inline-block w-4 h-4 m-auto mb-2"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
viewBox="0 0 1200 1200"
|
||||
><path
|
||||
fill="white"
|
||||
d="M567.663 0v190.423h64.679V0h-64.685h.006zm-264.11 57.225l-52.992 37.103l109.203 155.946l52.963-37.104L303.553 57.225zm592.886 0L787.268 213.171l52.971 37.104L949.44 94.328l-52.992-37.103h-.009zm-296.45 185.299c-158.227 0-286.493 96.083-286.493 214.625l162.772 492.948h247.47l162.758-492.948c0-118.54-128.258-214.625-286.492-214.625h-.015zM85.465 299.673l-22.099 60.814l178.849 65.114l22.181-60.785l-178.935-65.143h.004zm1029.062 0l-178.936 65.148l22.106 60.792l178.936-65.125l-22.106-60.815zM255.756 577.681l-183.9 49.326l16.686 62.431l183.9-49.255l-16.683-62.502h-.003zm688.48 0l-16.674 62.501l183.9 49.247l16.674-62.432l-183.9-49.318v.002zM472.66 986.032v85.686h254.687v-85.673H472.661l-.001-.013zm0 128.282V1200h254.687v-85.672H472.661l-.001-.014z"
|
||||
/></svg
|
||||
>
|
||||
</div>
|
||||
{/if}
|
||||
</main>
|
||||
|
||||
</div>
|
||||
<aside class="hidden lg:block relative fixed w-1/4 ml-4">
|
||||
{#if data?.user?.tier !== "Pro" || data?.user?.freeTrial}
|
||||
<div
|
||||
class="w-full text-white border border-gray-600 rounded-md h-fit pb-4 mt-4 cursor-pointer"
|
||||
>
|
||||
<a
|
||||
href="/pricing"
|
||||
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>
|
||||
</a>
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
|
||||
<InfiniteLoading on:infinite={infiniteHandler} />
|
||||
|
||||
|
||||
{:else}
|
||||
<div class="text-white font-semibold text-lg justify-center items-center m-auto">
|
||||
Empty just like our souls...
|
||||
<svg class="inline-block w-4 h-4 m-auto mb-2" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1200 1200"><path fill="white" d="M567.663 0v190.423h64.679V0h-64.685h.006zm-264.11 57.225l-52.992 37.103l109.203 155.946l52.963-37.104L303.553 57.225zm592.886 0L787.268 213.171l52.971 37.104L949.44 94.328l-52.992-37.103h-.009zm-296.45 185.299c-158.227 0-286.493 96.083-286.493 214.625l162.772 492.948h247.47l162.758-492.948c0-118.54-128.258-214.625-286.492-214.625h-.015zM85.465 299.673l-22.099 60.814l178.849 65.114l22.181-60.785l-178.935-65.143h.004zm1029.062 0l-178.936 65.148l22.106 60.792l178.936-65.125l-22.106-60.815zM255.756 577.681l-183.9 49.326l16.686 62.431l183.9-49.255l-16.683-62.502h-.003zm688.48 0l-16.674 62.501l183.9 49.247l16.674-62.432l-183.9-49.318v.002zM472.66 986.032v85.686h254.687v-85.673H472.661l-.001-.013zm0 128.282V1200h254.687v-85.672H472.661l-.001-.014z"/></svg>
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
{:else}
|
||||
<div class="flex justify-center items-center h-80">
|
||||
<div class="relative">
|
||||
<label class="bg-[#09090B] rounded-xl 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
|
||||
class="w-full text-white border border-gray-600 rounded-md h-fit pb-4 mt-4 cursor-pointer"
|
||||
>
|
||||
<a
|
||||
href="cramer-tracker"
|
||||
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">
|
||||
Cramer Tracker
|
||||
</h2>
|
||||
<ArrowLogo class="w-8 h-8 mr-3 flex-shrink-0" />
|
||||
</div>
|
||||
<span class="text-white p-3 ml-3 mr-3">
|
||||
Follow Jim Cramer latest stock picks
|
||||
</span>
|
||||
</a>
|
||||
</div>
|
||||
|
||||
<div
|
||||
class="w-full text-white border border-gray-600 rounded-md h-fit pb-4 mt-4 cursor-pointer"
|
||||
>
|
||||
<a
|
||||
href="/reddit-tracker"
|
||||
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">
|
||||
Reddit Tracker
|
||||
</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 trends of r/Wallstreetbets
|
||||
</span>
|
||||
</a>
|
||||
</div>
|
||||
</aside>
|
||||
</div>
|
||||
|
||||
{/if}
|
||||
|
||||
</div>
|
||||
|
||||
</section>
|
||||
|
||||
|
||||
|
||||
<style>
|
||||
|
||||
.scroller {
|
||||
scrollbar-width: thin;
|
||||
}
|
||||
|
||||
</style>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
@ -10,9 +10,8 @@
|
||||
|
||||
export let data;
|
||||
|
||||
let isLoaded = false;
|
||||
let rawData = [];
|
||||
let stockList = [];
|
||||
let rawData = data?.getSentimentTracker ?? [];
|
||||
let stockList = rawData?.slice(0, 50) ?? [];
|
||||
|
||||
async function handleScroll() {
|
||||
const scrollThreshold = document.body.offsetHeight * 0.8; // 80% of the website height
|
||||
@ -25,11 +24,6 @@
|
||||
}
|
||||
|
||||
onMount(() => {
|
||||
rawData = data?.getSentimentTracker ?? [];
|
||||
stockList = rawData?.slice(0, 50) ?? [];
|
||||
|
||||
isLoaded = true;
|
||||
|
||||
if (data?.user?.tier === "Pro") {
|
||||
window.addEventListener("scroll", handleScroll);
|
||||
return () => {
|
||||
@ -171,139 +165,126 @@
|
||||
</h1>
|
||||
</div>
|
||||
|
||||
{#if isLoaded}
|
||||
<div
|
||||
class="mb-8 w-full text-center sm:text-start sm:flex sm:flex-row sm:items-center m-auto text-gray-100 border border-gray-800 sm:rounded-lg h-auto p-5"
|
||||
<div
|
||||
class="mb-8 w-full text-center sm:text-start sm:flex sm:flex-row sm:items-center m-auto text-gray-100 border border-gray-800 sm:rounded-lg h-auto p-5"
|
||||
>
|
||||
<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="#FBCE3C"
|
||||
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
|
||||
>
|
||||
<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="#FBCE3C"
|
||||
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
|
||||
>
|
||||
We update our data in realtime to provide you with the latest trends
|
||||
and the most bullish stocks being discussed on Twitter and StockTwits
|
||||
</div>
|
||||
We update our data in realtime to provide you with the latest trends
|
||||
and the most bullish stocks being discussed on Twitter and StockTwits
|
||||
</div>
|
||||
|
||||
<div class="w-screen sm:w-full m-auto mt-20 sm:mt-10">
|
||||
<div
|
||||
class="w-screen sm:w-full m-auto rounded-none sm:rounded-lg mb-4 overflow-x-scroll sm:overflow-hidden"
|
||||
<div class="w-screen sm:w-full m-auto mt-20 sm:mt-10">
|
||||
<div
|
||||
class="w-screen sm:w-full m-auto rounded-none sm:rounded-lg mb-4 overflow-x-scroll sm:overflow-hidden"
|
||||
>
|
||||
<table
|
||||
class="table table-sm table-compact rounded-none sm:rounded-md w-full bg-[#09090B] border-bg-[#09090B] m-auto"
|
||||
>
|
||||
<table
|
||||
class="table table-sm table-compact rounded-none sm:rounded-md w-full bg-[#09090B] border-bg-[#09090B] m-auto"
|
||||
>
|
||||
<thead>
|
||||
<TableHeader {columns} {sortOrders} {sortData} />
|
||||
</thead>
|
||||
<tbody>
|
||||
{#each stockList as item, index}
|
||||
<tr
|
||||
class="sm:hover:bg-[#245073] border-b border-[#27272A] sm:hover:bg-opacity-[0.2] odd:bg-[#27272A] {index +
|
||||
1 ===
|
||||
stockList?.length && data?.user?.tier !== 'Pro'
|
||||
? 'opacity-[0.1]'
|
||||
: ''}"
|
||||
<thead>
|
||||
<TableHeader {columns} {sortOrders} {sortData} />
|
||||
</thead>
|
||||
<tbody>
|
||||
{#each stockList as item, index}
|
||||
<tr
|
||||
class="sm:hover:bg-[#245073] border-b border-[#27272A] sm:hover:bg-opacity-[0.2] odd:bg-[#27272A] {index +
|
||||
1 ===
|
||||
stockList?.length && data?.user?.tier !== 'Pro'
|
||||
? 'opacity-[0.1]'
|
||||
: ''}"
|
||||
>
|
||||
<td
|
||||
class="text-white text-sm sm:text-[1rem] font-medium text-white text-end"
|
||||
>
|
||||
<td
|
||||
class="text-white text-sm sm:text-[1rem] font-medium text-white text-end"
|
||||
>
|
||||
{item?.rank}
|
||||
</td>
|
||||
{item?.rank}
|
||||
</td>
|
||||
|
||||
<td class="text-sm sm:text-[1rem] text-start">
|
||||
<HoverStockChart symbol={item?.symbol} />
|
||||
</td>
|
||||
<td class="text-sm sm:text-[1rem] text-start">
|
||||
<HoverStockChart symbol={item?.symbol} />
|
||||
</td>
|
||||
|
||||
<td
|
||||
class="whitespace-nowrap text-white text-sm sm:text-[1rem] text-white text-start"
|
||||
>
|
||||
{item?.name?.length > charNumber
|
||||
? item?.name?.slice(0, charNumber) + "..."
|
||||
: item?.name}
|
||||
</td>
|
||||
<td
|
||||
class="whitespace-nowrap text-white text-sm sm:text-[1rem] text-white text-start"
|
||||
>
|
||||
{item?.name?.length > charNumber
|
||||
? item?.name?.slice(0, charNumber) + "..."
|
||||
: item?.name}
|
||||
</td>
|
||||
|
||||
<td
|
||||
class="text-end text-sm sm:text-[1rem] font-medium text-white whitespace-nowrap"
|
||||
>
|
||||
{abbreviateNumber(item?.marketCap)}
|
||||
</td>
|
||||
<td
|
||||
class="text-end text-sm sm:text-[1rem] font-medium text-white whitespace-nowrap"
|
||||
>
|
||||
{abbreviateNumber(item?.marketCap)}
|
||||
</td>
|
||||
|
||||
<td
|
||||
class="text-end text-sm sm:text-[1rem] whitespace-nowrap font-medium text-white"
|
||||
>
|
||||
{item?.price}
|
||||
</td>
|
||||
<td
|
||||
class="text-end text-sm sm:text-[1rem] whitespace-nowrap font-medium text-white"
|
||||
>
|
||||
{item?.price}
|
||||
</td>
|
||||
|
||||
<td
|
||||
class="text-sm sm:text-[1rem] whitespace-nowrap {item?.changesPercentage >=
|
||||
0
|
||||
? 'text-[#00FC50]'
|
||||
: 'text-[#FF2F1F]'} text-end"
|
||||
>
|
||||
{item?.changesPercentage > 0
|
||||
? "+"
|
||||
: ""}{item?.changesPercentage}%
|
||||
</td>
|
||||
<td
|
||||
class="text-sm sm:text-[1rem] whitespace-nowrap {item?.changesPercentage >=
|
||||
0
|
||||
? 'text-[#00FC50]'
|
||||
: 'text-[#FF2F1F]'} text-end"
|
||||
>
|
||||
{item?.changesPercentage > 0
|
||||
? "+"
|
||||
: ""}{item?.changesPercentage}%
|
||||
</td>
|
||||
|
||||
<td
|
||||
class="text-end text-sm sm:text-[1rem] font-medium whitespace-nowrap {item?.sentiment >=
|
||||
55
|
||||
? 'text-[#00FC50]'
|
||||
: item?.sentiment >= 50
|
||||
? 'text-[#E57C34]'
|
||||
: 'text-[#FF2F1F]'}"
|
||||
>
|
||||
<div class="flex flex-row items-center justify-end">
|
||||
<div class="">
|
||||
{item?.sentiment >= 80
|
||||
? "Very Bullish"
|
||||
: item?.sentiment >= 55
|
||||
? "Bullish"
|
||||
: item?.sentiment > 50
|
||||
? "Mixed"
|
||||
: "Bearish"}
|
||||
</div>
|
||||
<div
|
||||
class="ml-2 px-1.5 py-1.5 border text-center rounded-lg text-xs font-semibold"
|
||||
>
|
||||
{item?.sentiment}
|
||||
</div>
|
||||
<td
|
||||
class="text-end text-sm sm:text-[1rem] font-medium whitespace-nowrap {item?.sentiment >=
|
||||
55
|
||||
? 'text-[#00FC50]'
|
||||
: item?.sentiment >= 50
|
||||
? 'text-[#E57C34]'
|
||||
: 'text-[#FF2F1F]'}"
|
||||
>
|
||||
<div class="flex flex-row items-center justify-end">
|
||||
<div class="">
|
||||
{item?.sentiment >= 80
|
||||
? "Very Bullish"
|
||||
: item?.sentiment >= 55
|
||||
? "Bullish"
|
||||
: item?.sentiment > 50
|
||||
? "Mixed"
|
||||
: "Bearish"}
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
{/each}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<UpgradeToPro
|
||||
{data}
|
||||
title="Get the latest stock trends from social media to never miss out the next hype"
|
||||
/>
|
||||
<div
|
||||
class="ml-2 px-1.5 py-1.5 border text-center rounded-lg text-xs font-semibold"
|
||||
>
|
||||
{item?.sentiment}
|
||||
</div>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
{/each}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
{:else}
|
||||
<div class="flex justify-center items-center h-80">
|
||||
<div class="relative">
|
||||
<label
|
||||
class="bg-[#09090B] rounded-xl 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}
|
||||
<UpgradeToPro
|
||||
{data}
|
||||
title="Get the latest stock trends from social media to never miss out the next hype"
|
||||
/>
|
||||
</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"
|
||||
>
|
||||
<div
|
||||
<a
|
||||
href="/pricing"
|
||||
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">
|
||||
@ -315,15 +296,17 @@
|
||||
<span class="text-white p-3 ml-3 mr-3">
|
||||
Upgrade now for unlimited access to all data and tools.
|
||||
</span>
|
||||
</div>
|
||||
</a>
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
<div
|
||||
on:click={() => goto("/cramer-tracker")}
|
||||
class="w-full text-white border border-gray-600 rounded-md 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">
|
||||
<a
|
||||
href="cramer-tracker"
|
||||
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">
|
||||
Cramer Tracker
|
||||
@ -333,14 +316,16 @@
|
||||
<span class="text-white p-3 ml-3 mr-3">
|
||||
Follow Jim Cramer latest stock picks
|
||||
</span>
|
||||
</div>
|
||||
</a>
|
||||
</div>
|
||||
|
||||
<div
|
||||
on:click={() => goto("/reddit-tracker")}
|
||||
class="w-full text-white border border-gray-600 rounded-md 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">
|
||||
<a
|
||||
href="/reddit-tracker"
|
||||
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">
|
||||
Reddit Tracker
|
||||
@ -350,7 +335,7 @@
|
||||
<span class="text-white p-3 ml-3 mr-3">
|
||||
Get the latest trends of r/Wallstreetbets
|
||||
</span>
|
||||
</div>
|
||||
</a>
|
||||
</div>
|
||||
</aside>
|
||||
</div>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user