diff --git a/src/pages/honkai3rd/weapons/index.tsx b/src/pages/honkai3rd/weapons/index.tsx index 48bc8bf3..abe1713b 100644 --- a/src/pages/honkai3rd/weapons/index.tsx +++ b/src/pages/honkai3rd/weapons/index.tsx @@ -1,17 +1,96 @@ /** @jsxImportSource theme-ui */ import { Text, Box, Heading, Flex, Link } from '@theme-ui/components' -import Image from 'next/image' import NextLink from 'next/link' import Breadcrumb from '../../../components/organisms/Breadcrumb' import Honkai3rdNavigator from '../../../components/organisms/Honkai3rdNavigator' import { listWeapons, WeaponData } from '../../../data/honkai3rd/weapons' import { pick } from 'ramda' +import SquareImageBox from '../../../components/atoms/SquareImageBox' +import { useMemo, useState } from 'react' +import FilterButton from '../../../components/atoms/FilterButton' + +type WeaponListItemData = Pick< + WeaponData, + 'id' | 'name' | 'rarity' | 'category' +> interface WeaponListPageProps { - weaponDataList: Pick[] + weaponDataList: WeaponListItemData[] } +const weaponFilterOptions = [ + { value: 'all', label: 'All' }, + { value: 'pistol', label: 'Pistols' }, + { value: 'katana', label: 'Katanas' }, + { value: 'cannon', label: 'Cannons' }, + { value: 'greatsword', label: 'Greatswords' }, + { value: 'cross', label: 'Crosses' }, + { value: 'gauntlet', label: 'Gauntlets' }, + { value: 'scythe', label: 'Scythes' }, + { value: 'lance', label: 'Lances' }, + { value: 'bow', label: 'Bows' }, +] + const WeaponListPage = ({ weaponDataList }: WeaponListPageProps) => { + const [filter, setFilter] = useState('all') + + const weaponList = useMemo(() => { + return weaponDataList.map((weapon) => { + const hidden = isWeaponHidden(weapon, filter) + return ( + + + + + + {weapon.name} + + + {'⭐'.repeat(weapon.rarity)} + + + + + ) + }) + }, [weaponDataList, filter]) + return ( @@ -25,73 +104,29 @@ const WeaponListPage = ({ weaponDataList }: WeaponListPageProps) => { /> Weapons - + + Filter by Category + + {weaponFilterOptions.map(({ value, label }) => { + return ( + + ) + })} + + - {weaponDataList.map((weapon) => { - return ( - - - - - {weapon.name} - - - {weapon.name} - - - {'⭐'.repeat(weapon.rarity)} - - - - - ) - })} + {weaponList} @@ -104,8 +139,26 @@ export async function getStaticProps() { return { props: { weaponDataList: listWeapons().map((weapon) => { - return pick(['name', 'id', 'rarity'], weapon) + return pick(['name', 'id', 'rarity', 'category'], weapon) }), }, } } + +function isWeaponHidden(weapon: WeaponListItemData, filter: string): boolean { + switch (filter) { + case 'pistol': + case 'katana': + case 'cannon': + case 'greatsword': + case 'cross': + case 'gauntlet': + case 'scythe': + case 'lance': + case 'bow': + return weapon.category !== filter + default: + case 'all': + return false + } +}