Skip to content

Commit

Permalink
Save clear timeouts
Browse files Browse the repository at this point in the history
  • Loading branch information
harsh-mn-yral committed Feb 12, 2024
1 parent c0308ef commit a4f5300
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 30 deletions.
6 changes: 4 additions & 2 deletions packages/experiments/src/routes/(feed)/up-down/+layout.svelte
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
<script lang="ts">
import FeedLayout from '@hnn/components/experiments/layout/FeedLayout.svelte'
import { showOnboardingPopup } from '$lib/stores/popups'
import { onMount } from 'svelte'
import { onDestroy, onMount } from 'svelte'
let onboarding: any
let onboardingTimeout: ReturnType<typeof setTimeout>
function mountOnboarding() {
setTimeout(
onboardingTimeout = setTimeout(
() =>
import('$lib/components/popup/Onboarding.svelte').then(
(d) => (onboarding = d.default),
Expand All @@ -15,6 +16,7 @@ function mountOnboarding() {
}
onMount(() => mountOnboarding())
onDestroy(() => clearTimeout(onboardingTimeout))
</script>

<svelte:head>
Expand Down
26 changes: 14 additions & 12 deletions packages/experiments/src/routes/+layout.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import '@hnn/components/tailwind.css'
import NetworkStatus from '@hnn/components/network-status/NetworkStatus.svelte'
import { registerEvent } from '@hnn/components/analytics/GA.utils'
import { onMount } from 'svelte'
import { onDestroy, onMount } from 'svelte'
import { authState } from '$lib/stores/auth'
import userProfile from '$lib/stores/userProfile'
import { removeSplashScreen } from '$lib/stores/popups'
Expand All @@ -23,15 +23,15 @@ function registerServiceWorker() {
}
let GA: any
let GATimeout: ReturnType<typeof setTimeout>
function initializeGA() {
try {
import('@hnn/components/analytics/GA.svelte').then((d) => {
GA = d.default
console.info('loaded GA')
})
} catch (_) {
Log('warn', 'Could not load GA')
}
GATimeout = setTimeout(async () => {
try {
GA = (await import('@hnn/components/analytics/GA.svelte')).default
} catch (_) {
Log('warn', 'Could not load GA')
}
}, 6000)
}
function listenForUnhandledRejections() {
Expand All @@ -48,11 +48,13 @@ onMount(() => {
initDb()
listenForUnhandledRejections()
registerServiceWorker()
setTimeout(() => {
initializeGA()
}, 6000)
initializeGA()
removeSplashScreen()
})
onDestroy(() => {
clearTimeout(GATimeout)
})
</script>

<svelte:window
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,12 +129,7 @@ onMount(async () => {
$hotOrNotFeedVideos = []
}
await tick()
setTimeout(
() => {
fetchNextVideos()
},
data.post ? 3000 : 0,
)
fetchNextVideos()
handleParams()
})
Expand Down
23 changes: 13 additions & 10 deletions packages/web-client/src/routes/+layout.svelte
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<script lang="ts">
import '@hnn/components/tailwind.css'
import { onMount } from 'svelte'
import { onDestroy, onMount } from 'svelte'
import { authState } from '$lib/stores/auth'
import LoginPopup from '$lib/components/auth/LoginPopup.svelte'
import Log from '$lib/utils/Log'
Expand All @@ -25,12 +25,15 @@ function registerServiceWorker() {
}
let GA: any
async function initializeGA() {
try {
GA = (await import('@hnn/components/analytics/GA.svelte')).default
} catch (_) {
Log('warn', 'Could not load GA')
}
let GATimeout: ReturnType<typeof setTimeout>
function initializeGA() {
GATimeout = setTimeout(async () => {
try {
GA = (await import('@hnn/components/analytics/GA.svelte')).default
} catch (_) {
Log('warn', 'Could not load GA')
}
}, 6000)
}
function listenForUnhandledRejections() {
Expand All @@ -48,12 +51,12 @@ onMount(() => {
listenForUnhandledRejections()
initializeAuthClient()
registerServiceWorker()
setTimeout(() => {
initializeGA()
}, 6000)
initializeGA()
removeSplashScreen()
})
onDestroy(() => clearTimeout(GATimeout))
beforeNavigate(({ from, to, type }) => {
if (type === 'popstate') return
Expand Down

0 comments on commit a4f5300

Please sign in to comment.