Skip to content

Commit

Permalink
fix: shared link refresh on time
Browse files Browse the repository at this point in the history
  • Loading branch information
Pkcarreno committed Jun 3, 2024
1 parent 4e8cf1f commit d609569
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions src/features/editor/components/header/sharing-menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,24 @@ export const SharingMenu = () => {
}
};

useEffect(() => {
const handleTooltipTriggerClick = () => {
prepareSharedUrl();
};

const prepareSharedUrl = () => {
const url = new URL(location.href);

const searchParams = new URLSearchParams(location.hash.slice(1));
if (!isWithCode) {
searchParams.delete('code');
}
url.hash = searchParams.toString();

setSharedUrl(url.href);
};

useEffect(() => {
prepareSharedUrl();
}, [isTooltipOpen, isWithCode]);

return (
Expand All @@ -56,7 +66,11 @@ export const SharingMenu = () => {
<Tooltip open={isTooltipOpen} onOpenChange={setIsTooltipOpen}>
<TooltipTrigger asChild>
<PopoverTrigger asChild>
<Button size="icon" variant="outline">
<Button
size="icon"
variant="outline"
onClick={handleTooltipTriggerClick}
>
<Share1Icon />
<span className="sr-only">Shared current code</span>
</Button>
Expand Down

0 comments on commit d609569

Please sign in to comment.