diff --git a/src/routes/analysts/[slug]/+page.server.ts b/src/routes/analysts/[slug]/+page.server.ts index 6d23a6ce..d40ae441 100644 --- a/src/routes/analysts/[slug]/+page.server.ts +++ b/src/routes/analysts/[slug]/+page.server.ts @@ -13,7 +13,7 @@ export const load = async ({ locals, params }) => { body: JSON.stringify(postData), }); - const output = await response.json(); + const output = await response.json() || {}; return output; }; diff --git a/src/routes/analysts/[slug]/+page.svelte b/src/routes/analysts/[slug]/+page.svelte index 114c7d75..17e51773 100644 --- a/src/routes/analysts/[slug]/+page.svelte +++ b/src/routes/analysts/[slug]/+page.svelte @@ -5,6 +5,8 @@ import { onMount } from "svelte"; import HoverStockChart from "$lib/components/HoverStockChart.svelte"; import RatingsChart from "$lib/components/RatingsChart.svelte"; + import Infobox from "$lib/components/Infobox.svelte"; + export let data; let analystStats = data?.getAnalystStats; @@ -16,7 +18,7 @@ let analystScore = analystStats?.analystScore; let rank = analystStats?.rank; - let analystName = analystStats?.analystName; + let analystName = analystStats?.analystName ?? "n/a"; let companyName = analystStats?.companyName; let totalRatings = analystStats?.totalRatings; let successRate = analystStats?.successRate; @@ -30,7 +32,7 @@ function processTickerData(data) { const tickerMap = new Map(); - data.forEach((item) => { + data?.forEach((item) => { const { ticker } = item; if (!ticker) return; // Skip if ticker is not defined @@ -212,7 +214,7 @@
  • Home
  • Analyst
  • -
  • {analystName}
  • +
  • {analystName ?? "n/a"}
  • @@ -242,15 +244,15 @@

    - {analystName} + {analystName ?? "n/a"}

    - Stock Analyst at {companyName} + Stock Analyst at {companyName ?? "n/a"}

    {#each Array.from({ length: 5 }) as _, i} - {#if i < Math.floor(analystScore)} + {#if i < Math?.floor(analystScore)} ({analystScore})({analystScore ?? "n/a"})
    @@ -288,19 +290,19 @@ >
    - # {rank} + # {rank ?? "n/a"}
    - Out of {numOfAnalysts} analysts + Out of {numOfAnalysts ?? "n/a"} analysts
    - {totalRatings} + {totalRatings ?? "n/a"}
    = 0 + class={successRate >= 0 && successRate !== undefined ? "before:content-['+'] text-[#36D984]" - : "text-[#EF4444]"}>{successRate?.toFixed(2)}%{successRate !== undefined + ? successRate?.toFixed(2) + "%" + : "n/a"}
    = 0 + class={avgReturn >= 0 && avgReturn !== undefined ? "before:content-['+'] text-[#36D984]" - : "text-[#EF4444]"}>{avgReturn?.toFixed(2)}%{avgReturn !== undefined + ? avgReturn?.toFixed(2) + "%" + : "n/a"}
    -
    -
    -
    -
    Main Sectors:
    -
    - {#each data?.getAnalystStats?.mainSectors as item} - listItem?.title === item, - )?.link} - class="px-3 text-sm py-1 sm:text-[1rem] rounded-md bg-white bg-opacity-[0.1] sm:hover:bg-opacity-[0.2] ml-0" - > - {item} - - {/each} + {#if data?.getAnalystStats?.mainSectors?.length > 0} +
    + -
    -
    - Top Industries: -
    -
    - {#each data?.getAnalystStats?.mainIndustries as item} - - {item} - - {/each} +
    +
    + Top Industries: +
    +
    + {#each data?.getAnalystStats?.mainIndustries as item} + + {item} + + {/each} +
    -
    + {/if} - - {numOfStocks} Stocks - + {#if rawData?.length > 0} + + {numOfStocks} Stocks + -
    -
    - +
    -
    - - - - {#each stockList as item, index} - - + + + + + {#each stockList as item, index} + + - - - {item?.name?.length > charNumber - ? item?.name?.slice(0, charNumber) + "..." - : item?.name} + + - + - + - + - + - - - - - {#if checkedSymbol === item?.ticker} - + + {#if checkedSymbol === item?.ticker} + - - {/if} - {/each} - -
    - {#if index >= 5 && data?.user?.tier !== "Pro"} - - - XXXX - - -
    - XXXXXXXXXXXXXXXX -
    - -
    - - - - - +
    + {#if index >= 5 && data?.user?.tier !== "Pro"} + - Upgrade + XXXX + + +
    + XXXXXXXXXXXXXXXX +
    + +
    + + + + + + + Upgrade + +
    +
    + {:else} +
    + + + + {item?.name?.length > charNumber + ? item?.name?.slice(0, charNumber) + "..." + : item?.name}
    - - {:else} -
    - + {/if} +
    +
    + {item?.action_company}: + + {item?.rating_current}
    - {/if} -
    -
    - {item?.action_company}: - - {item?.rating_current} - -
    -
    +
    + {#if Math?.ceil(item?.adjusted_pt_prior) !== 0} + {Math?.ceil(item?.adjusted_pt_prior)} + + {Math?.ceil(item?.adjusted_pt_current)} + {:else if Math?.ceil(item?.adjusted_pt_current) !== 0} + {Math?.ceil(item?.adjusted_pt_current)} + {:else} + n/a + {/if} +
    +
    -
    - {#if Math?.ceil(item?.adjusted_pt_prior) !== 0} - {Math?.ceil(item?.adjusted_pt_prior)} - - {Math?.ceil(item?.adjusted_pt_current)} - {:else if Math?.ceil(item?.adjusted_pt_current) !== 0} - {Math?.ceil(item?.adjusted_pt_current)} - {:else} - n/a - {/if} -
    -
    + {item?.price !== null ? item?.price : "n/a"} + - {item?.price !== null ? item?.price : "n/a"} - + {item?.upside !== null ? item?.upside + "%" : "n/a"} + - {item?.upside !== null ? item?.upside + "%" : "n/a"} - + {item?.ratings !== null ? item?.ratings : "n/a"} + - {item?.ratings !== null ? item?.ratings : "n/a"} - - {new Date(item?.date).toLocaleString("en-US", { - month: "short", - day: "numeric", - year: "numeric", - daySuffix: "2-digit", - })} -
    -
    -
    -
    +
    + {new Date(item?.date).toLocaleString("en-US", { + month: "short", + day: "numeric", + year: "numeric", + daySuffix: "2-digit", + })} +
    +
    +
    - ({ - ...item, - type: item?.rating_current, - }), - )} - symbol={item?.ticker} - numOfRatings={item?.ratings} - /> +
    + ({ + ...item, + type: item?.rating_current, + }), + )} + symbol={item?.ticker} + numOfRatings={item?.ratings} + /> +
    -
    -
    +
    + + {/if} + {/each} + + +
    -
    + {:else} +
    + +
    + {/if}