diff --git a/src/cardFilter.tsx b/src/cardFilter.tsx index 3d12dde..30f4190 100644 --- a/src/cardFilter.tsx +++ b/src/cardFilter.tsx @@ -6,6 +6,7 @@ import { CardCriteria, CardCriteriaFields, ColorToggles, + EMPTY_CRITERIA, TagInput, applyCardCriteria, criteriaActive, @@ -95,6 +96,8 @@ export interface CardFilterState { filter: LibraryFilter; /** Whether anything is filtered on at all. */ active: boolean; + /** Clear every field and criterion. */ + reset: () => void; } /** State for a {@link CardFilterPanel}. `criteriaKey` persists the criteria @@ -108,7 +111,11 @@ export function useCardFilter(criteriaKey: string): CardFilterState { const json = JSON.stringify(toFilter(fields, criteria)); const filter = useMemo(() => JSON.parse(json) as LibraryFilter, [json]); const active = fieldsActive(fields) || criteriaActive(criteria); - return { fields, patch, criteria, patchCriteria, filter, active }; + const reset = () => { + setFields(EMPTY_FIELDS); + patchCriteria(EMPTY_CRITERIA); + }; + return { fields, patch, criteria, patchCriteria, filter, active, reset }; } /** @@ -121,6 +128,9 @@ export function CardFilterPanel({ facets, decks, hideNotOwned, + hideName, + hideInDeck, + alwaysExpanded, }: { state: CardFilterState; /** Suggestions for the type/subtype/keyword inputs. */ @@ -129,6 +139,13 @@ export function CardFilterPanel({ decks: Deck[]; /** Omit the "Not owned" toggle — for the Library, which only shows owned cards. */ hideNotOwned?: boolean; + /** Omit "Name contains" — for a caller with its own name box. */ + hideName?: boolean; + /** Omit "In deck" — for a caller already scoped to one deck. */ + hideInDeck?: boolean; + /** Show every field at every width, with no "More filters" toggle — for a + * popup, which has the room. */ + alwaysExpanded?: boolean; }) { const { fields: f, patch } = state; // Collapsed by default (relevant on narrow/mobile screens only). @@ -136,11 +153,13 @@ export function CardFilterPanel({ return ( <>
{error}
} +