feat: animation disable when diff > 200
This commit is contained in:
		
							parent
							
								
									e0b6eab7cf
								
							
						
					
					
						commit
						f089a04ef4
					
				
					 1 changed files with 27 additions and 3 deletions
				
			
		| 
						 | 
					@ -1,5 +1,5 @@
 | 
				
			||||||
import { Button } from "../components/Button.tsx";
 | 
					import { Button } from "../components/Button.tsx";
 | 
				
			||||||
import { useEffect, useRef } from "preact/hooks";
 | 
					import { useEffect, useRef, useLayoutEffect } from "preact/hooks";
 | 
				
			||||||
import { ComponentChildren } from "preact";
 | 
					import { ComponentChildren } from "preact";
 | 
				
			||||||
import { Signal, useSignal } from "@preact/signals";
 | 
					import { Signal, useSignal } from "@preact/signals";
 | 
				
			||||||
import { IS_BROWSER } from "$fresh/runtime.ts";
 | 
					import { IS_BROWSER } from "$fresh/runtime.ts";
 | 
				
			||||||
| 
						 | 
					@ -91,15 +91,39 @@ interface CorpSimple {
 | 
				
			||||||
function StockListByDate({prevSet, rows, name}:{prevSet:Set<string>, 
 | 
					function StockListByDate({prevSet, rows, name}:{prevSet:Set<string>, 
 | 
				
			||||||
  rows:Coperation[],
 | 
					  rows:Coperation[],
 | 
				
			||||||
name: string}){
 | 
					name: string}){
 | 
				
			||||||
 | 
					  const lastCount = useRef(rows.length);
 | 
				
			||||||
 | 
					  const curCount = rows.length;
 | 
				
			||||||
  const parent = useRef<HTMLDivElement>(null);
 | 
					  const parent = useRef<HTMLDivElement>(null);
 | 
				
			||||||
 | 
					  const controller = useRef<{
 | 
				
			||||||
 | 
					    isEnabled: ()=> boolean,
 | 
				
			||||||
 | 
					    disable: ()=>void,
 | 
				
			||||||
 | 
					    enable: ()=> void
 | 
				
			||||||
 | 
					  }| undefined>();
 | 
				
			||||||
  useEffect(()=>{
 | 
					  useEffect(()=>{
 | 
				
			||||||
    (async ()=>{
 | 
					    (async ()=>{
 | 
				
			||||||
      console.log("animation mount on ",name);
 | 
					      console.log("animation mount on ",name);
 | 
				
			||||||
      const {default:autoAnimate} = await import("https://esm.sh/@formkit/auto-animate@0.7.0");
 | 
					      const {default:autoAnimate} = await import("https://esm.sh/@formkit/auto-animate@0.7.0");
 | 
				
			||||||
      parent.current && autoAnimate(parent.current)
 | 
					      if (parent.current){
 | 
				
			||||||
 | 
					        const cntr = autoAnimate(parent.current);
 | 
				
			||||||
 | 
					        controller.current = cntr;
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
    })();
 | 
					    })();
 | 
				
			||||||
  },[parent]);
 | 
					  },[parent]);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  useLayoutEffect(()=>{
 | 
				
			||||||
 | 
					    if (controller.current){
 | 
				
			||||||
 | 
					      if (Math.abs(curCount - lastCount.current) > 200){
 | 
				
			||||||
 | 
					        console.log('disable animation', curCount, "from",  lastCount.current);
 | 
				
			||||||
 | 
					        controller.current.disable();
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					      else {
 | 
				
			||||||
 | 
					        console.log('enable animation', curCount, "from",  lastCount.current);
 | 
				
			||||||
 | 
					        controller.current.enable();
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					      lastCount.current = curCount;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					  }, [parent, rows]);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  return <div ref={parent}>
 | 
					  return <div ref={parent}>
 | 
				
			||||||
  <h2 class="text-lg">{name}</h2>
 | 
					  <h2 class="text-lg">{name}</h2>
 | 
				
			||||||
  {rows.map((row) => {
 | 
					  {rows.map((row) => {
 | 
				
			||||||
| 
						 | 
					@ -109,7 +133,7 @@ name: string}){
 | 
				
			||||||
        key={row.Code}
 | 
					        key={row.Code}
 | 
				
			||||||
        class={[
 | 
					        class={[
 | 
				
			||||||
          "bg-white",
 | 
					          "bg-white",
 | 
				
			||||||
          firstOccur ? "text-[#ff5454]" : "text-black",
 | 
					          firstOccur ? "text-[#ff5454] underline" : "text-black",
 | 
				
			||||||
        ].join(" ")}
 | 
					        ].join(" ")}
 | 
				
			||||||
      >
 | 
					      >
 | 
				
			||||||
        <a href={`https://stockplus.com/m/stocks/KOREA-A${row.Code}`}>
 | 
					        <a href={`https://stockplus.com/m/stocks/KOREA-A${row.Code}`}>
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		
		Reference in a new issue