Skip to content

Commit

Permalink
Merge pull request #60 from ScoopInstaller/code-lint
Browse files Browse the repository at this point in the history
Run linter during GitHub workflow execution + code formatting fixes
  • Loading branch information
gpailler committed May 17, 2023
2 parents 34c84fa + d601fd1 commit ba3ba79
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 32 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/build-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ jobs:
- name: Install dependencies
run: npm ci

- name: Code linter
run: npm run lint

- name: Build Staging Website
run: npm run build
env:
Expand Down
43 changes: 22 additions & 21 deletions src/components/Search.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ import { Container, Row, Col, Modal } from 'react-bootstrap';
import { Helmet } from 'react-helmet';
import { useSearchParams } from 'react-router-dom';

import { requestIdleCallback } from '../request-idle-callback';
import ManifestJson from '../serialization/ManifestJson';
import SearchResultsJson from '../serialization/SearchResultsJson';
import SearchBar from './SearchBar';
import SearchPagination from './SearchPagination';
import SearchProcessor, { SortDirection, sortModes } from './SearchProcessor';
import SearchResult from './SearchResult';
import { requestIdleCallback } from '../request-idle-callback';
import ManifestJson from '../serialization/ManifestJson';
import SearchResultsJson from '../serialization/SearchResultsJson';

const RESULTS_PER_PAGE = 20;
const SEARCH_PARAM_QUERY = 'q';
Expand Down Expand Up @@ -133,7 +133,6 @@ const Search = (): JSX.Element => {
setCurrentPage(getCurrentPageFromSearchParams());
}, [getCurrentPageFromSearchParams]);


if (getSortIndexFromSearchParams() !== sortIndex) {
setSortIndex(getSortIndexFromSearchParams());
}
Expand All @@ -147,7 +146,6 @@ const Search = (): JSX.Element => {
setInstallBucketName(getInstallBucketNameFromSearchParams());
}


