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
44667168
Commit
44667168
authored
Apr 15, 2024
by
Alejandro Celaya
Committed by
Alejandro Celaya
Apr 15, 2024
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Scroll to first highlighted annotation when loaded
parent
05aab054
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
34 additions
and
2 deletions
+34
-2
ThreadList.tsx
src/sidebar/components/ThreadList.tsx
+12
-0
ThreadList-test.js
src/sidebar/components/test/ThreadList-test.js
+22
-2
No files found.
src/sidebar/components/ThreadList.tsx
View file @
44667168
...
...
@@ -209,6 +209,18 @@ export default function ThreadList({ threads }: ThreadListProps) {
}
},
[
store
,
newAnnotationTag
]);
const
editing
=
store
.
countDrafts
()
>
0
;
const
highlightedAnnotations
=
store
.
highlightedAnnotations
();
// Scroll to the first highlighted annotation, unless creating/editing another
// annotation
useEffect
(()
=>
{
const
[
firstHighlightedAnnotation
]
=
highlightedAnnotations
;
if
(
!
editing
&&
firstHighlightedAnnotation
)
{
setScrollToId
(
firstHighlightedAnnotation
);
}
},
[
editing
,
highlightedAnnotations
]);
// Effect to scroll a particular thread into view. This is mainly used to
// scroll a newly created annotation into view.
useEffect
(()
=>
{
...
...
src/sidebar/components/test/ThreadList-test.js
View file @
44667168
...
...
@@ -4,6 +4,7 @@ import {
}
from
'@hypothesis/frontend-testing'
;
import
{
mount
}
from
'enzyme'
;
import
{
act
}
from
'preact/test-utils'
;
import
sinon
from
'sinon'
;
import
ThreadList
from
'../ThreadList'
;
import
{
$imports
}
from
'../ThreadList'
;
...
...
@@ -54,6 +55,8 @@ describe('ThreadList', () => {
fakeStore
=
{
setForcedVisible
:
sinon
.
stub
(),
unsavedAnnotations
:
sinon
.
stub
().
returns
([]),
countDrafts
:
sinon
.
stub
().
returns
(
0
),
highlightedAnnotations
:
sinon
.
stub
().
returns
([]),
};
fakeTopThread
=
{
...
...
@@ -177,10 +180,27 @@ describe('ThreadList', () => {
addNewAnnotation
(
wrapper
,
fakeTopThread
.
children
[
3
].
annotation
);
// The third thread in a collection of threads at default height (200)
// should be at 600px. This setting of `scrollTop` is the only
externally-
// observable thing that happens here...
// should be at 600px. This setting of `scrollTop` is the only
//
externally-
observable thing that happens here...
assert
.
calledWith
(
fakeScrollTop
,
600
);
});
it
(
'should do nothing for highlighted annotations while creating/editing'
,
()
=>
{
fakeStore
.
highlightedAnnotations
.
returns
([
't2'
,
't3'
]);
fakeStore
.
countDrafts
.
returns
(
10
);
createComponent
();
assert
.
notCalled
(
fakeScrollTop
);
});
it
(
'should set the scroll container `scrollTop` to first highlighted annotation'
,
()
=>
{
fakeStore
.
highlightedAnnotations
.
returns
([
't2'
,
't3'
]);
createComponent
();
// The first thread in a collection of threads at default height (200)
// should be at 200px.
assert
.
calledWith
(
fakeScrollTop
,
200
);
});
});
/**
...
...
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