From b3893995eabc04d9289f94630c5e19db1985b503 Mon Sep 17 00:00:00 2001 From: Nemesis Date: Mon, 6 Mar 2023 00:18:18 +0100 Subject: [PATCH] feat(weapons): add more filters --- src/components/pages/weapons.tsx | 80 ++++++++++++++++++++++++++++++-- src/store/weapons-filters.js | 8 ++++ 2 files changed, 83 insertions(+), 5 deletions(-) diff --git a/src/components/pages/weapons.tsx b/src/components/pages/weapons.tsx index cb0c28e..dbaf33e 100644 --- a/src/components/pages/weapons.tsx +++ b/src/components/pages/weapons.tsx @@ -113,24 +113,48 @@ export function filterWeapons( showUnreleasedContent, region = "GLOBAL", skills = [], + isRefinable, + isEX, + isRD, + isSubjugation, } ) { let filteredWeapons: IWeapon[] = weapons; if (!showUnreleasedContent) { const now = new Date(); - filteredWeapons = filteredWeapons.filter((costume) => { - return now >= new Date(costume.release_time); + filteredWeapons = filteredWeapons.filter((weapon) => { + return now >= new Date(weapon.release_time); }); } + if (isRefinable) { + filteredWeapons = filteredWeapons.filter( + (weapon) => weapon.weapon_ability_link[3] + ); + } + + if (isEX) { + filteredWeapons = filteredWeapons.filter((weapon) => weapon.is_ex_weapon); + } + + if (isRD) { + filteredWeapons = filteredWeapons.filter((weapon) => weapon.is_rd_weapon); + } + + if (isSubjugation) { + filteredWeapons = filteredWeapons.filter( + (weapon) => weapon.is_subjugation_weapon + ); + } + /** * SEA REGION * Hide GLOBAL/JP costumes */ if (!showUnreleasedContent && region === "SEA") { - filteredWeapons = filteredWeapons.filter((costume) => - hideSEASpoiler(costume.release_time) + filteredWeapons = filteredWeapons.filter((weapon) => + hideSEASpoiler(weapon.release_time) ); } @@ -160,6 +184,14 @@ export default function WeaponsPage({ const order = useSettingsStore((state) => state.order); const skills = useWeaponsFilters((state) => state.skills); const hasFilters = useWeaponsFilters((state) => state.computed.hasFilters); + const isRefinable = useWeaponsFilters((state) => state.isRefinable); + const setIsRefinable = useWeaponsFilters((state) => state.setIsRefinable); + const isEX = useWeaponsFilters((state) => state.isEX); + const isRD = useWeaponsFilters((state) => state.isRD); + const isSubjugation = useWeaponsFilters((state) => state.isSubjugation); + const setIsEX = useWeaponsFilters((state) => state.setIsEX); + const setIsRD = useWeaponsFilters((state) => state.setIsRD); + const setIsSubjugation = useWeaponsFilters((state) => state.setIsSubjugation); /** * Using a state and useEffect here because Next.js is @@ -225,6 +257,27 @@ export default function WeaponsPage({ ) : null } > + setIsRefinable(e.target.checked)} + label="Is refinable?" + /> + setIsEX(e.target.checked)} + label="Is EX?" + /> + setIsRD(e.target.checked)} + label="Is RoD?" + /> + setIsSubjugation(e.target.checked)} + label="Is Subjugation?" + /> + @@ -237,6 +290,10 @@ export default function WeaponsPage({ showUnreleasedContent, region, ownedWeapons, + isRefinable, + isEX, + isRD, + isSubjugation, })} abilitiesLookup={abilitiesLookup} valuedWeaponType={valuedWeaponType} @@ -252,6 +309,10 @@ export default function WeaponsPage({ showUnreleasedContent, region, ownedWeapons, + isRefinable, + isEX, + isRD, + isSubjugation, })} isSmall={displayType === "compact"} isLibrary={order === "library"} @@ -298,6 +359,15 @@ export function WeaponsTable({ showUnreleasedContent: boolean; valuedWeaponType?: string; }) { + const refiningAbilitiesLookup = {}; + weapons + .filter((weapon) => (weapon.weapon_ability_link[3] ? true : false)) + .forEach((weapon) => { + refiningAbilitiesLookup[ + weapon.weapon_ability_link[3].weapon_ability.name + ] = weapon.weapon_ability_link[3].weapon_ability.name; + }); + return ( { if (term.length === 0) return true; return term.includes( diff --git a/src/store/weapons-filters.js b/src/store/weapons-filters.js index 549d7c1..30333de 100644 --- a/src/store/weapons-filters.js +++ b/src/store/weapons-filters.js @@ -3,6 +3,10 @@ import { create } from 'zustand'; export const useWeaponsFilters = create((set, get) => ({ skills: [], + isRefinable: false, + isEX: false, + isRD: false, + isSubjugation: false, clear: () => set({ skills: [], }), @@ -35,4 +39,8 @@ export const useWeaponsFilters = create((set, get) => ({ skills: newSkills }; }), + setIsRefinable: (isRefinable) => set({ isRefinable }), + setIsEX: (isEX) => set({ isEX }), + setIsRD: (isRD) => set({ isRD }), + setIsSubjugation: (isSubjugation) => set({ isSubjugation }), })); \ No newline at end of file