This commit is contained in:
MuslemRahimi 2024-11-10 17:41:06 +01:00
parent 53b75876b8
commit fa2124b468
2 changed files with 28 additions and 17 deletions

View File

@ -6,7 +6,7 @@
<footer <footer
class="bg-[#09090B] border-t border-slate-800 z-20 sm:z-50 relative bottom-0 w-full sm:px-10 m-auto" class="bg-[#09090B] border-t border-slate-800 z-20 sm:z-50 relative bottom-0 w-full sm:px-10 m-auto"
> >
<div class="container mx-auto px-3"> <div class="container mx-auto px-5 sm:px-3">
<div class="w-full flex flex-col md:flex-row py-6"> <div class="w-full flex flex-col md:flex-row py-6">
<div class="flex-1 mb-8"> <div class="flex-1 mb-8">
<div class="flex flex-row items-center mt-4"> <div class="flex flex-row items-center mt-4">
@ -17,7 +17,7 @@
class="flex flex-row items-center" class="flex flex-row items-center"
> >
<svg <svg
class="w-6 h-6 ml-4" class="w-6 h-6"
xmlns="http://www.w3.org/2000/svg" xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 24 24" viewBox="0 0 24 24"
><path ><path

View File

@ -1,12 +1,5 @@
<script lang="ts"> <script lang="ts">
import { import { format, startOfWeek, addDays, addWeeks, subWeeks } from "date-fns";
format,
startOfWeek,
addDays,
addWeeks,
subWeeks,
differenceInWeeks,
} from "date-fns";
import { screenWidth, numberOfUnreadNotification } from "$lib/store"; import { screenWidth, numberOfUnreadNotification } from "$lib/store";
import { abbreviateNumber, listOfRelevantCountries } from "$lib/utils"; import { abbreviateNumber, listOfRelevantCountries } from "$lib/utils";
import ArrowLogo from "lucide-svelte/icons/move-up-right"; import ArrowLogo from "lucide-svelte/icons/move-up-right";
@ -21,7 +14,7 @@
let weekdayFiltered = []; let weekdayFiltered = [];
let syncWorker: Worker | undefined; let syncWorker: Worker | undefined;
const maxWeeksChange = 4; const maxWeeksChange = 6;
const today = new Date(); const today = new Date();
let currentWeek = startOfWeek(today, { weekStartsOn: 1 }); let currentWeek = startOfWeek(today, { weekStartsOn: 1 });
let previousMax = false; let previousMax = false;
@ -34,8 +27,20 @@
$: formattedWeekday = daysOfWeek.map((day) => format(day.date, "EEE, MMM d")); $: formattedWeekday = daysOfWeek.map((day) => format(day.date, "EEE, MMM d"));
$: weekday = getWeekdayData(economicCalendar, daysOfWeek); $: weekday = getWeekdayData(economicCalendar, daysOfWeek);
$: rawData = weekday; $: rawData = weekday;
$: previousMax = differenceInWeeks(currentWeek, today) <= -maxWeeksChange;
$: nextMax = differenceInWeeks(currentWeek, today) >= maxWeeksChange; // Calculate start and end boundaries
const startBoundary = subWeeks(
startOfWeek(today, { weekStartsOn: 1 }),
maxWeeksChange,
);
const endBoundary = addWeeks(
startOfWeek(today, { weekStartsOn: 1 }),
maxWeeksChange,
);
// Update max checks based on boundaries
$: previousMax = currentWeek <= startBoundary;
$: nextMax = currentWeek >= endBoundary;
let currentDate = new Date(); let currentDate = new Date();
let selectedWeekday = Math.min((currentDate.getDay() + 6) % 7, 4); let selectedWeekday = Math.min((currentDate.getDay() + 6) % 7, 4);
@ -90,10 +95,15 @@
} }
function changeWeek(state) { function changeWeek(state) {
currentWeek = const newWeek =
state === "previous" state === "previous"
? subWeeks(currentWeek, 1) ? subWeeks(currentWeek, 1)
: addWeeks(currentWeek, 1); : addWeeks(currentWeek, 1);
// Only update if within boundaries
if (newWeek >= startBoundary && newWeek <= endBoundary) {
currentWeek = newWeek;
}
} }
onMount(async () => { onMount(async () => {
@ -115,7 +125,6 @@
testList = testList =
rawList?.filter((item) => { rawList?.filter((item) => {
const index = item?.toLowerCase(); const index = item?.toLowerCase();
// Check if country starts with searchQuery
return index?.startsWith(searchQuery); return index?.startsWith(searchQuery);
}) || []; }) || [];
} }
@ -150,11 +159,13 @@
formattedWeekday = daysOfWeek.map((day) => format(day.date, "EEE, MMM d")); formattedWeekday = daysOfWeek.map((day) => format(day.date, "EEE, MMM d"));
weekday = getWeekdayData(economicCalendar, daysOfWeek); weekday = getWeekdayData(economicCalendar, daysOfWeek);
rawData = weekday; rawData = weekday;
previousMax = differenceInWeeks(currentWeek, today) <= -maxWeeksChange;
nextMax = differenceInWeeks(currentWeek, today) >= maxWeeksChange;
currentWeek = startOfWeek(today, { weekStartsOn: 1 }); currentWeek = startOfWeek(today, { weekStartsOn: 1 });
selectedWeekday = Math.min((currentDate.getDay() + 6) % 7, 4); selectedWeekday = Math.min((currentDate.getDay() + 6) % 7, 4);
// Reset max checks based on boundaries
previousMax = currentWeek <= startBoundary;
nextMax = currentWeek >= endBoundary;
} }
</script> </script>