Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: TODO in AppCard.tsx #16863

Merged
merged 1 commit into from
Sep 27, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 2 additions & 11 deletions packages/ui/components/apps/AppCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,29 +42,20 @@ export function AppCard({ app, credentials, searchText, userAdminTeams }: AppCar
const mutation = useAddAppMutation(null, {
onSuccess: (data) => {
if (data?.setupPending) return;
setIsLoading(false);
showToast(t("app_successfully_installed"), "success");
},
onError: (error) => {
if (error instanceof Error) showToast(error.message || t("app_could_not_be_installed"), "error");
setIsLoading(false);
},
});

const [searchTextIndex, setSearchTextIndex] = useState<number | undefined>(undefined);
/**
* @todo Refactor to eliminate the isLoading state by using mutation.isPending directly.
* Currently, the isLoading state is used to manage the loading indicator due to the delay in loading the next page,
* which is caused by heavy queries in getServersideProps. This causes the loader to turn off before the page changes.
*/
const [isLoading, setIsLoading] = useState<boolean>(mutation.isPending);

useEffect(() => {
setSearchTextIndex(searchText ? app.name.toLowerCase().indexOf(searchText.toLowerCase()) : undefined);
}, [app.name, searchText]);

const handleAppInstall = () => {
setIsLoading(true);
if (isConferencing(app.categories)) {
mutation.mutate({
type: app.type,
Expand Down Expand Up @@ -154,7 +145,7 @@ export function AppCard({ app, credentials, searchText, userAdminTeams }: AppCar
onClick: () => {
handleAppInstall();
},
loading: isLoading,
loading: mutation.isPending,
};
}
return <InstallAppButtonChild paid={app.paid} {...props} />;
Expand All @@ -176,7 +167,7 @@ export function AppCard({ app, credentials, searchText, userAdminTeams }: AppCar
onClick: () => {
handleAppInstall();
},
loading: isLoading,
loading: mutation.isPending,
};
}
return <InstallAppButtonChild paid={app.paid} {...props} />;
Expand Down
Loading