11import { Center , VStack , Icon , Text } from "@hope-ui/solid"
22import { Motion } from "solid-motionone"
33import { useContextMenu } from "solid-contextmenu"
4- import { batch , Show } from "solid-js"
4+ import { batch , Show , createSignal , onMount , onCleanup } from "solid-js"
55import { CenterLoading , LinkWithPush , ImageWithError } from "~/components"
66import { usePath , useRouter , useUtil } from "~/hooks"
77import { checkboxOpen , getMainColor , local , selectIndex } from "~/store"
@@ -27,8 +27,25 @@ export const GridItem = (props: { obj: StoreObj; index: number }) => {
2727 const { pushHref, to } = useRouter ( )
2828 const { openWithDoubleClick, toggleWithClick, restoreSelectionCache } =
2929 useSelectWithMouse ( )
30+
31+ const [ isVisible , setIsVisible ] = createSignal ( false )
32+ let ref : HTMLDivElement | undefined
33+
34+ onMount ( ( ) => {
35+ if ( ref ) {
36+ const observer = new IntersectionObserver (
37+ ( [ entry ] ) => {
38+ setIsVisible ( entry . isIntersecting )
39+ } ,
40+ { rootMargin : "50px" } ,
41+ )
42+ observer . observe ( ref )
43+ onCleanup ( ( ) => observer . disconnect ( ) )
44+ }
45+ } )
3046 return (
3147 < Motion . div
48+ ref = { ref }
3249 initial = { { opacity : 0 , scale : 0.9 } }
3350 animate = { { opacity : 1 , scale : 1 } }
3451 transition = { { duration : 0.2 } }
@@ -115,7 +132,7 @@ export const GridItem = (props: { obj: StoreObj; index: number }) => {
115132 } }
116133 />
117134 </ Show >
118- < Show when = { props . obj . thumb } fallback = { objIcon } >
135+ < Show when = { props . obj . thumb && isVisible ( ) } fallback = { objIcon } >
119136 < ImageWithError
120137 maxH = "$full"
121138 maxW = "$full"
0 commit comments