Skip to content

Commit

Permalink
feat: add filter shortcut for types
Browse files Browse the repository at this point in the history
  • Loading branch information
fspoettel committed Jun 18, 2024
1 parent 8fd5239 commit 40fb86b
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 7 deletions.
3 changes: 3 additions & 0 deletions src/components/filters/primitives/multiselect-filter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { FilterContainer } from "./filter-container";

type Props<T extends Coded> = {
changes?: string;
children?: React.ReactNode;
id: number;
itemToString?: (val: T) => string;
nameRenderer?: (val: T) => React.ReactNode;
Expand All @@ -20,6 +21,7 @@ type Props<T extends Coded> = {

export function MultiselectFilter<T extends Coded>({
changes,
children,
id,
itemToString,
nameRenderer,
Expand Down Expand Up @@ -55,6 +57,7 @@ export function MultiselectFilter<T extends Coded>({
<FilterContainer
filterString={changes}
onOpenChange={onOpenChange}
nonCollapsibleContent={children}

Check warning on line 60 in src/components/filters/primitives/multiselect-filter.tsx

View workflow job for this annotation

GitHub Actions / Lint

Props should be sorted alphabetically
onReset={onReset}
open={open}
title={title}
Expand Down
35 changes: 34 additions & 1 deletion src/components/filters/type-filter.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import { useCallback } from "react";

import { useStore } from "@/store";
import {
selectActiveList,
selectActiveListFilter,
selectMultiselectChanges,
selectTypeOptions,
Expand All @@ -8,13 +11,17 @@ import type { Type } from "@/store/services/queries.types";
import { isTypeFilterObject } from "@/store/slices/lists.type-guards";
import { assert } from "@/utils/assert";

import { ToggleGroup, ToggleGroupItem } from "../ui/toggle-group";
import { MultiselectFilter } from "./primitives/multiselect-filter";

const nameRenderer = (item: Type) => item.name;
const itemToString = (item: Type) => item.name.toLowerCase();

export function TypeFilter({ id }: { id: number }) {
const activeList = useStore(selectActiveList);
const filter = useStore((state) => selectActiveListFilter(state, id));
const setFilterValue = useStore((state) => state.setFilterValue);

assert(
isTypeFilterObject(filter),
`TypeFilter instantiated with '${filter?.type}'`,
Expand All @@ -23,6 +30,13 @@ export function TypeFilter({ id }: { id: number }) {
const changes = selectMultiselectChanges(filter.value);
const options = useStore(selectTypeOptions);

const handleApplyShortcut = useCallback(
(value: string[]) => {
setFilterValue(id, value);
},
[id, setFilterValue, filter.value],

Check warning on line 37 in src/components/filters/type-filter.tsx

View workflow job for this annotation

GitHub Actions / Lint

React Hook useCallback has an unnecessary dependency: 'filter.value'. Either exclude it or remove the dependency array
);

return (
<MultiselectFilter
changes={changes}
Expand All @@ -34,6 +48,25 @@ export function TypeFilter({ id }: { id: number }) {
placeholder="Select type(s)..."
title="Type"
value={filter.value}
/>
>
{!filter.open && activeList?.cardType === "player" && (
<ToggleGroup
full
type="multiple"
onValueChange={handleApplyShortcut}

Check warning on line 56 in src/components/filters/type-filter.tsx

View workflow job for this annotation

GitHub Actions / Lint

Props should be sorted alphabetically
value={filter.value}
>
<ToggleGroupItem value="asset" size="small-type">

Check warning on line 59 in src/components/filters/type-filter.tsx

View workflow job for this annotation

GitHub Actions / Lint

Props should be sorted alphabetically
Asset
</ToggleGroupItem>
<ToggleGroupItem value="event" size="small-type">

Check warning on line 62 in src/components/filters/type-filter.tsx

View workflow job for this annotation

GitHub Actions / Lint

Props should be sorted alphabetically
Event
</ToggleGroupItem>
<ToggleGroupItem value="skill" size="small-type">

Check warning on line 65 in src/components/filters/type-filter.tsx

View workflow job for this annotation

GitHub Actions / Lint

Props should be sorted alphabetically
Skill
</ToggleGroupItem>
</ToggleGroup>
)}
</MultiselectFilter>
);
}
8 changes: 7 additions & 1 deletion src/components/ui/toggle-group.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,12 @@
&:hover:not([data-state="on"]),
&:active:not([data-state="on"]),
&:focus-visible:not([data-state="on"]) {
background: var(--nord-2);
background: var(--nord-1);
}

&:hover[data-state="on"],
&:active[data-state="on"],
&:focus-visible[data-state="on"] {
background: var(--nord-3);
}
}
4 changes: 2 additions & 2 deletions src/pages/deck-view/deck-view.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
row-gap: 1rem;
display: grid;
grid-template-columns: 1fr;
grid-template-rows: min-content min-content min-content min-content;
grid-template-rows: min-content min-content min-content;
grid-template-areas:
"header"
"sidebar"
Expand All @@ -16,7 +16,7 @@
grid-template-areas:
"sidebar header"
"sidebar decklist";
grid-template-rows: min-content min-content 1fr;
grid-template-rows: min-content 1fr;
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/store/slices/lists.ts
Original file line number Diff line number Diff line change
Expand Up @@ -539,12 +539,12 @@ export function makePlayerCardsList(
): List {
const filters: FilterKey[] = [
"faction",
"type",
"level",
"ownership",
"investigator",
"level",
"cost",
"trait",
"type",
"subtype",
"asset",
"skillIcons",
Expand Down Expand Up @@ -593,10 +593,10 @@ export function makeEncounterCardsList(
): List {
const filters: FilterKey[] = [
"faction",
"type",
"ownership",
"cost",
"trait",
"type",
"subtype",
"asset",
"skillIcons",
Expand Down

0 comments on commit 40fb86b

Please sign in to comment.