diff --git a/src/lib/components/WatchListCard.svelte b/src/lib/components/WatchListCard.svelte index 4bc992d0..bc3e4281 100644 --- a/src/lib/components/WatchListCard.svelte +++ b/src/lib/components/WatchListCard.svelte @@ -507,11 +507,6 @@ if(watchList && isLoaded) Empty Watchlist - - - - - diff --git a/src/routes/+layout.svelte b/src/routes/+layout.svelte index 9ebfdda0..df53bda9 100644 --- a/src/routes/+layout.svelte +++ b/src/routes/+layout.svelte @@ -653,7 +653,7 @@ $: { - + Watchlist diff --git a/src/routes/api/update-options-watchlist/+server.ts b/src/routes/api/update-options-watchlist/+server.ts index 599b0a39..1e08d37d 100644 --- a/src/routes/api/update-options-watchlist/+server.ts +++ b/src/routes/api/update-options-watchlist/+server.ts @@ -6,29 +6,43 @@ export const POST: RequestHandler = async ({ request, locals }) => { const { pb } = locals; let output; + try { + // Ensure itemIdList is always an array. + const itemIdList = Array.isArray(data?.itemIdList) + ? data?.itemIdList + : [data?.itemIdList]; + const watchList = await pb.collection("optionsWatchlist").getOne(data?.id); - if (watchList?.optionsId?.includes(data?.itemId)) { - // Remove ticker from the watchlist. + // Check if all items in itemIdList are already in the watchlist. + const allItemsInWatchList = itemIdList.every((item) => + watchList?.optionsId.includes(item) + ); + + if (allItemsInWatchList) { + // Remove tickers from the watchlist. const newTickerList = watchList?.optionsId.filter( - (item) => item !== data?.itemId + (item) => !itemIdList.includes(item) ); output = await pb .collection("optionsWatchlist") .update(data?.id, { optionsId: newTickerList }); } else { - // Add ticker to the watchlist. - const newTickerList = [...watchList?.optionsId, data?.itemId]; + // Add new tickers to the watchlist. + const newTickerList = Array.from( + new Set([...watchList?.optionsId, ...itemIdList]) + ); output = await pb .collection("optionsWatchlist") .update(data?.id, { optionsId: newTickerList }); } } catch (e) { + // Handle case where watchlist does not exist. output = await pb.collection("optionsWatchlist").create( serialize({ user: locals?.user?.id, - optionsId: JSON.stringify([data?.itemId]), + optionsId: JSON.stringify(data?.itemIdList), }) ); } diff --git a/src/routes/options-flow/+page.svelte b/src/routes/options-flow/+page.svelte index 080c3745..815f6ffd 100644 --- a/src/routes/options-flow/+page.svelte +++ b/src/routes/options-flow/+page.svelte @@ -738,7 +738,7 @@ async function addToWatchlist(itemId) { if(data?.user?.tier === 'Pro') { try { const postData = { - 'itemId': itemId, + 'itemIdList': [itemId], 'id': optionsWatchlist?.id }; diff --git a/src/routes/watchlist/+layout.svelte b/src/routes/watchlist/+layout.svelte new file mode 100644 index 00000000..2ee03433 --- /dev/null +++ b/src/routes/watchlist/+layout.svelte @@ -0,0 +1,202 @@ + + + + + + + + + + + +
+ + + +
+ +
+
+ + +
+ +
+
+ +
+
+

+ Watchlist +

+
+ + + Monitor the performance and recent updates of your favorite options. + +
+ + + + + +
+ + + + +
+ + + +
+ {#each tabs as item, i} + + {/each} +
+ + + + +
+ + + + + +
+ + + +
+
+ + +
+ + + +
+ + + + \ No newline at end of file diff --git a/src/routes/watchlist/options/+page.server.ts b/src/routes/watchlist/options/+page.server.ts index a2196038..5cbff952 100644 --- a/src/routes/watchlist/options/+page.server.ts +++ b/src/routes/watchlist/options/+page.server.ts @@ -21,13 +21,13 @@ export const load = async ({ locals }) => { body: JSON.stringify(postData), }); const output = await response.json(); - return output; + return { id: watchList?.id, optionsList: output }; } else { - return []; + return { id: "", optionsList: [] }; } } catch (e) { console.error("Error fetching options watchlist or Benzinga data:", e); - return []; + return { id: "", optionsList: [] }; } }; diff --git a/src/routes/watchlist/options/+page.svelte b/src/routes/watchlist/options/+page.svelte index 66b4bbcb..a08320e7 100644 --- a/src/routes/watchlist/options/+page.svelte +++ b/src/routes/watchlist/options/+page.svelte @@ -1,22 +1,42 @@ @@ -85,75 +167,53 @@ let optionsWatchlist = data?.getOptionsWatchlist
- - - +
-
+
-
-
- - -
-
-

- Watchlist -

-
- - - Monitor the performance and recent updates of your favorite options. - -
- - - -
- - - - - - - - - - - - - -
- logo -
-
- - -
-
- + {#if isLoaded} {#if optionsWatchlist?.length !== 0} +
+ {#if editMode} + + {/if} + +
+
+ + @@ -175,9 +235,18 @@ let optionsWatchlist = data?.getOptionsWatchlist {formatTime(item?.time)} + + - - -
TimeSymbol Date ExpiryDTE Strike C/P Sent. handleFilter(item?.id)} class="flex flex-row items-center text-sm sm:text-[1rem] text-start"> + + + {item?.ticker} + + {formatDate(item?.date)} + {reformatDate(item?.date_expiration)} + {item?.dte < 0 ? 'expired' : item?.dte +'d'} @@ -210,20 +279,20 @@ let optionsWatchlist = data?.getOptionsWatchlist {abbreviateNumber(item?.cost_basis)} - {item?.type} + + {item?.option_activity_type} + {new Intl.NumberFormat("en", { minimumFractionDigits: 0, maximumFractionDigits: 0 }).format(item?.volume)} + {new Intl.NumberFormat("en", { minimumFractionDigits: 0, maximumFractionDigits: 0 @@ -245,7 +314,7 @@ let optionsWatchlist = data?.getOptionsWatchlist - + {:else}
@@ -274,59 +343,21 @@ let optionsWatchlist = data?.getOptionsWatchlist
{/if} + {:else} +
+
+ +
+
+ {/if} + - - diff --git a/src/routes/watchlist/stocks/+page.svelte b/src/routes/watchlist/stocks/+page.svelte index eeba2a42..45f836bd 100644 --- a/src/routes/watchlist/stocks/+page.svelte +++ b/src/routes/watchlist/stocks/+page.svelte @@ -16,7 +16,7 @@ let cloudFrontUrl = import.meta.env.VITE_IMAGE_URL; -export let data../$types.js; +export let data; /* @@ -156,7 +156,7 @@ async function createWatchList(event) { clicked?.dispatchEvent(new MouseEvent('click')); const anchor = document.createElement('a'); - anchor.href = '/watchlist'; + anchor.href = '/watchlist/stocks'; anchor.dispatchEvent(new MouseEvent('click')); @@ -371,64 +371,15 @@ onDestroy( () => {
- -
-
+
-
-
- - -
-
-

- Watchlist -

-
- - - Monitor the performance and recent updates of your favorite stocks. - -
- - - -
- - - - - - - - - - - - - -
- logo -
-
- - -
-
- - {#if isLoaded}