bugfixing options flow

This commit is contained in:
MuslemRahimi 2024-11-03 15:29:28 +01:00
parent b22d481009
commit a4a5c14a25
3 changed files with 79 additions and 51 deletions

View File

@ -79,11 +79,11 @@
</div>
</div>
</div>
<div class="grid grid-cols-1 gap-2 pb-5">
{#each newsList as item}
<div class="w-full flex flex-col bg-[#09090B] rounded-md m-auto">
<!--
{#if rawData?.length > 0}
<div class="grid grid-cols-1 gap-2 pb-5">
{#each newsList as item}
<div class="w-full flex flex-col bg-[#09090B] rounded-md m-auto">
<!--
{#if !checkIfYoutubeVideo(item.url)}
<div class="w-full aspect-video mb-4">
<iframe
@ -111,52 +111,55 @@
</a>
</div>
-->
<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>
<div class="w-full flex flex-col sm:flex-row">
<a
href={item?.url}
rel="noopener noreferrer"
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}
<p class="text-white text-sm mt-2 font-normal">
{item?.text?.length > 200
? item?.text?.slice(0, 200) + "..."
: item?.text}
</p>
<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
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>
<hr class="border-gray-600 w-full m-auto mt-5 mb-5" />
{/each}
</div>
{#if newsList?.length !== rawData?.length}
<label
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"
>
Load More News
</label>
<hr class="border-gray-600 w-full m-auto mt-5 mb-5" />
{/each}
</div>
{#if newsList?.length !== rawData?.length}
<label
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"
>
Load More News
</label>
{/if}
{:else}
<span class="text-white"> No News article available yet </span>
{/if}
</div>
</div>

View File

@ -75,14 +75,44 @@ function isSameDay(date1: Date, date2: Date): boolean {
}
function isDateWithinRange(dateString: string, range: string): boolean {
const now = new Date();
let now = new Date();
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 daysDiff = timeDiff / (1000 * 60 * 60 * 24);
switch (range.toLowerCase()) {
case "same day":
// Check if the current date and expiration date are the same
return isSameDay(now, expirationDate);
case "1 day":
return daysDiff >= 0 && daysDiff <= 1;

View File

@ -1532,12 +1532,7 @@
<WIIM {data} />
</div>
<div
class="w-full mt-10 sm:mt-0 m-auto sm:pl-6 sm:pb-6 sm:pt-6 {data
?.getNews?.length !== 0
? ''
: 'hidden'}"
>
<div class="w-full mt-10 sm:mt-0 m-auto sm:pl-6 sm:pb-6 sm:pt-6">
<News {data} />
</div>
</div>