fix: ui fixes
This commit is contained in:
@@ -2,7 +2,6 @@
|
||||
|
||||
import { useState, useEffect, useRef, useCallback } from "react";
|
||||
import {
|
||||
AtSign,
|
||||
Bookmark as BookmarkIcon,
|
||||
Copy,
|
||||
FolderPlus,
|
||||
@@ -113,6 +112,18 @@ export function TextSelectionToolbar() {
|
||||
setShowMore(false);
|
||||
}, []);
|
||||
|
||||
// Completed-action teardown. Unlike clearSelection (which only hides the
|
||||
// toolbar UI), this also drops the selection in the document — otherwise
|
||||
// the still-highlighted text re-triggers the toolbar on the very next
|
||||
// selectionchange/touchend — and forgets the saved range so a drawer's
|
||||
// onClose can't restore it after the action already succeeded.
|
||||
const finishAction = useCallback(() => {
|
||||
savedRangeRef.current = null;
|
||||
interactingRef.current = false;
|
||||
window.getSelection()?.removeAllRanges();
|
||||
clearSelection();
|
||||
}, [clearSelection]);
|
||||
|
||||
// Listen for selection changes
|
||||
useEffect(() => {
|
||||
function handleSelectionChange() {
|
||||
@@ -349,7 +360,7 @@ export function TextSelectionToolbar() {
|
||||
});
|
||||
toast.success("Bookmark saved", { duration: 2000 });
|
||||
window.dispatchEvent(new CustomEvent("spsays:bookmarks-changed"));
|
||||
clearSelection();
|
||||
finishAction();
|
||||
} catch (err) {
|
||||
if (err instanceof SocialError && err.status === 402) {
|
||||
toast.error("Bookmark limit reached", {
|
||||
@@ -369,14 +380,14 @@ export function TextSelectionToolbar() {
|
||||
async function onCopyText() {
|
||||
await copy(formatCopyText(selectedText));
|
||||
toast.success("Copied to clipboard", { duration: 1500 });
|
||||
clearSelection();
|
||||
finishAction();
|
||||
}
|
||||
|
||||
async function onCopyLink() {
|
||||
const url = await buildShortHighlightUrl(selectedText);
|
||||
await copy(url);
|
||||
toast.success("Link copied", { duration: 1500 });
|
||||
clearSelection();
|
||||
finishAction();
|
||||
}
|
||||
|
||||
async function onSaveToCollection() {
|
||||
@@ -400,7 +411,7 @@ export function TextSelectionToolbar() {
|
||||
icon: <KautilyaIcon className="size-3.5" />,
|
||||
onClick: () => {
|
||||
// TODO: Implement Ask Kautilya
|
||||
clearSelection();
|
||||
finishAction();
|
||||
},
|
||||
className: "text-amber-400 hover:bg-amber-400/15 hover:text-amber-300",
|
||||
};
|
||||
@@ -549,6 +560,9 @@ export function TextSelectionToolbar() {
|
||||
|
||||
<ComposePost
|
||||
open={showCompose}
|
||||
// Successful post → end the flow; the onClose that follows finds
|
||||
// no saved range left to restore, so the toolbar stays gone.
|
||||
onPosted={finishAction}
|
||||
onClose={() => {
|
||||
setShowCompose(false);
|
||||
if (isMobile) restoreSelection();
|
||||
@@ -560,6 +574,12 @@ export function TextSelectionToolbar() {
|
||||
|
||||
<CollectionsDrawer
|
||||
open={showCollections}
|
||||
// Successful save → close the drawer and end the flow (cancel still
|
||||
// goes through onClose and restores the selection).
|
||||
onSaved={() => {
|
||||
setShowCollections(false);
|
||||
finishAction();
|
||||
}}
|
||||
onClose={() => {
|
||||
setShowCollections(false);
|
||||
if (isMobile) restoreSelection();
|
||||
|
||||
Reference in New Issue
Block a user