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
648ff13c
Commit
648ff13c
authored
Jul 29, 2020
by
Kyle Keating
Committed by
Kyle Keating
Jul 30, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improve typecheck (search-input)
parent
0f6dd9b3
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
18 additions
and
17 deletions
+18
-17
search-input.js
src/sidebar/components/search-input.js
+18
-16
tsconfig.json
src/tsconfig.json
+0
-1
No files found.
src/sidebar/components/search-input.js
View file @
648ff13c
...
@@ -8,18 +8,30 @@ import useStore from '../store/use-store';
...
@@ -8,18 +8,30 @@ import useStore from '../store/use-store';
import
Button
from
'./button'
;
import
Button
from
'./button'
;
import
Spinner
from
'./spinner'
;
import
Spinner
from
'./spinner'
;
/**
* @typedef SearchInputProps
* @prop {boolean} [alwaysExpanded] -
* If true, the input field is always shown. If false, the input field is only shown
* if the query is non-empty.
* @prop {string} [query] - The currently active filter query.
* @prop {(value: string) => any} [onSearch] -
* Callback to invoke when the current filter query changes.
*/
/**
/**
* An input field in the top bar for entering a query that filters annotations
* An input field in the top bar for entering a query that filters annotations
* (in the sidebar) or searches annotations (in the stream/single annotation
* (in the sidebar) or searches annotations (in the stream/single annotation
* view).
* view).
*
*
* This component also renders a loading spinner to indicate when the client
* This component also renders a
e
loading spinner to indicate when the client
* is fetching for data from the API or in a "loading" state for any other
* is fetching for data from the API or in a "loading" state for any other
* reason.
* reason.
*
* @param {SearchInputProps} props
*/
*/
export
default
function
SearchInput
({
alwaysExpanded
,
query
,
onSearch
})
{
export
default
function
SearchInput
({
alwaysExpanded
,
query
,
onSearch
})
{
const
isLoading
=
useStore
(
store
=>
store
.
isLoading
());
const
isLoading
=
useStore
(
store
=>
store
.
isLoading
());
const
input
=
useRef
();
const
input
=
useRef
(
/** @type {HTMLInputElement|null} */
(
null
)
);
// The active filter query from the previous render.
// The active filter query from the previous render.
const
[
prevQuery
,
setPrevQuery
]
=
useState
(
query
);
const
[
prevQuery
,
setPrevQuery
]
=
useState
(
query
);
...
@@ -62,7 +74,9 @@ export default function SearchInput({ alwaysExpanded, query, onSearch }) {
...
@@ -62,7 +74,9 @@ export default function SearchInput({ alwaysExpanded, query, onSearch }) {
disabled
=
{
isLoading
}
disabled
=
{
isLoading
}
ref
=
{
input
}
ref
=
{
input
}
value
=
{
pendingQuery
}
value
=
{
pendingQuery
}
onInput
=
{
e
=>
setPendingQuery
(
e
.
target
.
value
)}
onInput
=
{
e
=>
setPendingQuery
(
/** @type {HTMLInputElement} */
(
e
.
target
).
value
)
}
/
>
/
>
{
!
isLoading
&&
(
{
!
isLoading
&&
(
<
Button
<
Button
...
@@ -72,25 +86,13 @@ export default function SearchInput({ alwaysExpanded, query, onSearch }) {
...
@@ -72,25 +86,13 @@ export default function SearchInput({ alwaysExpanded, query, onSearch }) {
title
=
"Search annotations"
title
=
"Search annotations"
/>
/>
)}
)}
{
isLoading
&&
<
Spinner
className
=
"top-bar__btn"
title
=
"Loading…"
/>
}
{
isLoading
&&
<
Spinner
/>
}
<
/form
>
<
/form
>
);
);
}
}
SearchInput
.
propTypes
=
{
SearchInput
.
propTypes
=
{
/**
* If true, the input field is always shown. If false, the input field is
* only shown if the query is non-empty.
*/
alwaysExpanded
:
propTypes
.
bool
,
alwaysExpanded
:
propTypes
.
bool
,
/**
* The currently active filter query.
*/
query
:
propTypes
.
string
,
query
:
propTypes
.
string
,
/**
* Callback to invoke when the current filter query changes.
*/
onSearch
:
propTypes
.
func
,
onSearch
:
propTypes
.
func
,
};
};
src/tsconfig.json
View file @
648ff13c
...
@@ -50,7 +50,6 @@
...
@@ -50,7 +50,6 @@
"sidebar/components/login-prompt-panel.js"
,
"sidebar/components/login-prompt-panel.js"
,
"sidebar/components/moderation-banner.js"
,
"sidebar/components/moderation-banner.js"
,
"sidebar/components/new-note-btn.js"
,
"sidebar/components/new-note-btn.js"
,
"sidebar/components/search-input.js"
,
"sidebar/components/search-status-bar.js"
,
"sidebar/components/search-status-bar.js"
,
"sidebar/components/selection-tabs.js"
,
"sidebar/components/selection-tabs.js"
,
"sidebar/components/share-annotations-panel.js"
,
"sidebar/components/share-annotations-panel.js"
,
...
...
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