-
Notifications
You must be signed in to change notification settings - Fork 800
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Jetpack: Fix some minor eslint lints (#39753)
Should be no functionality changes, unless some of the `react-hooks/` things were obscure bugs. * `curly` × 2: Missing `{}` around `if` bodies. * `eqeqeq` × 11: Use `===` and `!==` for comparisons. * `no-case-declarations` × 8: If a `case` has `const` or `let` inside, wrap it in a block for scoping. * `no-extra-boolean-cast` × 1: `if ( !! foo )` → `if ( foo )`. * `no-redeclare` × 2: A few useless `/* global JSON */`. * `no-undef` × 3: Remove some unused variables. * `no-unused-expressions` × 7: All ignored by updating `projects/plugins/jetpack/modules/.eslintrc.js`. * `no-useless-escape` × 4: Remove unnecessary `\`s in regexes. * `react-hooks/exhaustive-deps` × 3: Added missing deps. * One case needed a bit of refactoring. * `react-hooks/rules-of-hooks` × 5: Used `useSelect` and `useResizeObserver` unconditionally, and defined one that needed a conditional outside of `render()`. * `valid-typeof` × 2: Broken `undefined !== typeof window` check, changed to just use `window?` in later conditionals. * `@wordpress/no-global-active-element` × 2: Use `ownerDocument`.
- Loading branch information
Showing
28 changed files
with
129 additions
and
144 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
Significance: patch | ||
Type: other | ||
Comment: Fix various eslint lints. Should be no change to functionality, although it's possible some obscure React bugs got fixed. | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 25 additions & 21 deletions
46
projects/plugins/jetpack/extensions/blocks/opentable/use-restaurant-search.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,42 @@ | ||
import { useState, useEffect, useCallback } from '@wordpress/element'; | ||
import { useState, useEffect, useCallback, useMemo } from '@wordpress/element'; | ||
import { unionBy, throttle, isEmpty } from 'lodash'; | ||
|
||
export const possibleEmbed = /^\s*(http[s]?:\/\/|\<script)/; | ||
export const possibleEmbed = /^\s*(http[s]?:\/\/|<script)/; | ||
|
||
export default function useRestaurantSearch( searchTerm, maxResults ) { | ||
const [ restaurants, setRestaurants ] = useState( [] ); | ||
const [ hasRequestFailed, setHasRequestFailed ] = useState( false ); | ||
|
||
const searchRestaurants = ( input = '' ) => { | ||
setHasRequestFailed( false ); | ||
const searchRestaurants = useCallback( | ||
( input = '' ) => { | ||
setHasRequestFailed( false ); | ||
|
||
fetch( | ||
'https://www.opentable.com/widget/reservation/restaurant-search?pageSize=' + | ||
maxResults + | ||
'&query=' + | ||
encodeURIComponent( input ) | ||
) | ||
.then( result => result.json() ) | ||
.then( restaurantResponse => { | ||
setHasRequestFailed( false ); | ||
setRestaurants( unionBy( restaurants, restaurantResponse.items, 'rid' ) ); | ||
} ) | ||
.catch( () => setHasRequestFailed( true ) ); | ||
}; | ||
fetch( | ||
'https://www.opentable.com/widget/reservation/restaurant-search?pageSize=' + | ||
maxResults + | ||
'&query=' + | ||
encodeURIComponent( input ) | ||
) | ||
.then( result => result.json() ) | ||
.then( restaurantResponse => { | ||
setHasRequestFailed( false ); | ||
setRestaurants( unionBy( restaurants, restaurantResponse.items, 'rid' ) ); | ||
} ) | ||
.catch( () => setHasRequestFailed( true ) ); | ||
}, | ||
[ restaurants, maxResults ] | ||
); | ||
|
||
const throttledSearchRestaurants = useCallback( throttle( searchRestaurants, 500 ), [ | ||
restaurants, | ||
] ); | ||
const throttledSearchRestaurants = useMemo( | ||
() => throttle( searchRestaurants, 500 ), | ||
[ searchRestaurants ] | ||
); | ||
|
||
useEffect( () => { | ||
if ( ! isEmpty( searchTerm ) && ! possibleEmbed.test( searchTerm ) ) { | ||
throttledSearchRestaurants( searchTerm ); | ||
} | ||
}, [ searchTerm ] ); | ||
}, [ searchTerm, throttledSearchRestaurants ] ); | ||
|
||
return { restaurants, hasRequestFailed }; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.