Skip to content

usePromise, useCallablePromise → react-query#164

Merged
cguedes merged 7 commits into
mainfrom
use-promise-cleanup
Jun 20, 2023
Merged

usePromise, useCallablePromise → react-query#164
cguedes merged 7 commits into
mainfrom
use-promise-cleanup

Conversation

@danvk

@danvk danvk commented Jun 15, 2023

Copy link
Copy Markdown
Collaborator

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
Comment thread src/panels/ai/SelectionPanelSection.tsx Outdated
{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
Copy Markdown
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
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Updated.

@codecov

codecov Bot commented Jun 20, 2023

Copy link
Copy Markdown

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
@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.

3 participants