Restore Ultracite + fix sidebar (#1233)
This commit is contained in:
parent
8fbfc253fa
commit
947ed094a6
177 changed files with 6908 additions and 8306 deletions
|
|
@ -1,5 +1,5 @@
|
|||
import useSWR from 'swr';
|
||||
import { useRef, useEffect, useCallback, useState } from 'react';
|
||||
import { useCallback, useEffect, useRef, useState } from "react";
|
||||
import useSWR from "swr";
|
||||
|
||||
type ScrollFlag = ScrollBehavior | false;
|
||||
|
||||
|
|
@ -9,21 +9,25 @@ export function useScrollToBottom() {
|
|||
const [isAtBottom, setIsAtBottom] = useState(true);
|
||||
|
||||
const { data: scrollBehavior = false, mutate: setScrollBehavior } =
|
||||
useSWR<ScrollFlag>('messages:should-scroll', null, { fallbackData: false });
|
||||
useSWR<ScrollFlag>("messages:should-scroll", null, { fallbackData: false });
|
||||
|
||||
const handleScroll = useCallback(() => {
|
||||
if (!containerRef.current) return;
|
||||
if (!containerRef.current) {
|
||||
return;
|
||||
}
|
||||
const { scrollTop, scrollHeight, clientHeight } = containerRef.current;
|
||||
|
||||
// Check if we are within 100px of the bottom (like v0 does)
|
||||
setIsAtBottom(scrollTop + clientHeight >= scrollHeight - 100);
|
||||
}, []);
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
if (!containerRef.current) return;
|
||||
if (!containerRef.current) {
|
||||
return;
|
||||
}
|
||||
|
||||
const container = containerRef.current;
|
||||
|
||||
|
||||
const resizeObserver = new ResizeObserver(() => {
|
||||
requestAnimationFrame(() => {
|
||||
handleScroll();
|
||||
|
|
@ -43,7 +47,7 @@ export function useScrollToBottom() {
|
|||
childList: true,
|
||||
subtree: true,
|
||||
attributes: true,
|
||||
attributeFilter: ['style', 'class', 'data-state']
|
||||
attributeFilter: ["style", "class", "data-state"],
|
||||
});
|
||||
|
||||
handleScroll();
|
||||
|
|
@ -56,13 +60,15 @@ export function useScrollToBottom() {
|
|||
|
||||
useEffect(() => {
|
||||
const container = containerRef.current;
|
||||
if (!container) return;
|
||||
if (!container) {
|
||||
return;
|
||||
}
|
||||
|
||||
container.addEventListener('scroll', handleScroll);
|
||||
container.addEventListener("scroll", handleScroll);
|
||||
handleScroll(); // Check initial state
|
||||
|
||||
return () => {
|
||||
container.removeEventListener('scroll', handleScroll);
|
||||
container.removeEventListener("scroll", handleScroll);
|
||||
};
|
||||
}, [handleScroll]);
|
||||
|
||||
|
|
@ -79,10 +85,10 @@ export function useScrollToBottom() {
|
|||
}, [scrollBehavior, setScrollBehavior]);
|
||||
|
||||
const scrollToBottom = useCallback(
|
||||
(scrollBehavior: ScrollBehavior = 'smooth') => {
|
||||
setScrollBehavior(scrollBehavior);
|
||||
(currentScrollBehavior: ScrollBehavior = "smooth") => {
|
||||
setScrollBehavior(currentScrollBehavior);
|
||||
},
|
||||
[setScrollBehavior],
|
||||
[setScrollBehavior]
|
||||
);
|
||||
|
||||
function onViewportEnter() {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue