Skip to content

[Migadu] cache most results + minor api refactor - #13990

Merged
raycastbot merged 5 commits into
raycast:mainfrom
xmok:ext/migadu
Aug 21, 2024
Merged

raycastbot merged 5 commits into
raycast:mainfrom
xmok:ext/migadu

Conversation

@xmok

@xmok xmok commented Aug 12, 2024

Copy link
Copy Markdown
Contributor

Description

Replaced some of the useState with useCachedState so the data is cached.

In terms of refactoring, I moved the type casting of api responses into the api function itself so there is fewer explicit casting.

Screencast

No screencast needed as functionality has not changed besides data is now cached on future loads.

Checklist

@raycastbot raycastbot added extension fix / improvement Label for PRs with extension's fix improvements extension: migadu Issues related to the migadu extension labels Aug 12, 2024
@raycastbot

Copy link
Copy Markdown
Collaborator

Thank you for the update! 🎉

You can expect an initial review within five business days.

@raycastbot raycastbot added the OP is author The OP of the PR is the author of the extension label Aug 12, 2024
Comment thread extensions/migadu/package.json Resolved

function AliasesIndex({ domain }: { domain: string }) {
const { push } = useNavigation();
const [aliases, setAliases] = useState<Alias[]>([]);

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.

Suggestion (non-blocking): In an effort of pure refactoring, we can use useCachedPromise hook (instead of useCachedState) to replace the whole getDomainAliasesFromApi(), isLoading, error etc. and we won't need useCachedState. So something like:

const {isLoading, error, mutate, data: aliases} = useCachedPromise(getDomainAliases, [domain], {failureToastOptions: {title: "Error while getting domain aliases"}});

This will require some refactoring in callApi: removing the failure toast there and bubbling up the error msg as part of Error instead of ErrorResponse.

This way we can also optimistically mutate based on deletion etc.

This refactoring can be applied to most commands where we are using useCachedState in this PR. If this is intrusive for this PR, it can be handled as part of a separate PR too. What do you think?

Comment thread extensions/migadu/src/aliases.tsx Resolved
Comment thread extensions/migadu/src/rewrites.tsx Resolved

ghost left a comment

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.

I really like this refactor @xmok. Thanks for raising the bar 🔥

Another thing I noticed was the delete resource shortcut. Most Raycast commands/extensions will use Ctrl + x as a standard practice, for easy memorization. For example:

shortcut={Keyboard.Shortcut.Common.Remove}

But Cmd + d also makes sense.

@xmok

ghost commented Aug 15, 2024

Copy link
Copy Markdown
Contributor Author

Great suggestions. I really appreciate the review 👀.

  • We could add the cacheNamespace to cache for sure.
  • As for utilizing useCachedPromise, I have refactored a lot of extensions to use the native Raycast hooks like useFetch and useCachedPromise but refactoring for the sake of refactoring is something I try to avoid. A future PR could replace the current api with the hook but doing it right now seems redundant as the code is working for now. I'll submit a future PR for it and eventually a lot of my older extensions like Purelymail
  • The Keyboard shortcut is also a welcome suggestion.
  • Also updated the deps you mentioned.

Thanks!

ghost left a comment

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.

Can you also please indicate in the CHANGELOG that the delete shortcut has changed?

Comment thread extensions/migadu/src/aliases.tsx Resolved
Comment thread extensions/migadu/src/rewrites.tsx Resolved
@xmok

ghost commented Aug 16, 2024

Copy link
Copy Markdown
Contributor Author

@jfkisafk, thank you for catching the mistake 🤦‍♂️.
I updated the CHANGELOG.

I'll be sure to eventually migrate the extension to use the native hooks in the future which would supersede this PR 🔥.

@xmok xmok closed this Aug 18, 2024
@xmok
xmok deleted the ext/migadu branch August 18, 2024 11:10
@xmok
xmok restored the ext/migadu branch August 18, 2024 11:11
@xmok xmok reopened this Aug 18, 2024

ghost left a comment

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.

Hi 👋

Looks good to me, approved 🔥

@raycastbot
raycastbot merged commit 3d19281 into raycast:main Aug 21, 2024
@github-actions

ghost commented Aug 21, 2024

Copy link
Copy Markdown
Contributor

@raycastbot

ghost commented Aug 21, 2024

Copy link
Copy Markdown
Collaborator

🎉 🎉 🎉

We've rewarded your Raycast account with some credits. You will soon be able to exchange them for some swag.

@xmok
xmok deleted the ext/migadu branch August 21, 2024 12:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

extension fix / improvement Label for PRs with extension's fix improvements extension: migadu Issues related to the migadu extension OP is author The OP of the PR is the author of the extension

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants