Skip to content

Commit

Permalink
✨ refactor: Update copyLink method to accept optional ID parameter an…
Browse files Browse the repository at this point in the history
…d improve link sharing logic
  • Loading branch information
vaayne committed Jan 18, 2025
1 parent 75e2032 commit 5be0669
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 11 deletions.
2 changes: 1 addition & 1 deletion web/src/components/article/article-actions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ interface ArticleActionsProps {
isShared: boolean;
isExpired: boolean;
};
copyLink?: () => Promise<void>;
copyLink?: (id?: string) => Promise<void>;
shareExpireTime?: Date;
onUpdateExpiration: (date: Date) => Promise<void>;
}
Expand Down
15 changes: 5 additions & 10 deletions web/src/components/bookmarks/bookmark-detail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -125,14 +125,14 @@ export default function BookmarkDetailPage({ id }: { id: string }) {
setIsLoading(true);
const expiresAt = new Date();
expiresAt.setDate(expiresAt.getDate() + 7); // Share for 7 days
await shareContent(bookmark.id, {
const sharedContent = await shareContent(bookmark.id, {
expires_at: expiresAt.toISOString(),
});
toast({
title: "Success",
description: "Article shared successfully",
});
handleCopyLink();
await handleCopyLink(sharedContent.id);
} catch (error) {
toast({
title: "Error",
Expand Down Expand Up @@ -163,10 +163,9 @@ export default function BookmarkDetailPage({ id }: { id: string }) {
}
};

const handleCopyLink = async () => {
const handleCopyLink = async (id?: string) => {
try {
setIsLoading(true);
const shareUrl = getShareUrl(bookmark.metadata?.share?.id);
const shareUrl = getShareUrl(id || bookmark.metadata?.share?.id);
if (shareUrl) {
await navigator.clipboard.writeText(shareUrl);
toast({
Expand All @@ -180,8 +179,6 @@ export default function BookmarkDetailPage({ id }: { id: string }) {
description: "Failed to copy share link",
variant: "destructive",
});
} finally {
setIsLoading(false);
}
};

Expand Down Expand Up @@ -240,9 +237,7 @@ export default function BookmarkDetailPage({ id }: { id: string }) {
onUnshare={handleUnshare}
isLoading={isLoading}
shareStatus={shareStatus}
copyLink={
bookmark.metadata?.share?.id ? handleCopyLink : undefined
}
copyLink={handleCopyLink}
shareExpireTime={shareExpireTime}
onUpdateExpiration={handleUpdateExpiration}
/>
Expand Down

0 comments on commit 5be0669

Please sign in to comment.