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
082de109
Commit
082de109
authored
Mar 13, 2023
by
Alejandro Celaya
Committed by
Alejandro Celaya
Mar 15, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Migrate thread to TypeScript
parent
835f9bef
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
9 additions
and
20 deletions
+9
-20
thread.ts
src/sidebar/helpers/thread.ts
+9
-20
No files found.
src/sidebar/helpers/thread.
j
s
→
src/sidebar/helpers/thread.
t
s
View file @
082de109
import
type
{
Annotation
}
from
'../../types/api'
;
import
{
notNull
}
from
'../util/typing'
;
import
{
notNull
}
from
'../util/typing'
;
import
type
{
Thread
}
from
'./build-thread'
;
/** @typedef {import('../../types/api').Annotation} Annotation */
/** @typedef {import('./build-thread').Thread} Thread */
/**
/**
* Count the number of annotations/replies in the `thread` whose `visible`
* Count the number of annotations/replies in the `thread` whose `visible`
* property matches `visibility`.
* property matches `visibility`.
*
*
* @param {Thread} thread
* @param visibility — `true`: count visible annotations
* @param {boolean} visibility — `true`: count visible annotations
* `false`: count hidden annotations
* `false`: count hidden annotations
* @return {number}
*/
*/
function
countByVisibility
(
thread
,
visibility
)
{
function
countByVisibility
(
thread
:
Thread
,
visibility
:
boolean
):
number
{
const
matchesVisibility
=
thread
.
visible
===
visibility
;
const
matchesVisibility
=
thread
.
visible
===
visibility
;
return
thread
.
children
.
reduce
(
return
thread
.
children
.
reduce
(
(
count
,
reply
)
=>
count
+
countByVisibility
(
reply
,
visibility
),
(
count
,
reply
)
=>
count
+
countByVisibility
(
reply
,
visibility
),
...
@@ -22,19 +19,15 @@ function countByVisibility(thread, visibility) {
...
@@ -22,19 +19,15 @@ function countByVisibility(thread, visibility) {
/**
/**
* Count the hidden annotations/replies in the `thread`
* Count the hidden annotations/replies in the `thread`
*
* @param {Thread} thread
*/
*/
export
function
countHidden
(
thread
)
{
export
function
countHidden
(
thread
:
Thread
):
number
{
return
countByVisibility
(
thread
,
false
);
return
countByVisibility
(
thread
,
false
);
}
}
/**
/**
* Count the visible annotations/replies in the `thread`
* Count the visible annotations/replies in the `thread`
*
* @param {Thread} thread
*/
*/
export
function
countVisible
(
thread
)
{
export
function
countVisible
(
thread
:
Thread
):
number
{
return
countByVisibility
(
thread
,
true
);
return
countByVisibility
(
thread
,
true
);
}
}
...
@@ -64,11 +57,8 @@ export function countVisible(thread) {
...
@@ -64,11 +57,8 @@ export function countVisible(thread) {
* - reply 6
* - reply 6
*
*
* Return [reply 1, reply 4, reply 5]
* Return [reply 1, reply 4, reply 5]
*
* @param {Thread[]} threads
* @return {Annotation[]}
*/
*/
export
function
rootAnnotations
(
threads
)
{
export
function
rootAnnotations
(
threads
:
Thread
[]):
Annotation
[]
{
// If there are any threads at this level with extant annotations, return
// If there are any threads at this level with extant annotations, return
// those annotations
// those annotations
const
threadAnnotations
=
threads
const
threadAnnotations
=
threads
...
@@ -80,8 +70,7 @@ export function rootAnnotations(threads) {
...
@@ -80,8 +70,7 @@ export function rootAnnotations(threads) {
}
}
// Else, search across all children at once (an entire hierarchical level)
// Else, search across all children at once (an entire hierarchical level)
/** @type {Thread[]} */
const
allChildren
:
Thread
[]
=
[];
const
allChildren
=
[];
threads
.
forEach
(
thread
=>
{
threads
.
forEach
(
thread
=>
{
if
(
thread
.
children
)
{
if
(
thread
.
children
)
{
allChildren
.
push
(...
thread
.
children
);
allChildren
.
push
(...
thread
.
children
);
...
...
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