refactor: 优化eslint配置,提升代码质量 (#1341)
* feat: 统一并标准化eslint * lint: napcat.webui * lint: napcat.webui * lint: napcat.core * build: fix * lint: napcat.webui * refactor: 重构eslint * Update README.md
This commit is contained in:
651 files changed
+37978
-37584
No files matched your search
@@ -1,62 +1,62 @@
|
||||
import { useEffect, useRef, useState } from 'react'
|
||||
import { VariableSizeList } from 'react-window'
|
||||
import { useEffect, useRef, useState } from 'react';
|
||||
import { VariableSizeList } from 'react-window';
|
||||
|
||||
import OneBotItemRender, {
|
||||
getItemSize
|
||||
} from '@/components/onebot/display_card/render'
|
||||
getItemSize,
|
||||
} from '@/components/onebot/display_card/render';
|
||||
|
||||
import { isOB11Event } from '@/utils/onebot'
|
||||
import { isOB11Event } from '@/utils/onebot';
|
||||
|
||||
import type { AllOB11WsResponse } from '@/types/onebot'
|
||||
import type { AllOB11WsResponse } from '@/types/onebot';
|
||||
|
||||
export interface OneBotMessageListProps {
|
||||
messages: AllOB11WsResponse[]
|
||||
}
|
||||
|
||||
const OneBotMessageList: React.FC<OneBotMessageListProps> = (props) => {
|
||||
const { messages } = props
|
||||
const containerRef = useRef<HTMLDivElement>(null)
|
||||
const listRef = useRef<VariableSizeList>(null)
|
||||
const [containerHeight, setContainerHeight] = useState(400)
|
||||
const { messages } = props;
|
||||
const containerRef = useRef<HTMLDivElement>(null);
|
||||
const listRef = useRef<VariableSizeList>(null);
|
||||
const [containerHeight, setContainerHeight] = useState(400);
|
||||
|
||||
useEffect(() => {
|
||||
const resizeObserver = new ResizeObserver(() => {
|
||||
if (containerRef.current) {
|
||||
setContainerHeight(containerRef.current.offsetHeight)
|
||||
setContainerHeight(containerRef.current.offsetHeight);
|
||||
}
|
||||
})
|
||||
});
|
||||
|
||||
if (containerRef.current) {
|
||||
resizeObserver.observe(containerRef.current)
|
||||
resizeObserver.observe(containerRef.current);
|
||||
}
|
||||
|
||||
return () => {
|
||||
resizeObserver.disconnect()
|
||||
}
|
||||
}, [])
|
||||
resizeObserver.disconnect();
|
||||
};
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
if (listRef.current) {
|
||||
listRef.current.resetAfterIndex(0, true)
|
||||
listRef.current.resetAfterIndex(0, true);
|
||||
}
|
||||
}, [messages])
|
||||
}, [messages]);
|
||||
|
||||
return (
|
||||
<div className="w-full h-full overflow-hidden" ref={containerRef}>
|
||||
<div className='w-full h-full overflow-hidden' ref={containerRef}>
|
||||
<VariableSizeList
|
||||
ref={listRef}
|
||||
itemCount={messages.length}
|
||||
width="100%"
|
||||
width='100%'
|
||||
style={{
|
||||
overflowX: 'hidden'
|
||||
overflowX: 'hidden',
|
||||
}}
|
||||
itemSize={(idx) => {
|
||||
const msg = messages[idx]
|
||||
const msg = messages[idx];
|
||||
if (isOB11Event(msg)) {
|
||||
const size = getItemSize(msg.post_type)
|
||||
return size
|
||||
const size = getItemSize(msg.post_type);
|
||||
return size;
|
||||
} else {
|
||||
return 100
|
||||
return 100;
|
||||
}
|
||||
}}
|
||||
height={containerHeight}
|
||||
@@ -66,7 +66,7 @@ const OneBotMessageList: React.FC<OneBotMessageListProps> = (props) => {
|
||||
{OneBotItemRender}
|
||||
</VariableSizeList>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
export default OneBotMessageList
|
||||
export default OneBotMessageList;
|
||||
Reference in new issue
Block a user