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

Exclusive Multiselect Example (Size) #12

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions src/components/FiltersSlideover.vue
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ defineProps({
mode="tags"
placeholder="Any size"
v-model="filters.size"
:groups="true"
:options="filters.sizeOptions"
></Multiselect>
</div>
Expand Down
43 changes: 36 additions & 7 deletions src/stores/filters.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,28 @@ export const useFilters = defineStore("filters", {
},
size: helpers.migrateLocalStorage("filtersSize", "size", []),
sizeOptions: [
{ value: "tiny", label: "Tiny" },
{ value: "small", label: "Small" },
{ value: "medium", label: "Medium" },
{ value: "large", label: "Large" },
{ value: "huge", label: "Huge" },
{ value: "gargantuan", label: "Gargantuan" },
{
label:"Include",
options:[
{ value: "tiny", label: "Tiny" },
{ value: "small", label: "Small" },
{ value: "medium", label: "Medium" },
{ value: "large", label: "Large" },
{ value: "huge", label: "Huge" },
{ value: "gargantuan", label: "Gargantuan" },
]
},
{
label:"Exclude",
options:[
{ value: "ex-tiny", label: "-Tiny" },
{ value: "ex-small", label: "-Small" },
{ value: "ex-medium", label: "-Medium" },
{ value: "ex-large", label: "-Large" },
{ value: "ex-huge", label: "-Huge" },
{ value: "ex-gargantuan", label: "-Gargantuan" },
]
}
],
legendary: helpers.migrateLocalStorage(
"filtersLegendary",
Expand Down Expand Up @@ -173,7 +189,20 @@ export const useFilters = defineStore("filters", {
return {
search: (monster) => this.searchFor(monster.searchable),
alignment: (monster) => monster.alignment.bits & state.alignment.bits,
size: (monster) => state.size.includes(monster.size.toLowerCase()),
size: (monster) => {
const monsterSize = monster.size.toLowerCase();
const exclusiveFilters = state.size.filter((s)=>s.indexOf('ex-') === 0);
const inclusiveFilters = state.size.filter((s)=>s.indexOf('ex-') !== 0);

const isNotExcluded =
exclusiveFilters.length === 0 ||
!exclusiveFilters.includes(`ex-${monsterSize}`);
const isIncluded =
inclusiveFilters.length === 0 ||
inclusiveFilters.includes(monsterSize);

return isNotExcluded && isIncluded;
},
type: (monster) => state.type.includes(monster.type.toLowerCase()),
environment: (monster) =>
state.environment.find((environment) =>
Expand Down