chore: stop scrolling when wheeling in chat page
This commit is contained in:
@@ -74,7 +74,6 @@ const CanvasImageEditor: React.FC<CanvasImageEditorProps> = forwardRef(
|
||||
onScaleImageSize,
|
||||
handleUpdateImageList,
|
||||
handleUpdateMaskList,
|
||||
uploadButton,
|
||||
maskUpload
|
||||
},
|
||||
ref
|
||||
@@ -203,6 +202,7 @@ const CanvasImageEditor: React.FC<CanvasImageEditorProps> = forwardRef(
|
||||
|
||||
loadMaksWorkerRef.current!.onmessage = (event: any) => {
|
||||
if (event.data.type === 'done' && event.data.imageData) {
|
||||
console.log('load mask done');
|
||||
// draw the data to the overlay canvas
|
||||
const ctx = overlayCanvasRef.current!.getContext('2d')!;
|
||||
ctx.putImageData(event.data.imageData, 0, 0);
|
||||
@@ -406,8 +406,6 @@ const CanvasImageEditor: React.FC<CanvasImageEditorProps> = forwardRef(
|
||||
height: canvasRef.current!.height
|
||||
});
|
||||
|
||||
console.log('Image status:', imageStatus, negativeMaskRef.current);
|
||||
|
||||
if (imageStatus.isResetNeeded) {
|
||||
onReset();
|
||||
resetCanvas();
|
||||
@@ -424,6 +422,7 @@ const CanvasImageEditor: React.FC<CanvasImageEditorProps> = forwardRef(
|
||||
) {
|
||||
invertPainting(true);
|
||||
}
|
||||
console.log('Image status:', imageStatus, negativeMaskRef.current);
|
||||
|
||||
updateCursorSize();
|
||||
}, [drawImage, imageStatus.isOriginal, imageStatus.isResetNeeded]);
|
||||
|
||||
@@ -32,7 +32,6 @@ const ToolsBar: React.FC<ToolsBarProps> = (props) => {
|
||||
disabled,
|
||||
loading,
|
||||
lineWidth,
|
||||
uploadButton,
|
||||
invertMask,
|
||||
handleBrushSizeChange,
|
||||
undo,
|
||||
@@ -94,7 +93,6 @@ const ToolsBar: React.FC<ToolsBarProps> = (props) => {
|
||||
<ClearOutlined className="font-size-14" />
|
||||
</Button>
|
||||
</Tooltip>
|
||||
{uploadButton}
|
||||
<UploadImg
|
||||
disabled={loading || invertMask}
|
||||
handleUpdateImgList={handleUpdateImageList}
|
||||
|
||||
@@ -32,6 +32,9 @@ export default function useOverlayScroller(data?: {
|
||||
const scrollEventElement = React.useRef<any>(null);
|
||||
const instanceRef = React.useRef<any>(null);
|
||||
const initialized = React.useRef(false);
|
||||
const scrollElementRef = React.useRef<any>(null);
|
||||
const stopUpdatePosition = React.useRef(false);
|
||||
const timerRef = React.useRef<any>(null);
|
||||
const [initialize, instance] = useOverlayScrollbars({
|
||||
options: {
|
||||
update: {
|
||||
@@ -57,6 +60,20 @@ export default function useOverlayScroller(data?: {
|
||||
scrollEventElement.current =
|
||||
instanceRef.current?.elements()?.scrollEventElement;
|
||||
|
||||
const handleOnScroll = () => {
|
||||
const scrollTop = scrollEventElement.current?.scrollTop;
|
||||
const scrollHeight = scrollEventElement.current?.scrollHeight;
|
||||
const clientHeight = scrollEventElement.current?.clientHeight;
|
||||
|
||||
const isBottom = scrollTop + clientHeight + 20 >= scrollHeight;
|
||||
|
||||
if (isBottom) {
|
||||
stopUpdatePosition.current = false;
|
||||
} else {
|
||||
stopUpdatePosition.current = true;
|
||||
}
|
||||
};
|
||||
|
||||
const throttledScroll = React.useCallback(
|
||||
throttle(() => {
|
||||
scrollEventElement.current?.scrollTo?.({
|
||||
@@ -79,6 +96,9 @@ export default function useOverlayScroller(data?: {
|
||||
// scroll to bottom
|
||||
const throttledUpdateScrollerPosition = React.useCallback(
|
||||
(delay?: number) => {
|
||||
if (stopUpdatePosition.current) {
|
||||
return;
|
||||
}
|
||||
if (delay === 0) {
|
||||
scrollauto();
|
||||
} else {
|
||||
@@ -103,6 +123,29 @@ export default function useOverlayScroller(data?: {
|
||||
instanceRef.current?.elements()?.scrollEventElement;
|
||||
};
|
||||
|
||||
const handleWheelCallback = React.useCallback((e: any) => {
|
||||
handleOnScroll();
|
||||
if (timerRef.current) {
|
||||
clearTimeout(timerRef.current);
|
||||
}
|
||||
timerRef.current = setTimeout(() => {
|
||||
stopUpdatePosition.current = false;
|
||||
}, 1500);
|
||||
}, []);
|
||||
|
||||
// add wheel event
|
||||
const handleWheelEvent = () => {
|
||||
scrollElementRef.current?.addEventListener?.('wheel', handleWheelCallback);
|
||||
};
|
||||
|
||||
// remove wheel event
|
||||
const removeWheelEvent = () => {
|
||||
scrollElementRef.current?.removeEventListener?.(
|
||||
'wheel',
|
||||
handleWheelCallback
|
||||
);
|
||||
};
|
||||
|
||||
const createInstance = React.useCallback(
|
||||
(el: any) => {
|
||||
if (instanceRef.current) {
|
||||
@@ -110,10 +153,12 @@ export default function useOverlayScroller(data?: {
|
||||
}
|
||||
if (el) {
|
||||
initialize(el);
|
||||
scrollElementRef.current = el;
|
||||
initialized.current = true;
|
||||
instanceRef.current = instance?.();
|
||||
scrollEventElement.current =
|
||||
instanceRef.current?.elements()?.scrollEventElement;
|
||||
handleWheelEvent();
|
||||
}
|
||||
return instanceRef.current;
|
||||
},
|
||||
@@ -123,6 +168,7 @@ export default function useOverlayScroller(data?: {
|
||||
useEffect(() => {
|
||||
return () => {
|
||||
instanceRef.current?.destroy?.();
|
||||
removeWheelEvent();
|
||||
};
|
||||
}, [instance]);
|
||||
|
||||
|
||||
@@ -176,7 +176,6 @@ export default function useChatCompletion(
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
const throttleUpdatePosition = _.throttle(updateScrollerPosition, 100);
|
||||
|
||||
useEffect(() => {
|
||||
if (scroller.current) {
|
||||
|
||||
Reference in New Issue
Block a user