minor improvements enhancing code readability

This commit is contained in:
Tobias Maestrini 2024-02-25 23:17:28 +01:00
parent 723e0dd953
commit de56496a18
2 changed files with 23 additions and 19 deletions

View File

@ -33,6 +33,23 @@ const MyTools: React.FC<
/** === USE EFFECT HOOKS === */
React.useEffect(() => {
(async () => {
await initListData();
})();
}, [props]);
React.useEffect(() => {
if (myTools.length > 0 && errorMessage) {
setErrorMessage(undefined);
}
if (myTools.length === 0) {
setErrorMessage(
errorMsgNotFound
);
}
}, [myTools]);
/** === FUNCTIONS === */
async function initListData(): Promise<void> {
if (props.wpLists?.personalToolsList && props.wpSite?.url) {
const tmpTools = await getUsersTools(props.context, props.userEmail, { list: props.wpLists.personalToolsList, siteUrl: props.wpSite.url });
if (tmpTools) {
@ -49,24 +66,12 @@ const MyTools: React.FC<
setSelectableTools(tmpSelectTools);
}
}
})();
}, [props]);
React.useEffect(() => {
if (myTools.length > 0 && errorMessage) {
setErrorMessage(undefined);
}
if (myTools.length === 0) {
setErrorMessage(
errorMsgNotFound
);
}
}, [myTools]);
/** === FUNCTIONS === */
const handleClickOpen = (): void => {
setOpen(true);
};
const handleClose = (): void => {
setOpen(false);
};

View File

@ -40,7 +40,6 @@ export const getSelectableTools = async (
context: WebPartContext,
availableToolsList: ListDefintion,
): Promise<Array<ITool>> => {
console.log([context, availableToolsList]);
const sourceWeb = await getSourceWeb(context, availableToolsList?.siteUrl ?? '');
const sourceList = sourceWeb.lists.getById(availableToolsList?.list?.id ?? '');
const requestRes = await sourceList.items();