diff --git a/src/js/components/Stream.tsx b/src/js/components/Stream.tsx index 211da4c..4fef28c 100644 --- a/src/js/components/Stream.tsx +++ b/src/js/components/Stream.tsx @@ -26,44 +26,44 @@ export function Stream({ const className = classNames("body", "stream"); const style: React.CSSProperties = endOfStream || isPaused ? { overflowY: "auto" } : { overflowY: "hidden" }; - const ul = useRef(); - const ayat = useMemo(() => { - return stream.map((ayah: Quran.Ayah) => { - return ( -
  • - - {(isPaused || endOfStream) && ( - turnOffSound()} - /> - )} - - {t(locale, "surah")} {formatNumber(surah.id, locale)} - {t(locale, "comma")} {t(locale, "ayah")}{" "} - {formatNumber(ayah.id, locale)} - - -

    {ayah.text}

    -
  • - ); - }); + const ref = useRef(); + const ul = useMemo(() => { + return ( +
      + {stream.map((ayah: Quran.Ayah) => { + return ( +
    • + + {(isPaused || endOfStream) && ( + turnOffSound()} + /> + )} + + {t(locale, "surah")} {formatNumber(surah.id, locale)} + {t(locale, "comma")} {t(locale, "ayah")}{" "} + {formatNumber(ayah.id, locale)} + + +

      {ayah.text}

      +
    • + ); + })} +
    + ); }, [stream.length]); useEffect(() => { - const el = ul.current; + const el = ref.current; if (el) { - const top = el.scrollHeight + el.scrollTop; - el.scrollTo({ behavior: "smooth", top }); + const top = 1024 + el.scrollHeight + el.scrollTop; + el.scrollBy({ behavior: "smooth", top }); el.scrollIntoView({ behavior: "smooth" }); } - }, [ul.current, stream.length]); + }, [stream.length]); - return ( -
      - {ayat} -
    - ); + return ul; }