Commit 648ff13c authored by Kyle Keating's avatar Kyle Keating Committed by Kyle Keating

Improve typecheck (search-input)

parent 0f6dd9b3
...@@ -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 eloading 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,
}; };
...@@ -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",
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment