From 4fe15b89d64943013835e32f67ec1f49a326bd08 Mon Sep 17 00:00:00 2001 From: yacchin1205 <968739+yacchin1205@users.noreply.github.com> Date: Wed, 27 Dec 2023 16:53:06 +0900 Subject: [PATCH] Fix lints --- src/widgets/search-widget.tsx | 128 ++++++++++++++++++---------------- 1 file changed, 66 insertions(+), 62 deletions(-) diff --git a/src/widgets/search-widget.tsx b/src/widgets/search-widget.tsx index d5a9707..3429d49 100644 --- a/src/widgets/search-widget.tsx +++ b/src/widgets/search-widget.tsx @@ -10,8 +10,6 @@ import { ResultEntity } from '../components/result'; import { requestAPI } from '../handler'; import { SortOrder } from '../components/results'; - - type SearchResponse = { notebooks: ResultEntity[]; limit: number; @@ -19,100 +17,106 @@ type SearchResponse = { numFound: number; }; - type NotebookResponse = { filename: string; }; - async function performSearch(query: SearchQuery): Promise { const params: { - query: string, - sort?: string, - limit?: string, - start?: string, + query: string; + sort?: string; + limit?: string; + start?: string; } = { - query: query.queryString, + query: query.queryString }; const { sortQuery, pageQuery } = query; if (sortQuery) { - params.sort = `${sortQuery.column} ${sortQuery.order === SortOrder.Ascending ? 'asc' : 'desc'}` + params.sort = `${sortQuery.column} ${ + sortQuery.order === SortOrder.Ascending ? 'asc' : 'desc' + }`; } if (pageQuery) { params.limit = pageQuery.limit.toString(); params.start = pageQuery.start.toString(); } const resp = await requestAPI( - `v1/notebook/search?${new URLSearchParams(params)}`, + `v1/notebook/search?${new URLSearchParams(params)}` ); return resp; } - -async function prepareNotebook(path: string, id: string): Promise { - const resp = await requestAPI( - `v1/import${path}/${id}`, - ); +async function prepareNotebook( + path: string, + id: string +): Promise { + const resp = await requestAPI(`v1/import${path}/${id}`); return resp; } - type SearchWidgetProps = { documents: IDocumentManager; -} - +}; export function SearchWidget(props: SearchWidgetProps): JSX.Element { const { documents } = props; const [results, setResults] = useState([]); const [page, setPage] = useState<{ - start: number, - limit: number, - numFound: number + start: number; + limit: number; + numFound: number; } | null>(null); const [error, setError] = useState(undefined); - const searched = useCallback((query: SearchQuery) => { - performSearch(query) - .then((results) => { - setError(undefined); - setResults(results.notebooks); - setPage({ - start: results.start, - limit: results.limit, - numFound: results.numFound, + const searched = useCallback( + (query: SearchQuery) => { + performSearch(query) + .then(results => { + setError(undefined); + setResults(results.notebooks); + setPage({ + start: results.start, + limit: results.limit, + numFound: results.numFound + }); + }) + .catch(error => { + setError(error); + }); + }, + [results] + ); + const selected = useCallback( + (result: ResultEntity) => { + prepareNotebook('/nbsearch-tmp', result.id) + .then(result => { + documents.openOrReveal(`/nbsearch-tmp/${result.filename}`); + }) + .catch(error => { + setError(error); }); - }) - .catch((error) => { - setError(error); - }); - }, [results]); - const selected = useCallback((result: ResultEntity) => { - prepareNotebook('/nbsearch-tmp', result.id) - .then((result) => { - documents.openOrReveal(`/nbsearch-tmp/${result.filename}`); - }) - .catch((error) => { - setError(error); - }); - }, [documents]); - return - - + }, + [documents] + ); + return ( + + + + ); } - -export function buildWidget(documents: IDocumentManager, withLabel: boolean): ReactWidget { - const widget = ReactWidget.create( - - ); +export function buildWidget( + documents: IDocumentManager, + withLabel: boolean +): ReactWidget { + const widget = ReactWidget.create(); widget.id = 'nbsearch::notebooksearch'; widget.title.icon = searchIcon; widget.title.caption = 'NBSearch'; @@ -120,4 +124,4 @@ export function buildWidget(documents: IDocumentManager, withLabel: boolean): Re widget.title.label = 'NBSearch'; } return widget; -} \ No newline at end of file +}