bugfixing options flow
This commit is contained in:
parent
b22d481009
commit
a4a5c14a25
@ -79,11 +79,11 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
{#if rawData?.length > 0}
|
||||||
<div class="grid grid-cols-1 gap-2 pb-5">
|
<div class="grid grid-cols-1 gap-2 pb-5">
|
||||||
{#each newsList as item}
|
{#each newsList as item}
|
||||||
<div class="w-full flex flex-col bg-[#09090B] rounded-md m-auto">
|
<div class="w-full flex flex-col bg-[#09090B] rounded-md m-auto">
|
||||||
<!--
|
<!--
|
||||||
{#if !checkIfYoutubeVideo(item.url)}
|
{#if !checkIfYoutubeVideo(item.url)}
|
||||||
<div class="w-full aspect-video mb-4">
|
<div class="w-full aspect-video mb-4">
|
||||||
<iframe
|
<iframe
|
||||||
@ -111,52 +111,55 @@
|
|||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
-->
|
-->
|
||||||
<div class="w-full flex flex-col sm:flex-row">
|
<div class="w-full flex flex-col sm:flex-row">
|
||||||
<a
|
|
||||||
href={item?.url}
|
|
||||||
rel="noopener noreferrer"
|
|
||||||
target="_blank"
|
|
||||||
class="w-full sm:max-w-56 h-fit max-h-96 sm:mr-3 border border-gray-800 rounded-md"
|
|
||||||
>
|
|
||||||
<div class="flex-shrink-0 m-auto">
|
|
||||||
<img
|
|
||||||
src={item?.image}
|
|
||||||
class="h-auto w-full rounded-md"
|
|
||||||
alt="news image"
|
|
||||||
loading="lazy"
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
</a>
|
|
||||||
<div class="-mt-3 w-full">
|
|
||||||
<h3 class="text-sm text-white/80 truncate mb-2 mt-3">
|
|
||||||
{formatDate(item?.publishedDate)} ago · {item?.site}
|
|
||||||
</h3>
|
|
||||||
<a
|
<a
|
||||||
href={item?.url}
|
href={item?.url}
|
||||||
rel="noopener noreferrer"
|
rel="noopener noreferrer"
|
||||||
target="_blank"
|
target="_blank"
|
||||||
class="text-lg sm:text-xl font-bold text-white"
|
class="w-full sm:max-w-56 h-fit max-h-96 sm:mr-3 border border-gray-800 rounded-md"
|
||||||
>
|
>
|
||||||
{item?.title}
|
<div class="flex-shrink-0 m-auto">
|
||||||
<p class="text-white text-sm mt-2 font-normal">
|
<img
|
||||||
{item?.text?.length > 200
|
src={item?.image}
|
||||||
? item?.text?.slice(0, 200) + "..."
|
class="h-auto w-full rounded-md"
|
||||||
: item?.text}
|
alt="news image"
|
||||||
</p>
|
loading="lazy"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
</a>
|
</a>
|
||||||
|
<div class="-mt-3 w-full">
|
||||||
|
<h3 class="text-sm text-white/80 truncate mb-2 mt-3">
|
||||||
|
{formatDate(item?.publishedDate)} ago · {item?.site}
|
||||||
|
</h3>
|
||||||
|
<a
|
||||||
|
href={item?.url}
|
||||||
|
rel="noopener noreferrer"
|
||||||
|
target="_blank"
|
||||||
|
class="text-lg sm:text-xl font-bold text-white"
|
||||||
|
>
|
||||||
|
{item?.title}
|
||||||
|
<p class="text-white text-sm mt-2 font-normal">
|
||||||
|
{item?.text?.length > 200
|
||||||
|
? item?.text?.slice(0, 200) + "..."
|
||||||
|
: item?.text}
|
||||||
|
</p>
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
<hr class="border-gray-600 w-full m-auto mt-5 mb-5" />
|
||||||
<hr class="border-gray-600 w-full m-auto mt-5 mb-5" />
|
{/each}
|
||||||
{/each}
|
</div>
|
||||||
</div>
|
{#if newsList?.length !== rawData?.length}
|
||||||
{#if newsList?.length !== rawData?.length}
|
<label
|
||||||
<label
|
on:click={loadMoreData}
|
||||||
on:click={loadMoreData}
|
class="shadow-lg rounded-md cursor-pointer w-5/6 sm:w-full 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 sm:hover:bg-purple-700 bg-purple-600"
|
||||||
class="shadow-lg rounded-md cursor-pointer w-5/6 sm:w-full 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 sm:hover:bg-purple-700 bg-purple-600"
|
>
|
||||||
>
|
Load More News
|
||||||
Load More News
|
</label>
|
||||||
</label>
|
{/if}
|
||||||
|
{:else}
|
||||||
|
<span class="text-white"> No News article available yet </span>
|
||||||
{/if}
|
{/if}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@ -75,14 +75,44 @@ function isSameDay(date1: Date, date2: Date): boolean {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function isDateWithinRange(dateString: string, range: string): boolean {
|
function isDateWithinRange(dateString: string, range: string): boolean {
|
||||||
const now = new Date();
|
let now = new Date();
|
||||||
const expirationDate = new Date(dateString);
|
const expirationDate = new Date(dateString);
|
||||||
|
const dayOfWeek = now.getDay();
|
||||||
|
|
||||||
|
// Special handling for "1 day" range when it's Friday, Saturday, or Sunday
|
||||||
|
if (
|
||||||
|
range.toLowerCase() === "1 day" &&
|
||||||
|
(dayOfWeek === 5 || dayOfWeek === 6 || dayOfWeek === 0)
|
||||||
|
) {
|
||||||
|
// Calculate next Monday
|
||||||
|
const daysUntilMonday =
|
||||||
|
dayOfWeek === 5
|
||||||
|
? 3 // From Friday
|
||||||
|
: dayOfWeek === 6
|
||||||
|
? 2 // From Saturday
|
||||||
|
: 1; // From Sunday
|
||||||
|
|
||||||
|
const monday = new Date(now);
|
||||||
|
monday.setDate(now.getDate() + daysUntilMonday);
|
||||||
|
|
||||||
|
// Compare with next Monday
|
||||||
|
return isSameDay(expirationDate, monday);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Adjust now to Friday if it falls on a weekend (for other ranges)
|
||||||
|
if (dayOfWeek === 6) {
|
||||||
|
// Saturday
|
||||||
|
now.setDate(now.getDate() - 1); // Move to Friday
|
||||||
|
} else if (dayOfWeek === 0) {
|
||||||
|
// Sunday
|
||||||
|
now.setDate(now.getDate() - 2); // Move to Friday
|
||||||
|
}
|
||||||
|
|
||||||
const timeDiff = expirationDate.getTime() - now.getTime();
|
const timeDiff = expirationDate.getTime() - now.getTime();
|
||||||
const daysDiff = timeDiff / (1000 * 60 * 60 * 24);
|
const daysDiff = timeDiff / (1000 * 60 * 60 * 24);
|
||||||
|
|
||||||
switch (range.toLowerCase()) {
|
switch (range.toLowerCase()) {
|
||||||
case "same day":
|
case "same day":
|
||||||
// Check if the current date and expiration date are the same
|
|
||||||
return isSameDay(now, expirationDate);
|
return isSameDay(now, expirationDate);
|
||||||
case "1 day":
|
case "1 day":
|
||||||
return daysDiff >= 0 && daysDiff <= 1;
|
return daysDiff >= 0 && daysDiff <= 1;
|
||||||
|
|||||||
@ -1532,12 +1532,7 @@
|
|||||||
<WIIM {data} />
|
<WIIM {data} />
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div
|
<div class="w-full mt-10 sm:mt-0 m-auto sm:pl-6 sm:pb-6 sm:pt-6">
|
||||||
class="w-full mt-10 sm:mt-0 m-auto sm:pl-6 sm:pb-6 sm:pt-6 {data
|
|
||||||
?.getNews?.length !== 0
|
|
||||||
? ''
|
|
||||||
: 'hidden'}"
|
|
||||||
>
|
|
||||||
<News {data} />
|
<News {data} />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user