Skip to content

Commit

Permalink
🐛 fix: Conditionally render shared link and refactor share link creat…
Browse files Browse the repository at this point in the history
…ion logic
  • Loading branch information
berry-13 committed Jan 5, 2025
1 parent 059bcdd commit 6e07382
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,11 @@ export default function ShareButton({
</div>
)}

<div className="cursor-text break-all text-center text-sm text-text-secondary">
{sharedLink}
</div>
{share?.shareId !=== undefined && (
<div className="cursor-text break-all text-center text-sm text-text-secondary">
{sharedLink}
</div>
)}
</div>
</div>
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export default function SharedLinkButton({
const copyTimeoutRef = useRef<number | null>(null);
const shareId = share?.shareId || undefined;

const { mutate, isLoading: isCreateLoading } = useCreateSharedLinkMutation({
const { mutateAsync: mutate, isLoading: isCreateLoading } = useCreateSharedLinkMutation({
onError: () => {
showToast({
message: localize('com_ui_share_error'),
Expand Down Expand Up @@ -96,13 +96,27 @@ export default function SharedLinkButton({
}, 1500);
};

const createShareLink = async () => {
const share = await mutate({ conversationId });
const newLink = generateShareLink(share.shareId);
setSharedLink(newLink);

if (typeof copyTimeoutRef.current === 'number') {
clearTimeout(copyTimeoutRef.current);
}

setIsCopying(true);
copy(newLink);
copyTimeoutRef.current = window.setTimeout(() => {
setIsCopying(false);
}, 1500);
};

const getHandler = (shareId?: string) => {
if (shareId === undefined) {
return {
handler: async () => {
mutate({ conversationId });

setSharedLink(generateShareLink(shareId));
createShareLink();
},
label: (
<>
Expand Down

0 comments on commit 6e07382

Please sign in to comment.