update news section
This commit is contained in:
parent
af67492e11
commit
5fcb820c85
@ -21,6 +21,7 @@
|
|||||||
let watchList: any[] = [];
|
let watchList: any[] = [];
|
||||||
|
|
||||||
let news = [];
|
let news = [];
|
||||||
|
let groupedNews = {};
|
||||||
let checkedItems;
|
let checkedItems;
|
||||||
let socket;
|
let socket;
|
||||||
|
|
||||||
@ -213,6 +214,22 @@
|
|||||||
|
|
||||||
watchList = output?.data;
|
watchList = output?.data;
|
||||||
news = output?.news;
|
news = output?.news;
|
||||||
|
news = news?.map((item) => {
|
||||||
|
const match = watchList?.find((w) => w?.symbol === item?.symbol);
|
||||||
|
return match ? { ...item, type: match?.type } : { ...item };
|
||||||
|
});
|
||||||
|
groupedNews = Object?.entries(
|
||||||
|
news?.reduce((acc, item) => {
|
||||||
|
const dateKey = new Intl.DateTimeFormat("en-US", {
|
||||||
|
day: "2-digit",
|
||||||
|
month: "short",
|
||||||
|
year: "numeric",
|
||||||
|
}).format(new Date(item?.publishedDate));
|
||||||
|
if (!acc[dateKey]) acc[dateKey] = [];
|
||||||
|
acc[dateKey]?.push(item);
|
||||||
|
return acc;
|
||||||
|
}, {}),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
async function createWatchList(event) {
|
async function createWatchList(event) {
|
||||||
@ -1319,70 +1336,96 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div
|
<div
|
||||||
class="w-full m-auto border-b border-gray-600 mt-16 mb-16"
|
class="w-full m-auto border-b border-gray-600 mt-16 mb-10"
|
||||||
></div>
|
></div>
|
||||||
|
|
||||||
<h2
|
<div class=" text-white">
|
||||||
class="text-start text-white text-xl sm:text-2xl font-bold mb-3"
|
<div class="mb-3 flex items-center space-x-2">
|
||||||
>
|
<h2
|
||||||
News
|
class="text-start text-white text-xl sm:text-2xl font-bold"
|
||||||
</h2>
|
>
|
||||||
|
News
|
||||||
<div class="relative text-gray-800 m-auto">
|
</h2>
|
||||||
<div class="flex flex-wrap md:flex-row">
|
<!--
|
||||||
{#each news as item}
|
<button title="Refresh news"
|
||||||
<a
|
><svg
|
||||||
href={item.url}
|
class="w-5 h-5 mt-1.5 text-icon"
|
||||||
target="_blank"
|
fill="none"
|
||||||
class="cursor-pointer mb-10 w-full"
|
viewBox="0 0 24 24"
|
||||||
>
|
stroke="currentColor"
|
||||||
<div class="flex-shrink-0 float-left">
|
style="max-width:40px"
|
||||||
<img
|
><path
|
||||||
src={item?.image}
|
stroke-linecap="round"
|
||||||
class="float-left w-36 sm:w-40 rounded-xl ml-2 mr-4 mb-2"
|
stroke-linejoin="round"
|
||||||
alt="news image"
|
d="M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15"
|
||||||
loading="lazy"
|
stroke-width="2"
|
||||||
/>
|
></path></svg
|
||||||
<div
|
></button
|
||||||
class="absolute w-36 sm:w-40 ml-2 mr-4 mb-2 h-6 bg-[#0C0F17] bg-opacity-80 flex justify-center items-center"
|
>
|
||||||
>
|
-->
|
||||||
<p class="text-white italic text-xs">
|
|
||||||
{new URL(item?.url).hostname.replace(
|
|
||||||
"www.",
|
|
||||||
"",
|
|
||||||
)}
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div class="flex-grow">
|
|
||||||
<div class="text-sm text-white flex flex-row">
|
|
||||||
<div
|
|
||||||
class="rounded-full w-6 h-6 relative bg-gray-800 mr-1.5 mb-0.5"
|
|
||||||
>
|
|
||||||
<img
|
|
||||||
class="rounded-full w-4 h-4 absolute inset-1/2 transform -translate-x-1/2 -translate-y-1/2"
|
|
||||||
src={`https://financialmodelingprep.com/image-stock/${item.symbol}.png`}
|
|
||||||
loading="lazy"
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
{item?.symbol} · {formatDate(
|
|
||||||
item?.publishedDate,
|
|
||||||
)} ago
|
|
||||||
</div>
|
|
||||||
<h2
|
|
||||||
class="text-start text-sm sm:text-md font-medium mb-2 flex-shrink text-white"
|
|
||||||
>
|
|
||||||
{item.title}
|
|
||||||
</h2>
|
|
||||||
<p class="text-white text-sm sm:text-md p-2">
|
|
||||||
{item?.text?.length > 250
|
|
||||||
? item?.text?.slice(0, 250) + "..."
|
|
||||||
: item?.text}
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
</a>
|
|
||||||
{/each}
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
{#each groupedNews as [date, items]}
|
||||||
|
<h3 class="mb-1.5 mt-3 font-semibold text-faded">
|
||||||
|
{date}
|
||||||
|
</h3>
|
||||||
|
<div class="border border-gray-700">
|
||||||
|
{#each items as item}
|
||||||
|
<div class="flex border-gray-600 text-small">
|
||||||
|
<div
|
||||||
|
class="hidden min-w-[100px] items-center justify-center bg-[#27272A] p-1 lg:flex"
|
||||||
|
>
|
||||||
|
{new Date(item.publishedDate).toLocaleTimeString(
|
||||||
|
"en-US",
|
||||||
|
{
|
||||||
|
hour: "2-digit",
|
||||||
|
minute: "2-digit",
|
||||||
|
hour12: true,
|
||||||
|
},
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
<div
|
||||||
|
class="flex-grow px-3 py-2 lg:py-1 border-gray-700 border-t"
|
||||||
|
>
|
||||||
|
<a
|
||||||
|
href={item?.url}
|
||||||
|
target="_blank"
|
||||||
|
rel="nofollow noopener noreferrer"
|
||||||
|
class="text-white sm:hover:text-blue-400"
|
||||||
|
>
|
||||||
|
<h4
|
||||||
|
class="text-sm font-semibold lg:text-[1rem]"
|
||||||
|
>
|
||||||
|
{item?.title}
|
||||||
|
</h4>
|
||||||
|
</a>
|
||||||
|
<div
|
||||||
|
class="flex flex-wrap gap-x-2 pt-2 text-sm lg:pt-0.5"
|
||||||
|
>
|
||||||
|
<div class="text-white lg:hidden">
|
||||||
|
{new Date(
|
||||||
|
item.publishedDate,
|
||||||
|
).toLocaleTimeString("en-US", {
|
||||||
|
hour: "2-digit",
|
||||||
|
minute: "2-digit",
|
||||||
|
hour12: true,
|
||||||
|
})}
|
||||||
|
</div>
|
||||||
|
<div class="text-white">{item?.site}</div>
|
||||||
|
·
|
||||||
|
<div class="flex flex-wrap gap-x-2">
|
||||||
|
<a
|
||||||
|
href={`/${item?.type}/${item?.symbol}`}
|
||||||
|
class="sm:hover:text-white text-blue-400"
|
||||||
|
>{item?.symbol}</a
|
||||||
|
>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{/each}
|
||||||
|
</div>
|
||||||
|
{/each}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{:else}
|
{:else}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user