(improvement)(webapp) optimize show case query code (#257)

This commit is contained in:
williamhliu
2023-10-18 17:35:38 +08:00
committed by GitHub
parent 65614ed3ba
commit 7b861f563c

View File

@@ -16,22 +16,16 @@ const ShowCase: React.FC<Props> = ({ agentId, onSendMsg }) => {
const [showCaseMap, setShowCaseMap] = useState<ShowCaseMapType>({}); const [showCaseMap, setShowCaseMap] = useState<ShowCaseMapType>({});
const [loading, setLoading] = useState(false); const [loading, setLoading] = useState(false);
const updateData = async (pageNo: number) => { const updateData = async () => {
if (pageNo === 1) { setLoading(true);
setLoading(true); const res = await queryShowCase(agentId, 1, 30);
} setLoading(false);
const res = await queryShowCase(agentId, pageNo, 30); setShowCaseMap(res.data.showCaseMap);
if (pageNo === 1) {
setLoading(false);
}
setShowCaseMap(
pageNo === 1 ? res.data.showCaseMap : { ...showCaseMap, ...res.data.showCaseMap }
);
}; };
useEffect(() => { useEffect(() => {
if (agentId) { if (agentId) {
updateData(1); updateData();
} }
}, [agentId]); }, [agentId]);