Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add a "Select all" for the filters #113

Merged
merged 3 commits into from
Aug 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 58 additions & 0 deletions pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import StrategyEntity from 'components/StrategyEntity';
import PartnerEntity from 'components/PartnerEntity';

const defaultSettings: TSettings = {
shouldShowAllFilters: true,
shouldShowOnlyAnomalies: true,
shouldShowOnlyEndorsed: true,
shouldShowVersion: 'v4',
Expand Down Expand Up @@ -63,6 +64,62 @@ const AnomaliesCheckbox = ({appSettings, set_appSettings}: {
</label>;
};

const SelectAllCheckbox = ({appSettings, set_appSettings}: {
appSettings: TSettings,
set_appSettings: React.Dispatch<React.SetStateAction<TSettings>>
}): ReactElement | null => {
useEffect((): void => {
set_appSettings((prev): TSettings => {
const isAllSelected = [
prev.shouldShowMissingTranslations,
prev.shouldShowIcons,
prev.shouldShowPrice,
prev.shouldShowRetirement,
prev.shouldShowYearnMetaFile,
prev.shouldShowLedgerLive,
prev.shouldShowStrategies,
prev.shouldShowRisk,
prev.shouldShowRiskScore,
prev.shouldShowDescriptions,
prev.shouldShowAPY,
prev.shouldShowWantTokenDescription
].every(Boolean);

return ({...prev, shouldShowAllFilters: isAllSelected});
});
}, [set_appSettings]);

return <label
htmlFor={'checkbox-anomalies'}
className={'flex w-fit cursor-pointer flex-row items-center rounded-lg bg-neutral-200/60 p-2 font-mono text-sm text-neutral-500 transition-colors hover:bg-neutral-200'}>
<p className={'pr-4'}>{'Select All Filters'}</p>
<input
type={'checkbox'}
id={'checkbox-select-all'}
className={'ml-2 rounded-lg'}
checked={appSettings.shouldShowAllFilters}
onChange={(): void => {
const isSelectAllChecked = !appSettings.shouldShowAllFilters;
set_appSettings({
...appSettings,
shouldShowAllFilters: isSelectAllChecked,
shouldShowMissingTranslations: isSelectAllChecked,
shouldShowIcons: isSelectAllChecked,
shouldShowPrice: isSelectAllChecked,
shouldShowRetirement: isSelectAllChecked,
shouldShowYearnMetaFile: isSelectAllChecked,
shouldShowLedgerLive: isSelectAllChecked,
shouldShowStrategies: isSelectAllChecked,
shouldShowRisk: isSelectAllChecked,
shouldShowRiskScore: isSelectAllChecked,
shouldShowDescriptions: isSelectAllChecked,
shouldShowAPY: isSelectAllChecked,
shouldShowWantTokenDescription: isSelectAllChecked
});
}} />
</label>;
};

function convertToKebabCase(str: string): string {
return str
.trim()
Expand Down Expand Up @@ -277,6 +334,7 @@ function Index(): ReactNode {
/>
</span>
{shouldShowAnomaliesCheckbox ? <AnomaliesCheckbox appSettings={appSettings} set_appSettings={set_appSettings} /> : null}
<SelectAllCheckbox appSettings={appSettings} set_appSettings={set_appSettings} />
</div>
</div>
<div className={'flex flex-wrap pb-6'}>
Expand Down
1 change: 1 addition & 0 deletions types/types.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {TProtocolsData, TStrategiesData, TTokensData, TVaultsData} from './entit
export type TEntity = 'vaults' | 'tokens' | 'protocols' | 'strategies' | 'partners';
export type TVersions = 'all' | 'v2' | 'v3' | 'v4';
export type TSettings = {
shouldShowAllFilters: boolean,
shouldShowOnlyAnomalies: boolean,
shouldShowOnlyEndorsed: boolean,
shouldShowMissingTranslations: boolean,
Expand Down
Loading