mirror of
https://github.com/Yidadaa/ChatGPT-Next-Web.git
synced 2025-10-23 00:19:23 +08:00
feat: maskpage&newchatpage adapt new ui framework done
This commit is contained in:
@@ -1,26 +1,35 @@
|
||||
import { useLayoutEffect, useRef } from "react";
|
||||
import { useLayoutEffect, useRef, useState } from "react";
|
||||
|
||||
type Size = {
|
||||
width: number;
|
||||
height: number;
|
||||
};
|
||||
|
||||
export function useWindowSize(callback: (size: Size) => void) {
|
||||
export function useWindowSize(callback?: (size: Size) => void) {
|
||||
const callbackRef = useRef<typeof callback>();
|
||||
|
||||
callbackRef.current = callback;
|
||||
|
||||
const [size, setSize] = useState({
|
||||
width: window.innerWidth,
|
||||
height: window.innerHeight,
|
||||
});
|
||||
|
||||
useLayoutEffect(() => {
|
||||
const onResize = () => {
|
||||
callbackRef.current?.({
|
||||
width: window.innerWidth,
|
||||
height: window.innerHeight,
|
||||
});
|
||||
setSize({
|
||||
width: window.innerWidth,
|
||||
height: window.innerHeight,
|
||||
});
|
||||
};
|
||||
|
||||
window.addEventListener("resize", onResize);
|
||||
|
||||
callback({
|
||||
callback?.({
|
||||
width: window.innerWidth,
|
||||
height: window.innerHeight,
|
||||
});
|
||||
@@ -29,4 +38,6 @@ export function useWindowSize(callback: (size: Size) => void) {
|
||||
window.removeEventListener("resize", onResize);
|
||||
};
|
||||
}, []);
|
||||
|
||||
return size;
|
||||
}
|
||||
|
Reference in New Issue
Block a user