Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
coopwire-hypothesis
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
孙灵跃 Leon Sun
coopwire-hypothesis
Commits
6c26193d
Commit
6c26193d
authored
Apr 15, 2024
by
Alejandro Celaya
Committed by
Alejandro Celaya
Apr 16, 2024
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Scroll to most recent highlighted annotation
parent
7308187e
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
29 additions
and
24 deletions
+29
-24
ThreadList.tsx
src/sidebar/components/ThreadList.tsx
+26
-21
ThreadList-test.js
src/sidebar/components/test/ThreadList-test.js
+3
-3
No files found.
src/sidebar/components/ThreadList.tsx
View file @
6c26193d
...
...
@@ -150,19 +150,6 @@ export default function ThreadList({ threads }: ThreadListProps) {
[
topLevelThreads
,
threadHeights
,
scrollPosition
,
scrollContainerHeight
],
);
const
store
=
useSidebarStore
();
// Get the `$tag` of the most recently created unsaved annotation.
const
newAnnotationTag
=
(()
=>
{
// If multiple unsaved annotations exist, assume that the last one in the
// list is the most recently created one.
const
newAnnotations
=
store
.
unsavedAnnotations
();
if
(
!
newAnnotations
.
length
)
{
return
null
;
}
return
newAnnotations
[
newAnnotations
.
length
-
1
].
$tag
;
})();
// Compute the heading to display above each thread. Headings are only shown
// in some document types (eg. VitalSource books).
//
...
...
@@ -197,6 +184,21 @@ export default function ThreadList({ threads }: ThreadListProps) {
return
headings
;
},
[
threads
]);
const
store
=
useSidebarStore
();
const
editing
=
store
.
countDrafts
()
>
0
;
const
highlightedAnnotations
=
store
.
highlightedAnnotations
();
// Get the `$tag` of the most recently created unsaved annotation.
const
newAnnotationTag
=
(()
=>
{
// If multiple unsaved annotations exist, assume that the last one in the
// list is the most recently created one.
const
newAnnotations
=
store
.
unsavedAnnotations
();
if
(
!
newAnnotations
.
length
)
{
return
null
;
}
return
newAnnotations
[
newAnnotations
.
length
-
1
].
$tag
;
})();
// Scroll to newly created annotations and replies.
//
// nb. If there are multiple unsaved annotations and the newest one is saved
...
...
@@ -209,17 +211,20 @@ export default function ThreadList({ threads }: ThreadListProps) {
}
},
[
store
,
newAnnotationTag
]);
const
editing
=
store
.
countDrafts
()
>
0
;
const
highlightedAnnotations
=
store
.
highlightedAnnotations
();
const
mostRecentlyHighlightedAnnotationId
=
useMemo
(
// If multiple highlighted annotations exist, assume that the last one in
// the list is the most recent.
()
=>
highlightedAnnotations
[
highlightedAnnotations
.
length
-
1
],
[
highlightedAnnotations
],
);
// Scroll to the
first highlighted annotation, unless creating/editing another
// annotation
// Scroll to the
most recently highlighted annotation, unless creating/editing
// an
other an
notation
useEffect
(()
=>
{
const
[
firstHighlightedAnnotation
]
=
highlightedAnnotations
;
if
(
!
editing
&&
firstHighlightedAnnotation
)
{
setScrollToId
(
firstHighlightedAnnotation
);
if
(
!
editing
&&
mostRecentlyHighlightedAnnotationId
)
{
setScrollToId
(
mostRecentlyHighlightedAnnotationId
);
}
},
[
editing
,
highlightedAnnotations
]);
},
[
editing
,
mostRecentlyHighlightedAnnotationId
]);
// Effect to scroll a particular thread into view. This is mainly used to
// scroll a newly created annotation into view.
...
...
src/sidebar/components/test/ThreadList-test.js
View file @
6c26193d
...
...
@@ -197,9 +197,9 @@ describe('ThreadList', () => {
fakeStore
.
highlightedAnnotations
.
returns
([
't2'
,
't3'
]);
createComponent
();
// The
first thread in a collection of threads at default height (200)
//
should be at 2
00px.
assert
.
calledWith
(
fakeScrollTop
,
2
00
);
// The
last highlighted annotation is the third in the collection of
//
threads. At default height (200) should be at 4
00px.
assert
.
calledWith
(
fakeScrollTop
,
4
00
);
});
});
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment