From 07e606a00c46bc01eee7a549f4c10d745fe207f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Chalifour?= Date: Fri, 24 Apr 2020 15:55:17 +0200 Subject: [PATCH] chore: format code --- babel.config.js | 2 +- src/DocSearchModal.tsx | 31 +++++++++--------- src/ErrorScreen.tsx | 4 +-- src/NoResultsScreen.tsx | 32 ++++++++++--------- src/ScreenState.tsx | 2 +- src/StartScreen.tsx | 6 ++-- src/icons/ErrorIcon.tsx | 3 +- src/icons/NoResultsIcon.tsx | 3 +- src/icons/SelectIcon.tsx | 7 ++++- src/stored-searches.ts | 4 +-- src/style.css | 63 +++++++++++++++++++++---------------- 11 files changed, 85 insertions(+), 72 deletions(-) diff --git a/babel.config.js b/babel.config.js index 7d68e20c..602182e1 100644 --- a/babel.config.js +++ b/babel.config.js @@ -1,6 +1,6 @@ /* eslint-disable import/no-commonjs */ -module.exports = api => { +module.exports = (api) => { const isTest = api.env('test'); const modules = isTest ? 'commonjs' : false; const targets = {}; diff --git a/src/DocSearchModal.tsx b/src/DocSearchModal.tsx index a23c154e..668a76a4 100644 --- a/src/DocSearchModal.tsx +++ b/src/DocSearchModal.tsx @@ -44,7 +44,7 @@ export function DocSearchModal({ placeholder = 'Search docs', searchParameters, onClose = noop, - transformItems = x => x, + transformItems = (x) => x, hitComponent = Hit, navigator, }: DocSearchProps) { @@ -62,10 +62,7 @@ export function DocSearchModal({ const snipetLength = React.useRef(10); const initialQuery = React.useRef( typeof window !== 'undefined' - ? window - .getSelection()! - .toString() - .slice(0, MAX_QUERY_SIZE) + ? window.getSelection()!.toString().slice(0, MAX_QUERY_SIZE) : '' ).current; @@ -95,7 +92,7 @@ export function DocSearchModal({ search && favoriteSearches .getAll() - .findIndex(x => x.objectID === search.objectID) === -1 + .findIndex((x) => x.objectID === search.objectID) === -1 ) { recentSearches.add(search); } @@ -195,7 +192,7 @@ export function DocSearchModal({ }, ], }) - .catch(error => { + .catch((error) => { // The Algolia `RetryError` happens when all the servers have // failed, meaning that there's no chance the response comes // back. This is the right time to display an error. @@ -207,7 +204,7 @@ export function DocSearchModal({ throw error; }) .then((hits: DocSearchHit[]) => { - const sources = groupBy(hits, hit => hit.hierarchy.lvl0); + const sources = groupBy(hits, (hit) => hit.hierarchy.lvl0); // We store the `lvl0`s to display them as search suggestions // in the “no results“ screen. @@ -220,7 +217,7 @@ export function DocSearchModal({ }); } - return Object.values(sources).map(items => { + return Object.values(sources).map((items) => { return { onSelect({ suggestion }) { saveRecentSearch(suggestion); @@ -231,10 +228,10 @@ export function DocSearchModal({ }, getSuggestions() { return Object.values( - groupBy(items, item => item.hierarchy.lvl1) + groupBy(items, (item) => item.hierarchy.lvl1) ) - .map(items => { - return items.map(item => { + .map((items) => { + return items.map((item) => { const url = new URL(item.url); return { @@ -244,15 +241,15 @@ export function DocSearchModal({ }); }) .map(transformItems) - .map(hits => - hits.map(item => { + .map((hits) => + hits.map((item) => { return { ...item, // eslint-disable-next-line @typescript-eslint/camelcase __docsearch_parent: item.type !== 'lvl1' && hits.find( - siblingItem => + (siblingItem) => siblingItem.type === 'lvl1' && siblingItem.hierarchy.lvl1 === item.hierarchy.lvl1 @@ -328,7 +325,7 @@ export function DocSearchModal({ ] .filter(Boolean) .join(' ')} - onClick={event => { + onClick={(event) => { if (event.target === event.currentTarget) { onClose(); } @@ -352,7 +349,7 @@ export function DocSearchModal({ hitComponent={hitComponent} recentSearches={recentSearches} favoriteSearches={favoriteSearches} - onItemClick={item => { + onItemClick={(item) => { saveRecentSearch(item); onClose(); }} diff --git a/src/ErrorScreen.tsx b/src/ErrorScreen.tsx index 7ef7a943..632382a3 100644 --- a/src/ErrorScreen.tsx +++ b/src/ErrorScreen.tsx @@ -7,9 +7,7 @@ export function ErrorScreen() {
-

- Unable to fetch results -

+

Unable to fetch results

You might want to check your network connection.

diff --git a/src/NoResultsScreen.tsx b/src/NoResultsScreen.tsx index 3158a844..165e7e53 100644 --- a/src/NoResultsScreen.tsx +++ b/src/NoResultsScreen.tsx @@ -10,10 +10,10 @@ import { NoResultsIcon } from './icons'; interface NoResultsScreenProps extends AutocompleteApi< - InternalDocSearchHit, - React.FormEvent, - React.MouseEvent, - React.KeyboardEvent + InternalDocSearchHit, + React.FormEvent, + React.MouseEvent, + React.KeyboardEvent > { state: AutocompleteState; inputRef: React.MutableRefObject; @@ -39,17 +39,19 @@ export function NoResultsScreen(props: NoResultsScreenProps) { {searchSuggestions.slice(0, 3).reduce( (acc, search) => [ ...acc, -
  • , +
  • + +
  • , ], [] )} diff --git a/src/ScreenState.tsx b/src/ScreenState.tsx index 5b5d8c89..f0b087b6 100644 --- a/src/ScreenState.tsx +++ b/src/ScreenState.tsx @@ -32,7 +32,7 @@ export const ScreenState = React.memo( } const hasSuggestions = props.state.suggestions.some( - suggestion => suggestion.items.length > 0 + (suggestion) => suggestion.items.length > 0 ); if (!props.state.query) { diff --git a/src/StartScreen.tsx b/src/StartScreen.tsx index 11f36787..fee8bac7 100644 --- a/src/StartScreen.tsx +++ b/src/StartScreen.tsx @@ -57,7 +57,7 @@ export function StartScreen(props: StartScreenProps) {