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
c48a0a63
Commit
c48a0a63
authored
Apr 15, 2022
by
Robert Knight
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add missing types for ThreadCard, ThreadList
parent
62b149a4
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
17 additions
and
12 deletions
+17
-12
ThreadCard.js
src/sidebar/components/ThreadCard.js
+6
-2
ThreadList.js
src/sidebar/components/ThreadList.js
+8
-7
visible-threads-test.js
src/sidebar/helpers/test/visible-threads-test.js
+1
-1
visible-threads.js
src/sidebar/helpers/visible-threads.js
+2
-2
No files found.
src/sidebar/components/ThreadCard.js
View file @
c48a0a63
...
@@ -42,6 +42,7 @@ function ThreadCard({ frameSync, thread }) {
...
@@ -42,6 +42,7 @@ function ThreadCard({ frameSync, thread }) {
);
);
const
scrollToAnnotation
=
useCallback
(
const
scrollToAnnotation
=
useCallback
(
/** @param {string} tag */
tag
=>
{
tag
=>
{
frameSync
.
scrollToAnnotation
(
tag
);
frameSync
.
scrollToAnnotation
(
tag
);
},
},
...
@@ -72,11 +73,14 @@ function ThreadCard({ frameSync, thread }) {
...
@@ -72,11 +73,14 @@ function ThreadCard({ frameSync, thread }) {
onClick
=
{
e
=>
{
onClick
=
{
e
=>
{
// Prevent click events intended for another action from
// Prevent click events intended for another action from
// triggering a page scroll.
// triggering a page scroll.
if
(
!
isFromButtonOrLink
(
/** @type {Element} */
(
e
.
target
)))
{
if
(
!
isFromButtonOrLink
(
/** @type {Element} */
(
e
.
target
))
&&
threadTag
)
{
scrollToAnnotation
(
threadTag
);
scrollToAnnotation
(
threadTag
);
}
}
}}
}}
onMouseEnter
=
{()
=>
focusThreadAnnotation
(
threadTag
)}
onMouseEnter
=
{()
=>
focusThreadAnnotation
(
threadTag
??
null
)}
onMouseLeave
=
{()
=>
focusThreadAnnotation
(
null
)}
onMouseLeave
=
{()
=>
focusThreadAnnotation
(
null
)}
key
=
{
thread
.
id
}
key
=
{
thread
.
id
}
>
>
...
...
src/sidebar/components/ThreadList.js
View file @
c48a0a63
...
@@ -87,7 +87,7 @@ function ThreadList({ threads }) {
...
@@ -87,7 +87,7 @@ function ThreadList({ threads }) {
},
[]);
},
[]);
// Map of thread ID to measured height of thread.
// Map of thread ID to measured height of thread.
const
[
threadHeights
,
setThreadHeights
]
=
useState
(
{}
);
const
[
threadHeights
,
setThreadHeights
]
=
useState
(
()
=>
new
Map
()
);
// ID of thread to scroll to after the next render. If the thread is not
// ID of thread to scroll to after the next render. If the thread is not
// present, the value persists until it can be "consumed".
// present, the value persists until it can be "consumed".
...
@@ -151,8 +151,9 @@ function ThreadList({ threads }) {
...
@@ -151,8 +151,9 @@ function ThreadList({ threads }) {
// Clear `scrollToId` so we don't scroll again after the next render.
// Clear `scrollToId` so we don't scroll again after the next render.
setScrollToId
(
null
);
setScrollToId
(
null
);
/** @param {Thread} thread */
const
getThreadHeight
=
thread
=>
const
getThreadHeight
=
thread
=>
threadHeights
[
thread
.
id
]
||
THREAD_DIMENSION_DEFAULTS
.
defaultHeight
;
threadHeights
.
get
(
thread
.
id
)
||
THREAD_DIMENSION_DEFAULTS
.
defaultHeight
;
const
yOffset
=
topLevelThreads
const
yOffset
=
topLevelThreads
.
slice
(
0
,
threadIndex
)
.
slice
(
0
,
threadIndex
)
...
@@ -166,7 +167,7 @@ function ThreadList({ threads }) {
...
@@ -166,7 +167,7 @@ function ThreadList({ threads }) {
// heights of thread cards and update `threadHeights` state if there are changes.
// heights of thread cards and update `threadHeights` state if there are changes.
useEffect
(()
=>
{
useEffect
(()
=>
{
setThreadHeights
(
prevHeights
=>
{
setThreadHeights
(
prevHeights
=>
{
const
changedHeights
=
{}
;
const
changedHeights
=
new
Map
()
;
for
(
let
{
id
}
of
visibleThreads
)
{
for
(
let
{
id
}
of
visibleThreads
)
{
const
threadElement
=
/** @type {HTMLElement} */
(
const
threadElement
=
/** @type {HTMLElement} */
(
document
.
getElementById
(
id
)
document
.
getElementById
(
id
)
...
@@ -186,18 +187,18 @@ function ThreadList({ threads }) {
...
@@ -186,18 +187,18 @@ function ThreadList({ threads }) {
}
}
const
height
=
getElementHeightWithMargins
(
threadElement
);
const
height
=
getElementHeightWithMargins
(
threadElement
);
if
(
height
!==
prevHeights
[
id
]
)
{
if
(
height
!==
prevHeights
.
get
(
id
)
)
{
changedHeights
[
id
]
=
height
;
changedHeights
.
set
(
id
,
height
)
;
}
}
}
}
// Skip update if no heights changed from previous measured values
// Skip update if no heights changed from previous measured values
// (or defaults).
// (or defaults).
if
(
Object
.
keys
(
changedHeights
).
length
===
0
)
{
if
(
changedHeights
.
size
===
0
)
{
return
prevHeights
;
return
prevHeights
;
}
}
return
{
...
prevHeights
,
...
changedHeights
}
;
return
new
Map
([...
prevHeights
,
...
changedHeights
])
;
});
});
},
[
visibleThreads
]);
},
[
visibleThreads
]);
...
...
src/sidebar/helpers/test/visible-threads-test.js
View file @
c48a0a63
...
@@ -19,7 +19,7 @@ describe('sidebar/helpers/visible-threads', () => {
...
@@ -19,7 +19,7 @@ describe('sidebar/helpers/visible-threads', () => {
{
id
:
't9'
},
{
id
:
't9'
},
{
id
:
't10'
},
{
id
:
't10'
},
];
];
fakeThreadHeights
=
{}
;
fakeThreadHeights
=
new
Map
()
;
fakeWindowHeight
=
100
;
fakeWindowHeight
=
100
;
fakeDefaultDimensions
=
{
fakeDefaultDimensions
=
{
defaultHeight
:
200
,
defaultHeight
:
200
,
...
...
src/sidebar/helpers/visible-threads.js
View file @
c48a0a63
...
@@ -18,7 +18,7 @@ export const THREAD_DIMENSION_DEFAULTS = {
...
@@ -18,7 +18,7 @@ export const THREAD_DIMENSION_DEFAULTS = {
* estimating which of the threads are within or near the viewport.
* estimating which of the threads are within or near the viewport.
*
*
* @param {Thread[]} threads - List of threads in the order they appear
* @param {Thread[]} threads - List of threads in the order they appear
* @param {
Record
<string, number>} threadHeights - Map of thread ID to measured height
* @param {
Map
<string, number>} threadHeights - Map of thread ID to measured height
* @param {number} scrollPos - Vertical scroll offset of scrollable container
* @param {number} scrollPos - Vertical scroll offset of scrollable container
* @param {number} windowHeight -
* @param {number} windowHeight -
* Height of the visible area of the scrollable container.
* Height of the visible area of the scrollable container.
...
@@ -43,7 +43,7 @@ export function calculateVisibleThreads(
...
@@ -43,7 +43,7 @@ export function calculateVisibleThreads(
let
offscreenLowerHeight
=
0
;
let
offscreenLowerHeight
=
0
;
threads
.
forEach
(
thread
=>
{
threads
.
forEach
(
thread
=>
{
const
threadHeight
=
threadHeights
[
thread
.
id
]
||
defaultHeight
;
const
threadHeight
=
threadHeights
.
get
(
thread
.
id
)
||
defaultHeight
;
const
threadIsAboveViewport
=
const
threadIsAboveViewport
=
totalHeight
+
threadHeight
<
scrollPos
-
marginAbove
;
totalHeight
+
threadHeight
<
scrollPos
-
marginAbove
;
...
...
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