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

usePromise, useCallablePromise → react-query #164

Merged
merged 7 commits into from
Jun 20, 2023
Merged

Conversation

danvk
Copy link
Collaborator

@danvk danvk commented Jun 15, 2023

Rather than use our own bespoke Promise hooks, we should probably just use react-query, which is wildly popular and supports this use case just fine:
https://stackoverflow.com/questions/62340697/react-query-how-to-usequery-when-button-is-clicked

There's a slight behavior change here: previously if you fetched a rewrite and then selected some new text, we'd show the new text and the old rewrite. Now we clear the rewrite. If we want to go back to the old behavior, we could change to queryKey: [] or queryKey: [!!selection].

@danvk danvk marked this pull request as ready for review June 15, 2023 20:35
@danvk danvk requested a review from cguedes June 15, 2023 20:36
{rewriteCallState.state === 'error' && <span className="bg-red-50">{String(rewriteCallState.error)}</span>}
{rewriteCallState.state === 'loading' && <span>Processing...</span>}
{rewriteCallState.state === 'ok' && (
{error ? <span className="bg-red-50">{String(error)}</span> : null}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why not write !!error && <span className="bg-red-50">{String(error)}</span> here?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Updated.

@codecov
Copy link

codecov bot commented Jun 20, 2023

Codecov Report

Merging #164 (eda2ad3) into main (615e0c1) will increase coverage by 1.48%.
The diff coverage is 0.00%.

@@            Coverage Diff             @@
##             main     #164      +/-   ##
==========================================
+ Coverage   36.70%   38.19%   +1.48%     
==========================================
  Files          52       50       -2     
  Lines        2490     2393      -97     
  Branches      114      112       -2     
==========================================
  Hits          914      914              
+ Misses       1553     1458      -95     
+ Partials       23       21       -2     
Impacted Files Coverage Δ
src/main.tsx 0.00% <0.00%> (ø)
src/panels/ai/SelectionPanelSection.tsx 0.00% <0.00%> (ø)

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@cguedes cguedes merged commit 46878ed into main Jun 20, 2023
10 of 11 checks passed
@cguedes cguedes deleted the use-promise-cleanup branch June 20, 2023 08:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants