Skip to content

Commit

Permalink
feat(weapons): add more filters
Browse files Browse the repository at this point in the history
  • Loading branch information
KeziahMoselle committed Mar 5, 2023
1 parent 17e7312 commit b389399
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 5 deletions.
80 changes: 75 additions & 5 deletions src/components/pages/weapons.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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)
);
}

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -225,6 +257,27 @@ export default function WeaponsPage({
) : null
}
>
<Checkbox
isChecked={isRefinable}
setState={(e) => setIsRefinable(e.target.checked)}
label="Is refinable?"
/>
<Checkbox
isChecked={isEX}
setState={(e) => setIsEX(e.target.checked)}
label="Is EX?"
/>
<Checkbox
isChecked={isRD}
setState={(e) => setIsRD(e.target.checked)}
label="Is RoD?"
/>
<Checkbox
isChecked={isSubjugation}
setState={(e) => setIsSubjugation(e.target.checked)}
label="Is Subjugation?"
/>

<WeaponsSkillsFilters />
</DatabaseNavbar>

Expand All @@ -237,6 +290,10 @@ export default function WeaponsPage({
showUnreleasedContent,
region,
ownedWeapons,
isRefinable,
isEX,
isRD,
isSubjugation,
})}
abilitiesLookup={abilitiesLookup}
valuedWeaponType={valuedWeaponType}
Expand All @@ -252,6 +309,10 @@ export default function WeaponsPage({
showUnreleasedContent,
region,
ownedWeapons,
isRefinable,
isEX,
isRD,
isSubjugation,
})}
isSmall={displayType === "compact"}
isLibrary={order === "library"}
Expand Down Expand Up @@ -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 (
<MaterialTable
title={title ?? `${weapons.length} weapons in the database.`}
Expand Down Expand Up @@ -581,7 +651,7 @@ export function WeaponsTable({
cellStyle: {
textAlign: "center",
},
lookup: abilitiesLookup,
lookup: refiningAbilitiesLookup,
customFilterAndSearch: (term, weapon) => {
if (term.length === 0) return true;
return term.includes(
Expand Down
8 changes: 8 additions & 0 deletions src/store/weapons-filters.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: [],
}),
Expand Down Expand Up @@ -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 }),
}));

0 comments on commit b389399

Please sign in to comment.