bugfixing
This commit is contained in:
parent
6d10acdd26
commit
695b42b099
@ -19,44 +19,50 @@ type FlyAndScaleParams = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
export const groupNews = (news, watchList) => {
|
export const groupNews = (news, watchList) => {
|
||||||
return Object.entries(
|
return Object.entries(
|
||||||
news
|
news
|
||||||
?.map(item => {
|
?.map(item => {
|
||||||
// Add 'type' based on watchList
|
// Add 'type' based on watchList
|
||||||
const match = watchList?.find(w => w?.symbol === item?.symbol);
|
const match = watchList?.find(w => w?.symbol === item?.symbol);
|
||||||
return match ? { ...item, type: match.type } : { ...item };
|
return match ? { ...item, type: match.type } : { ...item };
|
||||||
})
|
})
|
||||||
?.reduce((acc, item) => {
|
?.reduce((acc, item) => {
|
||||||
const dateKey = new Intl.DateTimeFormat('en-US', {
|
const dateKey = new Intl.DateTimeFormat('en-US', {
|
||||||
day: '2-digit',
|
day: '2-digit',
|
||||||
month: 'short',
|
month: 'short',
|
||||||
year: 'numeric',
|
year: 'numeric',
|
||||||
}).format(new Date(item?.publishedDate));
|
}).format(new Date(item?.publishedDate));
|
||||||
|
const titleKey = item.title;
|
||||||
const titleKey = item.title;
|
if (!acc[dateKey]) acc[dateKey] = {};
|
||||||
|
if (!acc[dateKey][titleKey]) acc[dateKey][titleKey] = [];
|
||||||
if (!acc[dateKey]) acc[dateKey] = {};
|
acc[dateKey][titleKey]?.push(item);
|
||||||
if (!acc[dateKey][titleKey]) acc[dateKey][titleKey] = [];
|
return acc;
|
||||||
|
}, {})
|
||||||
acc[dateKey][titleKey]?.push(item);
|
)
|
||||||
|
// Sort the grouped dates in descending order to have the latest date first
|
||||||
return acc;
|
?.sort(([dateA], [dateB]) => new Date(dateB) - new Date(dateA))
|
||||||
}, {})
|
?.map(([date, titleGroup]) => [
|
||||||
)?.map(([date, titleGroup]) => [
|
|
||||||
date,
|
date,
|
||||||
Object?.entries(titleGroup)?.map(([title, items]) => {
|
Object.entries(titleGroup)
|
||||||
// Sort by time for each group
|
// Sort titles by the latest time of their items
|
||||||
items?.sort((a, b) => new Date(b?.publishedDate) - new Date(a?.publishedDate));
|
.sort(([, itemsA], [, itemsB]) => {
|
||||||
|
const latestTimeA = new Date(Math.max(...itemsA.map(item => new Date(item.publishedDate))));
|
||||||
// Get the unique symbols
|
const latestTimeB = new Date(Math.max(...itemsB.map(item => new Date(item.publishedDate))));
|
||||||
const symbols = [...new Set(items?.map(item => item.symbol))];
|
return latestTimeB - latestTimeA;
|
||||||
|
})
|
||||||
// Return the group with symbols and items
|
.map(([title, items]) => {
|
||||||
return { title, items, symbols };
|
// Sort items within each title group by latest time
|
||||||
}),
|
items.sort((a, b) => new Date(b.publishedDate) - new Date(a.publishedDate));
|
||||||
|
|
||||||
|
// Get the unique symbols
|
||||||
|
const symbols = [...new Set(items.map(item => item.symbol))];
|
||||||
|
|
||||||
|
// Return the group with symbols and items
|
||||||
|
return { title, items, symbols };
|
||||||
|
}),
|
||||||
]);
|
]);
|
||||||
}
|
};
|
||||||
|
|
||||||
|
|
||||||
export const calculateChange = (oldList?: any[], newList?: any[]) => {
|
export const calculateChange = (oldList?: any[], newList?: any[]) => {
|
||||||
|
|||||||
@ -16,15 +16,26 @@
|
|||||||
let switchWatchlist = false;
|
let switchWatchlist = false;
|
||||||
let editMode = false;
|
let editMode = false;
|
||||||
let numberOfChecked = 0;
|
let numberOfChecked = 0;
|
||||||
|
let activeIdx = 0;
|
||||||
|
|
||||||
let deleteTickerList = [];
|
let deleteTickerList = [];
|
||||||
|
|
||||||
let watchList: any[] = [];
|
let watchList: any[] = [];
|
||||||
|
|
||||||
let news = [];
|
let news = [];
|
||||||
let groupedNews = {};
|
let groupedNews = [];
|
||||||
let checkedItems;
|
let checkedItems;
|
||||||
let socket;
|
let socket;
|
||||||
|
|
||||||
|
const tabs = [
|
||||||
|
{
|
||||||
|
title: "News",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: "Earnings",
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
let allRows = [
|
let allRows = [
|
||||||
{ name: "Volume", rule: "volume", type: "int" },
|
{ name: "Volume", rule: "volume", type: "int" },
|
||||||
{ name: "Avg. Volume", rule: "avgVolume", type: "int" },
|
{ name: "Avg. Volume", rule: "avgVolume", type: "int" },
|
||||||
@ -219,6 +230,7 @@
|
|||||||
return match ? { ...item, type: match?.type } : { ...item };
|
return match ? { ...item, type: match?.type } : { ...item };
|
||||||
});
|
});
|
||||||
groupedNews = groupNews(news, watchList);
|
groupedNews = groupNews(news, watchList);
|
||||||
|
console.log(groupedNews);
|
||||||
}
|
}
|
||||||
|
|
||||||
async function createWatchList(event) {
|
async function createWatchList(event) {
|
||||||
@ -1333,92 +1345,108 @@
|
|||||||
></div>
|
></div>
|
||||||
|
|
||||||
<div class=" text-white">
|
<div class=" text-white">
|
||||||
<div class="mb-3 flex items-center space-x-2">
|
<div
|
||||||
<h2
|
class="inline-flex justify-center w-full rounded-md sm:w-auto mb-3"
|
||||||
class="text-start text-white text-xl sm:text-2xl font-bold"
|
>
|
||||||
|
<div
|
||||||
|
class="bg-[#313131] w-full min-w-24 sm:w-fit relative flex flex-wrap items-center justify-center rounded-md p-1 mt-4"
|
||||||
>
|
>
|
||||||
News
|
{#each tabs as item, i}
|
||||||
</h2>
|
<button
|
||||||
<!--
|
on:click={() => (activeIdx = i)}
|
||||||
<button title="Refresh news"
|
class="group relative z-[1] rounded-full w-1/2 min-w-24 md:w-auto px-5 py-1 {activeIdx ===
|
||||||
><svg
|
i
|
||||||
class="w-5 h-5 mt-1.5 text-icon"
|
? 'z-0'
|
||||||
fill="none"
|
: ''} "
|
||||||
viewBox="0 0 24 24"
|
>
|
||||||
stroke="currentColor"
|
{#if activeIdx === i}
|
||||||
style="max-width:40px"
|
<div
|
||||||
><path
|
class="absolute inset-0 rounded-md bg-[#fff]"
|
||||||
stroke-linecap="round"
|
></div>
|
||||||
stroke-linejoin="round"
|
{/if}
|
||||||
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"
|
<span
|
||||||
stroke-width="2"
|
class="relative text-sm block text-lg font-semibold {activeIdx ===
|
||||||
></path></svg
|
i
|
||||||
></button
|
? 'text-black'
|
||||||
>
|
: 'text-white'}"
|
||||||
-->
|
>
|
||||||
|
{item.title}
|
||||||
|
</span>
|
||||||
|
</button>
|
||||||
|
{/each}
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{#each groupedNews as [date, titleGroups]}
|
{#if groupedNews?.length > 0}
|
||||||
<h3 class="mb-1.5 mt-3 font-semibold text-faded">
|
{#each groupedNews as [date, titleGroups]}
|
||||||
{date}
|
<h3 class="mb-1.5 mt-3 font-semibold text-faded">
|
||||||
</h3>
|
{date}
|
||||||
<div class="border border-gray-700">
|
</h3>
|
||||||
{#each titleGroups as { title, items, symbols }}
|
<div class="border border-gray-700">
|
||||||
<div class="flex border-gray-600 text-small">
|
{#each titleGroups as { title, items, symbols }}
|
||||||
<div
|
<div class="flex border-gray-600 text-small">
|
||||||
class="hidden min-w-[100px] items-center justify-center bg-[#27272A] p-1 lg:flex"
|
|
||||||
>
|
|
||||||
{new Date(
|
|
||||||
items[0].publishedDate,
|
|
||||||
).toLocaleTimeString("en-US", {
|
|
||||||
hour: "2-digit",
|
|
||||||
minute: "2-digit",
|
|
||||||
hour12: true,
|
|
||||||
})}
|
|
||||||
</div>
|
|
||||||
<div class="flex-grow px-3 py-2 lg:py-1">
|
|
||||||
<a
|
|
||||||
href={items[0].url}
|
|
||||||
target="_blank"
|
|
||||||
rel="nofollow noopener noreferrer"
|
|
||||||
class="text-white sm:hover:text-blue-400"
|
|
||||||
>
|
|
||||||
<h4
|
|
||||||
class="text-sm font-semibold lg:text-[1rem]"
|
|
||||||
>
|
|
||||||
{title}
|
|
||||||
</h4>
|
|
||||||
</a>
|
|
||||||
<div
|
<div
|
||||||
class="flex flex-wrap gap-x-2 pt-2 text-sm lg:pt-0.5"
|
class="hidden min-w-[100px] items-center justify-center bg-[#27272A] p-1 lg:flex"
|
||||||
>
|
>
|
||||||
<div class="text-white lg:hidden">
|
{new Date(
|
||||||
{new Date(
|
items[0].publishedDate,
|
||||||
items[0].publishedDate,
|
).toLocaleTimeString("en-US", {
|
||||||
).toLocaleTimeString("en-US", {
|
hour: "2-digit",
|
||||||
hour: "2-digit",
|
minute: "2-digit",
|
||||||
minute: "2-digit",
|
hour12: true,
|
||||||
hour12: true,
|
})}
|
||||||
})}
|
</div>
|
||||||
</div>
|
<div
|
||||||
<div class="text-white">{items[0].site}</div>
|
class="flex-grow px-3 py-2 lg:py-1 border-t border-gray-700"
|
||||||
·
|
>
|
||||||
<div class="flex flex-wrap gap-x-2">
|
<a
|
||||||
{#each symbols as symbol}
|
href={items[0].url}
|
||||||
<a
|
target="_blank"
|
||||||
href={`/${items[0].type}/${symbol}`}
|
rel="nofollow noopener noreferrer"
|
||||||
class="sm:hover:text-white text-blue-400"
|
class="text-white sm:hover:text-blue-400"
|
||||||
>
|
>
|
||||||
{symbol}
|
<h4
|
||||||
</a>
|
class="text-sm font-semibold lg:text-[1rem]"
|
||||||
{/each}
|
>
|
||||||
|
{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(
|
||||||
|
items[0].publishedDate,
|
||||||
|
).toLocaleTimeString("en-US", {
|
||||||
|
hour: "2-digit",
|
||||||
|
minute: "2-digit",
|
||||||
|
hour12: true,
|
||||||
|
})}
|
||||||
|
</div>
|
||||||
|
<div class="text-white">{items[0].site}</div>
|
||||||
|
·
|
||||||
|
<div class="flex flex-wrap gap-x-2">
|
||||||
|
{#each symbols as symbol}
|
||||||
|
<a
|
||||||
|
href={`/${items[0].type}/${symbol}`}
|
||||||
|
class="sm:hover:text-white text-blue-400"
|
||||||
|
>
|
||||||
|
{symbol}
|
||||||
|
</a>
|
||||||
|
{/each}
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
{/each}
|
||||||
{/each}
|
</div>
|
||||||
</div>
|
{/each}
|
||||||
{/each}
|
{:else}
|
||||||
|
<span class="text-sm sm:text-[1rem]">
|
||||||
|
No news yet. Add some stocks to the watchlist to see the
|
||||||
|
latest news.
|
||||||
|
</span>
|
||||||
|
{/if}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{:else}
|
{:else}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user