tangled
alpha
login
or
join now
leaflet.pub
/
leaflet
289
fork
atom
a tool for shared writing and social publishing
289
fork
atom
overview
issues
28
pulls
pipelines
scroll into view comments panel
awarm.space
5 months ago
2228a52b
1bf9ee10
+18
-10
1 changed file
expand all
collapse all
unified
split
app
lish
[did]
[publication]
[rkey]
QuoteHandler.tsx
+18
-10
app/lish/[did]/[publication]/[rkey]/QuoteHandler.tsx
···
14
14
import { setInteractionState } from "./Interactions/Interactions";
15
15
import { PostPageContext } from "./PostPageContext";
16
16
import { PubLeafletPublication } from "lexicons/api";
17
17
+
import { flushSync } from "react-dom";
18
18
+
import { scrollIntoView } from "src/utils/scrollIntoView";
17
19
18
20
export function QuoteHandler() {
19
21
let [position, setPosition] = useState<{
···
31
33
? (() => {
32
34
const range = selection.getRangeAt(0);
33
35
const ancestor = range.commonAncestorContainer;
34
34
-
const element = ancestor.nodeType === Node.ELEMENT_NODE
35
35
-
? ancestor as Element
36
36
-
: ancestor.parentElement;
37
37
-
return element?.closest('.postContent') !== null;
36
36
+
const element =
37
37
+
ancestor.nodeType === Node.ELEMENT_NODE
38
38
+
? (ancestor as Element)
39
39
+
: ancestor.parentElement;
40
40
+
return element?.closest(".postContent") !== null;
38
41
})()
39
42
: false;
40
43
···
205
208
className="flex gap-1 items-center hover:font-bold px-1"
206
209
onClick={() => {
207
210
if (!position) return;
208
208
-
setInteractionState(document_uri, {
209
209
-
drawer: "comments",
210
210
-
drawerOpen: true,
211
211
-
commentBox: { quote: position },
212
212
-
});
211
211
+
flushSync(() =>
212
212
+
setInteractionState(document_uri, {
213
213
+
drawer: "comments",
214
214
+
drawerOpen: true,
215
215
+
commentBox: { quote: position },
216
216
+
}),
217
217
+
);
218
218
+
scrollIntoView("interaction-drawer");
213
219
}}
214
220
>
215
221
<CommentTiny /> Comment
···
220
226
);
221
227
};
222
228
223
223
-
function findDataIndex(node: Node): { index: string; element: Element; pageId?: string } | null {
229
229
+
function findDataIndex(
230
230
+
node: Node,
231
231
+
): { index: string; element: Element; pageId?: string } | null {
224
232
if (node.nodeType === Node.ELEMENT_NODE) {
225
233
const element = node as Element;
226
234
if (element.hasAttribute("data-index")) {