Skip to content

Commit

Permalink
[Dub] Fixed retry for shortening failures (#13824)
Browse files Browse the repository at this point in the history
* fix(dub): retry for shortening failures and open short links within toast with a push

* fix(dub): adds shortcut for retry

* Update CHANGELOG.md and optimise images

---------

Co-authored-by: raycastbot <[email protected]>
  • Loading branch information
jfkisafk and raycastbot authored Aug 14, 2024
1 parent a7506df commit ad5e627
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 39 deletions.
3 changes: 2 additions & 1 deletion extensions/dub/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
# Dub Link Shortener Changelog

## [Renaming] - 2024-08-01
## [Renaming and Fixes] - 2024-08-01
- Rename extension from `dub-link-shortener` to `dub`
- Transfer to `dubinc` organization
- Fixed retry for shortening failures and open short links within toast with a push.

## [README changes] - 2024-07-31

Expand Down
Binary file added extensions/dub/metadata/dub-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added extensions/dub/metadata/dub-2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed extensions/dub/metadata/dub-link-shortener-1.png
Binary file not shown.
Binary file removed extensions/dub/metadata/dub-link-shortener-2.png
Binary file not shown.
60 changes: 31 additions & 29 deletions extensions/dub/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 2 additions & 4 deletions extensions/dub/src/search-links.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { MutatePromise, showFailureToast } from "@raycast/utils";
import type { LinkSchema } from "dub/models/components";
import { withDubClient } from "./with-dub-client";

function SearchLinks() {
export function SearchLinks() {
const { shortLinks, error: linksError, isLoading: isLoadingLinks, mutate } = useShortLinks();

return (
Expand Down Expand Up @@ -181,9 +181,7 @@ const tryDeleteLink = async (linkId: string, mutate: MutatePromise<LinkSchema[]>
title: "❗ Failed to delete link",
primaryAction: {
title: "Retry",
onAction: async () => {
await tryDeleteLink(linkId, mutate);
},
onAction: () => tryDeleteLink(linkId, mutate),
},
});
});
Expand Down
16 changes: 11 additions & 5 deletions extensions/dub/src/shorten-link.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,18 @@ import {
Icon,
showToast,
Toast,
open,
Clipboard,
useNavigation,
LaunchProps,
Keyboard,
} from "@raycast/api";
import { FormValidation, showFailureToast, useCachedPromise, useForm } from "@raycast/utils";
import { createShortLink } from "@/api";
import { fetchLink, isEmpty } from "@utils/clipboard";
import { useTags } from "@hooks/use-tags";
import { useDomains } from "@hooks/use-domains";
import { withDubClient } from "./with-dub-client";
import { SearchLinks } from "@/search-links";

interface ShortLinkFormValues {
url: string;
Expand All @@ -29,7 +30,7 @@ interface ShortLinkFormValues {
}

const ShortenLinkForm = ({ retryValues, args }: { retryValues?: ShortLinkFormValues; args: Arguments.ShortenLink }) => {
const { push, pop } = useNavigation();
const { push } = useNavigation();
const { url, key } = args;
const { data: originalLink, isLoading: isLoadingLink } = useCachedPromise(fetchLink, [], { execute: isEmpty(url) });
const { tags } = useTags();
Expand All @@ -47,11 +48,16 @@ const ShortenLinkForm = ({ retryValues, args }: { retryValues?: ShortLinkFormVal
message: shortLink,
primaryAction: {
title: "Copy Short Link",
shortcut: Keyboard.Shortcut.Common.Copy,
onAction: () => Clipboard.copy(shortLink),
},
secondaryAction: {
title: "Open Short Links",
onAction: () => open("raycast://extensions/quuu/dub-link-shortener/search-links"),
shortcut: Keyboard.Shortcut.Common.Open,
onAction: async (toast) => {
push(<SearchLinks />);
await toast.hide();
},
},
});
})
Expand All @@ -60,13 +66,13 @@ const ShortenLinkForm = ({ retryValues, args }: { retryValues?: ShortLinkFormVal
const toast = await showFailureToast(err, { title: "❗ Failed to create link" });
toast.primaryAction = {
title: "Retry",
shortcut: Keyboard.Shortcut.Common.Refresh,
onAction: () => {
push(<ShortenLinkForm retryValues={vals} args={args} />);
toast.hide();
},
};
})
.finally(pop);
});
},
validation: {
url: FormValidation.Required,
Expand Down

0 comments on commit ad5e627

Please sign in to comment.