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

@ -25,30 +25,15 @@ const MyTools: React.FC<
const [selectableTools, setSelectableTools] = React.useState<Array<ITool>>(
[]
);
/** === VARIABLES === */
const errorMsgNotFound = "Could not find any tools saved for your user. Select 'Edit' to add some tools to this list.";
const errorMsgOnSave = "Something went wrong when saving your tools. Please try again or contact support.";
/** === USE EFFECT HOOKS === */
React.useEffect(() => {
(async () => {
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) {
setMyTools(tmpTools);
} else {
setErrorMessage(
errorMsgNotFound
);
}
}
if (props.wpLists?.availableToolsList && props.wpSite?.url) {
const tmpSelectTools = await getSelectableTools(props.context, { list: props.wpLists.availableToolsList, siteUrl: props.wpSite.url });
if (tmpSelectTools) {
setSelectableTools(tmpSelectTools);
}
}
await initListData();
})();
}, [props]);
@ -64,9 +49,29 @@ const MyTools: React.FC<
}, [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) {
setMyTools(tmpTools);
} else {
setErrorMessage(
errorMsgNotFound
);
}
}
if (props.wpLists?.availableToolsList && props.wpSite?.url) {
const tmpSelectTools = await getSelectableTools(props.context, { list: props.wpLists.availableToolsList, siteUrl: props.wpSite.url });
if (tmpSelectTools) {
setSelectableTools(tmpSelectTools);
}
}
}
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();