diff --git a/ui/src/components/summaryitemcomponents/CardSummary.svelte b/ui/src/components/summaryitemcomponents/CardSummary.svelte index f98ef984..7e7983fe 100644 --- a/ui/src/components/summaryitemcomponents/CardSummary.svelte +++ b/ui/src/components/summaryitemcomponents/CardSummary.svelte @@ -4,10 +4,10 @@ import { createEventDispatcher } from "svelte"; import { printTimeDiff, convertSpecialCharUrl } from "../../utils/utils"; import SendAlertModal from "../misccomponents/SendAlertModal.svelte"; - import { userSession$ } from "../../stores"; + import { userSession$, isLoggedIn } from "../../stores"; import { CONSTS } from "../../utils/utils"; import { navigateTo } from "svelte-router-spa"; - import { onMount } from "svelte"; + import { onDestroy } from "svelte"; export let value; export let isHtmlHintComp = false; @@ -23,14 +23,11 @@ const perfThreshold = () => dispatch("perfThreshold"); const htmlHintThreshold = () => dispatch("htmlHintThreshold"); - const emailAlertModal = () => { - userSession$.subscribe(async x => { - userApiKey = x.apiKey; - let fullUrl = convertSpecialCharUrl(value.url) - const res = await fetch(`${CONSTS.API}/api/getalertemailaddresses/${userApiKey}/${fullUrl}`); - sharedEmailAddresses = await res.json(); - showShareAlert = true; - }); + const emailAlertModal = async () => { + let fullUrl = convertSpecialCharUrl(value.url) + const res = await fetch(`${CONSTS.API}/api/getalertemailaddresses/${userApiKey}/${fullUrl}`); + sharedEmailAddresses = await res.json(); + showShareAlert = true; }; const navigateToLatestScan = () => { @@ -38,19 +35,21 @@ // Force reload page otherwise Svelte would not refresh the content location.reload(true); } - - onMount(async () => { - // Check if scan has any previous scans - userSession$.subscribe(async x => { - if (x) { - userApiKey = x.apiKey; - let fullUrl = convertSpecialCharUrl(value.url) - const res = await fetch(`${CONSTS.API}/api/scanSummaryFromUrl/${userApiKey}/${fullUrl}`); - previousScans = await res.json(); - } - }); - }) + const getPreviousScans = async () => { + let fullUrl = convertSpecialCharUrl(value.url) + const res = await fetch(`${CONSTS.API}/api/scanSummaryFromUrl/${userApiKey}/${fullUrl}`); + previousScans = await res.json(); + }; + + const userSubscriber = userSession$.subscribe(x => { + if (x) { + userApiKey = x.apiKey; + getPreviousScans(); + } + }); + + onDestroy(userSubscriber);