feat: add loading state to NLP prediction query

This commit is contained in:
Aditya 2025-01-30 11:15:18 +05:30
parent 1288eb87cf
commit 4ff19ac57d

View File

@ -1,10 +1,12 @@
/*
* Copyright © 2024 Hexastack. All rights reserved.
*
* Licensed under the GNU Affero General Public License v3.0 (AGPLv3) with the following additional terms:
* 1. The name "Hexabot" is a trademark of Hexastack. You may not use this name in derivative works without express written permission.
* 2. All derivative works must include clear attribution to the original creator and software, Hexastack and Hexabot, in a prominent location (e.g., in the software's "About" section, documentation, and README file).
*/
/*
* Copyright © 2025 Hexastack. All rights reserved.
*
* Licensed under the GNU Affero General Public License v3.0 (AGPLv3) with the following additional terms:
* 1. The name "Hexabot" is a trademark of Hexastack. You may not use this name in derivative works without express written permission.
* 2. All derivative works must include clear attribution to the original creator and software, Hexastack and Hexabot, in a prominent location (e.g., in the software's "About" section, documentation, and README file).
*/
import AddIcon from "@mui/icons-material/Add";
import Check from "@mui/icons-material/Check";
@ -65,6 +67,7 @@ const NlpDatasetSample: FC<NlpDatasetSampleProps> = ({
hasCount: false,
},
);
const [loading, setLoading] = useState(false);
const getNlpValueFromCache = useGetFromCache(EntityType.NLP_VALUE);
// eslint-disable-next-line react-hooks/exhaustive-deps
const defaultValues: INlpSampleFormAttributes = useMemo(
@ -121,7 +124,12 @@ const NlpDatasetSample: FC<NlpDatasetSampleProps> = ({
useQuery({
queryKey: ["nlp-prediction", currentText],
queryFn: async () => {
return await apiClient.predictNlp(currentText);
setLoading(true);
try{
return await apiClient.predictNlp(currentText);
}finally{
setLoading(false);
}
},
onSuccess: (result) => {
const traitEntities: INlpDatasetTraitEntity[] = result.entities.filter(
@ -226,6 +234,7 @@ const NlpDatasetSample: FC<NlpDatasetSampleProps> = ({
})),
);
}}
loading={loading}
/>
</ContentItem>
<Box display="flex" flexDirection="column">