Skip to content

Commit 44e5d32

Browse files
committed
feat: add #comment hash
1 parent c7c1694 commit 44e5d32

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

src/components/viewer/OperationViewer.tsx

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,19 @@ export const OperationViewer: ComponentType<{
119119
})
120120
const operation = data?.data
121121

122+
useEffect(() => {
123+
// on finished loading, scroll to #fragment if any
124+
if (operation) {
125+
const fragment = window.location.hash
126+
if (fragment) {
127+
const el = document.querySelector(fragment)
128+
if (el) {
129+
el.scrollIntoView({ behavior: 'smooth' })
130+
}
131+
}
132+
}
133+
}, [operation])
134+
122135
const levels = useLevels()?.data?.data || []
123136

124137
const [auth] = useAtom(authAtom)
@@ -354,7 +367,9 @@ function OperationViewerInner({
354367

355368
<div className="mb-6">
356369
<div>
357-
<H4 className="mb-4">评论 ({operation.commentsCount})</H4>
370+
<H4 className="mb-4" id="comment">
371+
评论 ({operation.commentsCount})
372+
</H4>
358373
<CommentArea operationId={operation.id} />
359374
</div>
360375
</div>

0 commit comments

Comments
 (0)