diff --git a/src/routes/economic-calendar/+page.svelte b/src/routes/economic-calendar/+page.svelte index 56bd1514..f63e48e3 100644 --- a/src/routes/economic-calendar/+page.svelte +++ b/src/routes/economic-calendar/+page.svelte @@ -2,9 +2,11 @@ import { format, startOfWeek, addDays, addWeeks, subWeeks, differenceInWeeks } from 'date-fns'; import { screenWidth, numberOfUnreadNotification } from '$lib/store'; import logo from '$lib/images/transcripts_logo.png'; - import { listOfCountries } from '$lib/utils'; + import { abbreviateNumber, listOfRelevantCountries } from '$lib/utils'; import ArrowLogo from "lucide-svelte/icons/move-up-right"; import { goto } from '$app/navigation'; + import * as DropdownMenu from "$lib/components/shadcn/dropdown-menu/index.js"; + import { Button } from "$lib/components/shadcn/button/index.js"; export let data; let rawData; @@ -17,6 +19,8 @@ let currentWeek = startOfWeek(today, { weekStartsOn: 1 }); let previousMax = false; let nextMax = false; + let searchQuery = ''; + $: testList = []; $: economicCalendar = data?.getEconomicCalendar; $: daysOfWeek = getDaysOfWeek(currentWeek); @@ -45,18 +49,7 @@ }); } - async function handleFilter(e, newFilter) { - const filterSet = new Set(filterList); - filterSet.has(newFilter) ? filterSet.delete(newFilter) : filterSet.add(newFilter); - filterList = Array.from(filterSet); - - if (filterList.length !== 0) { - await loadWorker(); - } else { - weekday = rawData; - } - } - + const handleMessage = (event) => { weekdayFiltered = event.data?.finalData?.output ?? []; }; @@ -93,6 +86,50 @@ function changeWeek(state) { currentWeek = state === 'previous' ? subWeeks(currentWeek, 1) : addWeeks(currentWeek, 1); } + + +function handleInput(event) { + const searchQuery = event.target.value?.toLowerCase() || ''; + + setTimeout(() => { + testList = []; + + if (searchQuery.length > 0) { + + const rawList = listOfRelevantCountries; + testList = rawList?.filter(item => { + const index = item?.toLowerCase(); + // Check if country starts with searchQuery + return index?.startsWith(searchQuery); + }) || []; + } + }, 50); +} + + +$: checkedItems = new Set(); + + + +async function handleChangeValue(value) { + if (checkedItems.has(value)) { + checkedItems.delete(value); + } else { + checkedItems.add(value); + } + const filterSet = new Set(filterList); + filterSet.has(value) ? filterSet.delete(value) : filterSet.add(value); + filterList = Array.from(filterSet); + + if (filterList.length !== 0) { + await loadWorker(); + } else { + weekday = rawData; + } + +} + + @@ -226,60 +263,48 @@
{#if filterList?.length !== 0} -
@@ -294,12 +319,12 @@ - - Event - Previous - Estimated - Actual - Impact + + Event + Previous + Forecast + Actual + Importance @@ -326,25 +351,41 @@ + + - {item?.event?.length > 15 ? item?.event?.slice(0,15) + '...' : item?.event} + {item?.event?.length > 30 ? item?.event?.slice(0,30) + '...' : item?.event} - {item?.previous !== null ? item?.previous : '-'} + {item?.prior !== (null || '') ? abbreviateNumber(item?.prior) : '-'} - {item?.estimate !== null ? item?.estimate : '-'} + {item?.consensus !== (null || '') ? abbreviateNumber(item?.consensus) : '-'} - {item?.actual !== null ? item?.actual : '-'} + {item?.actual !== null ? abbreviateNumber(item?.actual) : '-'} + + + +
+ {#each Array.from({ length: 3 }) as _, i} + {#if i < Math.floor(item?.importance)} + + {:else} + + {/if} + {/each} +
- - {item?.impact} - + diff --git a/src/routes/economic-calendar/+page.ts b/src/routes/economic-calendar/+page.ts index 3853ecc6..52555e2a 100644 --- a/src/routes/economic-calendar/+page.ts +++ b/src/routes/economic-calendar/+page.ts @@ -1,29 +1,28 @@ -import { getCache, setCache } from '$lib/store'; +import { getCache, setCache } from "$lib/store"; - -export const load = async ({parent}) => { +export const load = async ({ parent }) => { const getEconomicCalendar = async () => { let output; // Get cached data for the specific tickerID - const cachedData = getCache('', 'getEconomicCalendar'); + const cachedData = getCache("", "getEconomicCalendar"); if (cachedData) { output = cachedData; } else { - const { apiURL, apiKey } = await parent(); // make the POST request to the endpoint - const response = await fetch(apiURL + '/economic-calendar', { - method: 'GET', + const response = await fetch(apiURL + "/economic-calendar", { + method: "GET", headers: { - "Content-Type": "application/json", "X-API-KEY": apiKey + "Content-Type": "application/json", + "X-API-KEY": apiKey, }, }); output = await response.json(); // Cache the data for this specific tickerID with a specific name 'getEconomicCalendar' - setCache('', output, 'getEconomicCalendar'); + setCache("", output, "getEconomicCalendar"); } return output; @@ -31,6 +30,6 @@ export const load = async ({parent}) => { // Make sure to return a promise return { - getEconomicCalendar: await getEconomicCalendar() + getEconomicCalendar: await getEconomicCalendar(), }; -}; \ No newline at end of file +}; diff --git a/src/routes/economic-calendar/workers/filterWorker.ts b/src/routes/economic-calendar/workers/filterWorker.ts index 8592b821..e82932de 100644 --- a/src/routes/economic-calendar/workers/filterWorker.ts +++ b/src/routes/economic-calendar/workers/filterWorker.ts @@ -1,17 +1,66 @@ +export const listOfRelevantCountries = [ + { USA: "United States" }, + { CHN: "China" }, + { CAN: "Canada" }, + { GBR: "United Kingdom" }, + { JPN: "Japan" }, + { ISR: "Israel" }, + { BRA: "Brazil" }, + { FRA: "France" }, + { IRL: "Ireland" }, + { DEU: "Germany" }, + { MEX: "Mexico" }, + { IND: "India" }, + { AUS: "Australia" }, + { KOR: "South Korea" }, + { SWE: "Sweden" }, + { NLD: "Netherlands" }, + { CHE: "Switzerland" }, + { TWN: "Taiwan" }, + { ZAF: "South Africa" }, + { HKG: "Hong Kong" }, + { SGP: "Singapore" }, + { ARG: "Argentina" }, + { CHL: "Chile" }, + { PHL: "Philippines" }, + { TUR: "Turkey" }, + { ITA: "Italy" }, + { IDN: "Indonesia" }, + { MYS: "Malaysia" }, + { LUX: "Luxembourg" }, + { VNM: "Vietnam" }, + { NZL: "New Zealand" }, + { DNK: "Denmark" }, + { NOR: "Norway" }, + { FIN: "Finland" }, + { RUS: "Russia" }, + { ARE: "United Arab Emirates" }, +]; + +const countryMap = Object.fromEntries( + listOfRelevantCountries.map((entry) => { + const [code, name] = Object.entries(entry)[0]; + return [name, code]; + }) +); onmessage = async (event: MessageEvent) => { const rawData = event.data?.rawData; const filterList = event.data?.filterList; - const output = rawData?.map(subArray => - subArray?.filter(item => filterList?.includes(item?.country)) + + // Map filterList country names to abbreviations + const filterCodes = filterList?.map((name) => countryMap[name]) || []; + + // Filter rawData based on the mapped country codes + const output = rawData?.map((subArray) => + subArray?.filter((item) => filterCodes.includes(item?.country)) ); - let finalData = { output}; - postMessage({ message: 'success', finalData}); + let finalData = { output }; + postMessage({ message: "success", finalData }); // Sending data back to the main thread //postMessage({ message: 'Data received in the worker', ticker, apiURL }); }; export {}; - \ No newline at end of file diff --git a/src/routes/stock-screener/[strategyId]/+page.svelte b/src/routes/stock-screener/[strategyId]/+page.svelte index 969bc813..a06eea46 100644 --- a/src/routes/stock-screener/[strategyId]/+page.svelte +++ b/src/routes/stock-screener/[strategyId]/+page.svelte @@ -549,7 +549,6 @@ async function handleChangeValue(value) { console.warn(`Unhandled rule: ${ruleName}`); } - console.log(valueMappings[ruleName]) }