Skip to content

Commit

Permalink
Spinner only appears on home page
Browse files Browse the repository at this point in the history
  • Loading branch information
krispya committed Aug 3, 2024
1 parent 7db604a commit f21a812
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 5 deletions.
4 changes: 0 additions & 4 deletions app/Canvas.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -164,21 +164,18 @@ function SubscribeToFrameloop() {
type CanvasApi = {
isPaused: boolean
isLoaded: boolean
isLazyLoaded: boolean
pause: () => void
play: () => void
onPauseCallbacks: (() => void)[]
onPlayCallbacks: (() => void)[]
onPause: (callback: () => void) => () => void
onPlay: (callback: () => void) => () => void
setIsLoaded: (isLoaded: boolean) => void
setIsLazyLoaded: (isLazyLoaded: boolean) => void
}

export const useCanvasApi = create<CanvasApi>((set, get) => ({
isPaused: true,
isLoaded: false,
isLazyLoaded: typeof window === 'undefined' ? false : window.location.pathname !== '/',
onPauseCallbacks: [],
onPlayCallbacks: [],
onPause: (callback) => {
Expand Down Expand Up @@ -206,5 +203,4 @@ export const useCanvasApi = create<CanvasApi>((set, get) => ({
onPlay.forEach((fn) => fn())
},
setIsLoaded: (isLoaded) => set({ isLoaded }),
setIsLazyLoaded: (isLazyLoaded) => set({ isLazyLoaded }),
}))
5 changes: 4 additions & 1 deletion components/Spinner.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
'use client'
import { useSpring, a } from '@react-spring/web'
import { useCanvasApi } from 'app/Canvas'
import { usePathname } from 'next/navigation'
import { useEffect } from 'react'

export function Spinner() {
const isLoaded = useCanvasApi((state) => state.isLoaded)
const isLazyLoaded = useCanvasApi((state) => state.isLazyLoaded)
const pathname = usePathname()

const isLazyLoaded = pathname !== '/'

const [props, springApi] = useSpring(() => ({ opacity: isLazyLoaded ? 0 : 1 }))

Expand Down

0 comments on commit f21a812

Please sign in to comment.