Skip to content

Commit

Permalink
fix lint warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
fabiankaegy committed Jun 10, 2024
1 parent 58fbfca commit 2ed9356
Show file tree
Hide file tree
Showing 12 changed files with 60 additions and 45 deletions.
10 changes: 5 additions & 5 deletions components/content-search/SearchItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@ interface SearchItemProps {
renderType?: (suggestion: Suggestion) => string;
}

export function defaultRenderItemType(suggestion: Suggestion): string {
// Rename 'post_tag' to 'tag'. Ideally, the API would return the localised CPT or taxonomy label.
return suggestion.type === 'post_tag' ? 'tag' : suggestion.subtype;
}

const SearchItem: React.FC<SearchItemProps> = ({
suggestion,
onClick,
Expand Down Expand Up @@ -127,9 +132,4 @@ const SearchItem: React.FC<SearchItemProps> = ({
);
};

export function defaultRenderItemType(suggestion: Suggestion): string {
// Rename 'post_tag' to 'tag'. Ideally, the API would return the localised CPT or taxonomy label.
return suggestion.type === 'post_tag' ? 'tag' : suggestion.subtype;
}

export default SearchItem;
58 changes: 38 additions & 20 deletions components/content-search/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,8 @@ const ContentSearch: React.FC<ContentSearchProps> = ({
fetchInitialResults,
}) => {
const [searchString, setSearchString] = useState('');
const [searchQueries, setSearchQueries] = useState<{[key: string]: QueryCache}>({});
const [selectedItem, setSelectedItem] = useState<number|null>(null);
const [searchQueries, setSearchQueries] = useState<{ [key: string]: QueryCache }>({});
const [selectedItem, setSelectedItem] = useState<number | null>(null);
const [currentPage, setCurrentPage] = useState(1);
const [isFocused, setIsFocused] = useState(false);

Expand Down Expand Up @@ -219,13 +219,16 @@ const ContentSearch: React.FC<ContentSearchProps> = ({
const normalizedResults = filterResults(result);

if (mode === 'user') {
return normalizedResults.map((item) => ({
id: item.id,
subtype: mode,
title: item.name || '',
type: mode,
url: item.link || '',
} as SearchResult));
return normalizedResults.map(
(item) =>
({
id: item.id,
subtype: mode,
title: item.name || '',
type: mode,
url: item.link || '',
}) as SearchResult,
);
}

return normalizedResults;
Expand Down Expand Up @@ -255,7 +258,7 @@ const ContentSearch: React.FC<ContentSearchProps> = ({
if (!searchQueries[preparedQuery] || searchQueries[preparedQuery].controller === 1) {
setSearchQueries((queries) => {
// New queries.
const newQueries: {[key: string]: QueryCache} = {};
const newQueries: { [key: string]: QueryCache } = {};

// Remove errored or cancelled queries.
Object.keys(queries).forEach((query) => {
Expand Down Expand Up @@ -314,7 +317,7 @@ const ContentSearch: React.FC<ContentSearchProps> = ({
})
.then((results: Response) => {
const totalPages = parseInt(
( results.headers && results.headers.get('X-WP-TotalPages') ) || '0',
(results.headers && results.headers.get('X-WP-TotalPages')) || '0',
10,
);

Expand Down Expand Up @@ -401,7 +404,11 @@ const ContentSearch: React.FC<ContentSearchProps> = ({
if (i === currentPage) {
isLoading = false;

if ( searchQuery.totalPages && searchQuery.currentPage && searchQuery.totalPages > searchQuery.currentPage) {
if (
searchQuery.totalPages &&
searchQuery.currentPage &&
searchQuery.totalPages > searchQuery.currentPage
) {
showLoadMore = true;
}
}
Expand All @@ -424,9 +431,7 @@ const ContentSearch: React.FC<ContentSearchProps> = ({
useEffect(() => {
document.addEventListener('mouseup', (e: MouseEvent) => {
// Bail if anywhere inside search container is clicked.
if (
searchContainer.current?.contains(e.target as Node)
) {
if (searchContainer.current?.contains(e.target as Node)) {
return;
}

Expand All @@ -436,7 +441,11 @@ const ContentSearch: React.FC<ContentSearchProps> = ({

return (
<StyledComponentContext cacheKey="tenup-component-content-search">
<StyledNavigableMenu ref={searchContainer} onNavigate={handleOnNavigate} orientation="vertical">
<StyledNavigableMenu
ref={searchContainer}
onNavigate={handleOnNavigate}
orientation="vertical"
>
<StyledSearchControl
value={searchString}
onChange={(newSearchString) => {
Expand All @@ -454,7 +463,12 @@ const ContentSearch: React.FC<ContentSearchProps> = ({
{hasSearchString || hasInitialResults ? (
<>
<List className={`${NAMESPACE}-list`}>
{isLoading && currentPage === 1 && <StyledSpinner onPointerEnterCapture={null} onPointerLeaveCapture={null} />}
{isLoading && currentPage === 1 && (
<StyledSpinner
onPointerEnterCapture={null}
onPointerLeaveCapture={null}
/>
)}

{!isLoading && !hasSearchResults && (
<li
Expand All @@ -468,8 +482,7 @@ const ContentSearch: React.FC<ContentSearchProps> = ({
{__('Nothing found.', '10up-block-components')}
</li>
)}
{
(!isLoading || currentPage > 1) &&
{(!isLoading || currentPage > 1) &&
searchResults &&
searchResults.map((item, index) => {
if (!item.title.length) {
Expand Down Expand Up @@ -522,7 +535,12 @@ const ContentSearch: React.FC<ContentSearchProps> = ({
</LoadingContainer>
)}

{isLoading && currentPage > 1 && <StyledSpinner onPointerEnterCapture={null} onPointerLeaveCapture={null} />}
{isLoading && currentPage > 1 && (
<StyledSpinner
onPointerEnterCapture={null}
onPointerLeaveCapture={null}
/>
)}
</>
) : null}
</StyledNavigableMenu>
Expand Down
2 changes: 2 additions & 0 deletions components/inner-block-slider/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/* eslint-disable */
// @ts-nocheck
// eslint-disable-file
import { useSelect, useDispatch } from '@wordpress/data';
import { useEffect, useState, useRef } from '@wordpress/element';
Expand Down
2 changes: 1 addition & 1 deletion components/is-admin/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ interface IsAdminProps {
children: React.ReactNode;
}

/**
/*
* IsAdmin
*
* A wrapper component that checks wether the current user has admin capabilities
Expand Down
2 changes: 1 addition & 1 deletion components/media-toolbar/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ interface MediaToolbarProps {
id: number;
}

/**
/*
* MediaToolbar
*
* This is a helper component that adds the Media Replace Flow
Expand Down
2 changes: 1 addition & 1 deletion components/post-term-list/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import {
PostTaxonomiesHierarchicalTermSelector,
PostTaxonomiesFlatTermSelector,
} from '@wordpress/editor';
import { Optional } from '@10up/block-components';

import { usePopover, usePost, useSelectedTerms, useTaxonomy } from '../../hooks';
import { Optional } from '..';
import { PostTermContext } from './context';
import { ListItem, TermLink } from './item';

Expand Down
4 changes: 2 additions & 2 deletions components/post-title/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { useSelect } from '@wordpress/data';
import { usePost } from '../../hooks';

interface PostTitleProps<TElementType extends React.ElementType> {
tagName?: TElementType | keyof JSX.IntrinsicElements;
tagName: TElementType | keyof JSX.IntrinsicElements;
}

type PostTitlePropsWithOmit<TElementType extends React.ElementType> = PostTitleProps<TElementType> &
Expand All @@ -20,7 +20,7 @@ export const PostTitle = <TElementType extends React.ElementType = 'h1'>({
'postType',
postType,
'title',
postId,
postId as undefined | string,
);

const titlePlaceholder = useSelect(
Expand Down
2 changes: 1 addition & 1 deletion hooks/use-block-parent-attributes/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useSelect, useDispatch } from '@wordpress/data';
import { store as blockEditorStore, useBlockEditContext } from '@wordpress/block-editor';

/**
/*
* useBlockParentAttributes
*
* allows you to easily interface with the attributes of the direct
Expand Down
2 changes: 1 addition & 1 deletion hooks/use-has-selected-inner-block/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useSelect } from '@wordpress/data';
import { useBlockEditContext, store as blockEditorStore } from '@wordpress/block-editor';

/**
/*
* useHasSelectedInnerBlock
* Determine whether one of the inner blocks currently is selected
*/
Expand Down
5 changes: 2 additions & 3 deletions hooks/use-is-plugin-active/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@ const ACTIVE_STATUSES = ['active', 'network-active'] as const;
/**
* Custom hook to check if a plugin is active and whether its resolution has finished.
*
* @param pluginName The name of the plugin to check.
* @returns A tuple containing two boolean values: the first indicating whether the plugin is active,
* and the second indicating whether the resolution for the plugin has finished.
* @param {string} pluginName The name of the plugin to check.
* @returns {[boolean, boolean]} A tuple with the first value being whether the plugin is active and the second value being whether the resolution has finished.
*/
export const useIsPluginActive = (pluginName: string) => {
return useSelect(
Expand Down
9 changes: 5 additions & 4 deletions hooks/use-on-click-outside.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export function useOnClickOutside(onClickOutside: (event: MouseEvent | TouchEven
const ref = useRefEffect(
(element) => {
if (!element) {
return;
return () => {};
}
const listener = (event: MouseEvent | TouchEvent) => {
// Do nothing if clicking ref's element or descendent elements
Expand All @@ -25,7 +25,8 @@ export function useOnClickOutside(onClickOutside: (event: MouseEvent | TouchEven
const ownerDocument = element.ownerDocument || document;
const isRenderedInsideIframe = ownerDocument !== document;

const editorCanvasIframe = document.querySelector<HTMLIFrameElement>('[name="editor-canvas"]');
const editorCanvasIframe =
document.querySelector<HTMLIFrameElement>('[name="editor-canvas"]');
const editorCanvasDocument = editorCanvasIframe?.contentDocument;

ownerDocument.addEventListener('mousedown', listener);
Expand All @@ -37,8 +38,8 @@ export function useOnClickOutside(onClickOutside: (event: MouseEvent | TouchEven
document.addEventListener('mousedown', listener);
document.addEventListener('touchstart', listener);

// If the element is rendered outside the editor canvas iframe, we need to listen to events on the editor canvas
// document as well to detect clicks inside the editor canvas.
// If the element is rendered outside the editor canvas iframe, we need to listen to events on the editor canvas
// document as well to detect clicks inside the editor canvas.
} else if (editorCanvasDocument) {
editorCanvasDocument.addEventListener('mousedown', listener);
editorCanvasDocument.addEventListener('touchstart', listener);
Expand Down
7 changes: 1 addition & 6 deletions stores/icons/reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,8 @@
import { IconSetAction } from './actions';
import { IconSet } from './types';

/**
/*
* Reducer managing the block style variations.
*
* @param {object} state Current state.
* @param {object} action Dispatched action.
*
* @returns {object} Updated state.
*/
export default function reducer(
state: { iconSets: { [key: string]: IconSet } } = { iconSets: {} },
Expand Down

0 comments on commit 2ed9356

Please sign in to comment.