useEffect(() => {
if (searchResults?.results && selectedResultId) {
const selectedResultManifest = searchResults.results.find((x) => x.id === selectedResultId);
Expand Down Expand Up @@ -205,17 +203,23 @@ const Search = (): JSX.Element => {
[updateSearchParams]
);

const handleSortChange = (newSortIndex: number, newSortDirection: SortDirection): void => {
updateSearchParams(SEARCH_PARAM_SORT_INDEX, newSortIndex.toString(), true);
updateSearchParams(SEARCH_PARAM_SORT_DIRECTION, newSortDirection.toString(), true);
setSortIndex(newSortIndex);
setSortDirection(newSortDirection);
};
const handleSortChange = useCallback(
(newSortIndex: number, newSortDirection: SortDirection): void => {
updateSearchParams(SEARCH_PARAM_SORT_INDEX, newSortIndex.toString(), true);
updateSearchParams(SEARCH_PARAM_SORT_DIRECTION, newSortDirection.toString(), true);
setSortIndex(newSortIndex);
setSortDirection(newSortDirection);
},
[updateSearchParams]
);

const handleSearchOfficialOnlyChange = (newSearchOfficialOnly: boolean): void => {
updateSearchParams(SEARCH_PARAM_FILTER_OFFICIALONLY, newSearchOfficialOnly.toString(), true);
setSearchOfficialOnly(newSearchOfficialOnly);
};
const handleSearchOfficialOnlyChange = useCallback(
(newSearchOfficialOnly: boolean): void => {
updateSearchParams(SEARCH_PARAM_FILTER_OFFICIALONLY, newSearchOfficialOnly.toString(), true);
setSearchOfficialOnly(newSearchOfficialOnly);
},
[updateSearchParams]
);

const handleCopyToClipboard = useCallback((newContentToCopy: string): void => {
const handleCopyToClipboardAsync = async (data: string) => {
Expand All @@ -236,7 +240,6 @@ const Search = (): JSX.Element => {
const handleInstallBucketName = useCallback(
(newInstallBucketName: boolean): void => {
updateSearchParams(SEARCH_PARAM_OPTION_BUCKETNAME, newInstallBucketName.toString(), true);

setInstallBucketName(newInstallBucketName);
},
[updateSearchParams]
Expand Down Expand Up @@ -264,9 +267,9 @@ const Search = (): JSX.Element => {
sortIndex={sortIndex}
sortDirection={sortDirection}
searchOfficialOnly={searchOfficialOnly}
onSearchOfficialOnlyChange={handleSearchOfficialOnlyChange}
onResultsChange={handleResultsChange}
onSortChange={handleSortChange}
onSearchOfficialOnlyChange={handleSearchOfficialOnlyChange}
installBucketName={installBucketName}
onInstallBucketName={handleInstallBucketName}
/>
Expand All @@ -281,10 +284,9 @@ const Search = (): JSX.Element => {
key={searchResult.id}
result={searchResult}
officialRepositories={officialRepositories}
installBucketName={installBucketName}
onCopyToClipbard={handleCopyToClipboard}
onResultSelected={handleResultSelected}
installBucketName={installBucketName}
onInstallBucketName={handleInstallBucketName}
/>
))}
</Col>
Expand Down Expand Up @@ -315,9 +317,8 @@ const Search = (): JSX.Element => {
<SearchResult
result={selectedResult}
officialRepositories={officialRepositories}
onCopyToClipbard={handleCopyToClipboard}
installBucketName={installBucketName}
onInstallBucketName={handleInstallBucketName}
onCopyToClipbard={handleCopyToClipboard}
/>
)}
</Modal.Body>
Expand Down
9 changes: 4 additions & 5 deletions src/components/SearchProcessor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import { IconBaseProps } from 'react-icons';
import { FaSortAmountDown, FaSortAmountUp } from 'react-icons/fa';
import { GoSettings } from 'react-icons/go';

import SearchResultsJson from '../serialization/SearchResultsJson';
import BucketTypeIcon from './BucketTypeIcon';
import SearchStatus, { SearchStatusType } from './SearchStatus';
import SearchResultsJson from '../serialization/SearchResultsJson';

export enum SortDirection {
Ascending,
Expand All @@ -26,14 +26,13 @@ type SearchProcessorProps = {
sortIndex: number;
sortDirection: SortDirection;
searchOfficialOnly: boolean;

onSearchOfficialOnlyChange: (searchOfficialOnly: boolean) => void;
installBucketName: boolean;
onInstallBucketName: (installBucketName: boolean) => void;

resultsPerPage: number;
onResultsChange: (value?: SearchResultsJson) => void;
onSortChange: (sortIndex: number, sortDirection: SortDirection) => void;
onSearchOfficialOnlyChange: (searchOfficialOnly: boolean) => void;
};

export const sortModes: SortMode[] = [
Expand Down Expand Up @@ -94,11 +93,11 @@ const SearchProcessor = (props: SearchProcessorProps): JSX.Element => {
sortIndex,
sortDirection,
searchOfficialOnly,
onResultsChange,
onSortChange,
onSearchOfficialOnlyChange,
installBucketName,
onInstallBucketName,
onResultsChange,
onSortChange,
} = props;

const handleSortChange = useCallback(
Expand Down
10 changes: 4 additions & 6 deletions src/components/SearchResult.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ import { Img } from 'react-image';
import deprecatedSpdxLicenses from 'spdx-license-ids/deprecated.json';
import supportedSpdxLicenses from 'spdx-license-ids/index.json';

import BucketTypeIcon from './BucketTypeIcon';
import CopyToClipboardButton from './CopyToClipboardButton';
import ManifestJson from '../serialization/ManifestJson';
import Utils from '../utils';
import BucketTypeIcon from './BucketTypeIcon';
import CopyToClipboardButton from './CopyToClipboardButton';

const spdxLicenses = supportedSpdxLicenses.concat(deprecatedSpdxLicenses);

Expand All @@ -22,16 +22,14 @@ dayjs.extend(relativeTime);
type SearchResultProps = {
result: ManifestJson;
officialRepositories: { [key: string]: string };
installBucketName: boolean;
onCopyToClipbard: (content: string) => void;
onResultSelected?: (result: ManifestJson) => void;
cardRef?: React.RefObject<HTMLDivElement>;

installBucketName: boolean;
onInstallBucketName: (installBucketName: boolean) => void;
};

const SearchResult = (props: SearchResultProps): JSX.Element => {
const { result, officialRepositories, onCopyToClipbard, onResultSelected, cardRef, installBucketName } = props;
const { result, officialRepositories, installBucketName, onCopyToClipbard, onResultSelected, cardRef } = props;
const homepageRef = useRef<HTMLSpanElement>(null);
const [homepageTooltipHidden, setHomepageTooltipHidden] = useState<boolean>(false);

Expand Down

0 comments on commit ba3ba79

Please sign in to comment.