Skip to content

refactor: replace custom useLoading hook with ahooks useRequest#2953

Draft
apalchys wants to merge 3 commits intomasterfrom
apalchys/replace-withloading-hook-with-userequest-yyuztt
Draft

refactor: replace custom useLoading hook with ahooks useRequest#2953
apalchys wants to merge 3 commits intomasterfrom
apalchys/replace-withloading-hook-with-userequest-yyuztt

Conversation

@apalchys
Copy link
Copy Markdown
Member

@apalchys apalchys commented Mar 15, 2026

Motivation

  • Remove custom loading wrapper and standardize async request handling with ahooks useRequest for clearer semantics and built-in error/side-effect handling.
  • Consolidate loading state management and reduce duplicated boilerplate around try/catch/finally patterns.

Description

  • Deleted the custom hook file client/src/components/useLoading.tsx and replaced its usage with useRequest from ahooks across multiple modules.
  • Converted const [loading, withLoading] = useLoading() call sites into const { loading, runAsync: fn } = useRequest(..., { manual: true }) or aggregated multiple useRequest loadings into a combined loading flag where appropriate.
  • Added onError handlers to several useRequest calls to surface user-facing messages via message.error and preserved previous error-handling behavior in most places.
  • Updated many pages and components (for example under Mentor, Teams, Students, Interviews, Notifications, Opportunities, MentorRegistry, AutoTest, StudentDashboard, and others) to call the new runAsync functions and to use useRequest for manual triggers and refresh dependencies.

@apalchys apalchys changed the title Replace custom useLoading hook with ahooks useRequest across client components refactor: replace custom useLoading hook with ahooks useRequest Mar 15, 2026
@apalchys apalchys added deploy and removed codex labels Mar 15, 2026
Base automatically changed from apalchys/client-improvements to master March 16, 2026 15:59
@apalchys apalchys force-pushed the apalchys/replace-withloading-hook-with-userequest-yyuztt branch from c713d7c to 37073dd Compare March 16, 2026 17:31
Copy link
Copy Markdown
Contributor

@AlreadyBored AlreadyBored left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

useLoading swallowed errors — callers never saw exceptions, just got undefined back. runAsync re-throws after onError, so any call site without try/catch will now produce an unhandled promise rejection. Is that what we want?

},
);

const handleDeleteConsent = withLoading(async () => {
Copy link
Copy Markdown
Contributor

@AlreadyBored AlreadyBored Mar 17, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These two funcs lost their withLoading wrapping entirely. No loading state, no error handling, is it okay?

const { loading: loadingCancelMentor, runAsync: cancelMentor } = useRequest(
async (githubId: string) => {
setModalData(null);
await mentorRegistryService.cancelMentorRegistry(githubId);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No onError here — if the request fails, the user gets no feedback.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants