From d2eabf629706b517a76a9b433ca34ba071a67da8 Mon Sep 17 00:00:00 2001 From: Sakura Knoll Date: Sun, 9 Jan 2022 20:52:36 +0900 Subject: [PATCH] Hide battlesuit filters for small display --- public/locales/en-US/common.json | 1 + public/locales/ko-KR/common.json | 1 + src/components/atoms/FilterButton.tsx | 20 ++++++++++---- src/pages/honkai3rd/battlesuits/index.tsx | 32 ++++++++++++++++++++--- 4 files changed, 46 insertions(+), 8 deletions(-) diff --git a/public/locales/en-US/common.json b/public/locales/en-US/common.json index 63823da6..2fa82084 100644 --- a/public/locales/en-US/common.json +++ b/public/locales/en-US/common.json @@ -25,6 +25,7 @@ }, "battlesuits-list": { "heading": "Battlesuits", + "filters": "Filters", "filter-by-features": "Filter by Features", "filter-by-valkyries": "Filter by Valkyries" }, diff --git a/public/locales/ko-KR/common.json b/public/locales/ko-KR/common.json index 1c1fa118..3b8749f5 100644 --- a/public/locales/ko-KR/common.json +++ b/public/locales/ko-KR/common.json @@ -20,6 +20,7 @@ }, "battlesuits-list": { "heading": "발키리", + "filters": "필터", "filter-by-features": "특성 필터", "filter-by-valkyries": "발키리 필터" }, diff --git a/src/components/atoms/FilterButton.tsx b/src/components/atoms/FilterButton.tsx index 5df106cb..ada005f3 100644 --- a/src/components/atoms/FilterButton.tsx +++ b/src/components/atoms/FilterButton.tsx @@ -1,5 +1,6 @@ /** @jsxImportSource theme-ui */ -import PageLink from './PageLink' +import { useRouter } from 'next/router' +import { Link } from 'theme-ui' import SquareImageBox from './SquareImageBox' interface FilterButtonProps { @@ -8,6 +9,7 @@ interface FilterButtonProps { label: string value: string m?: string | number + close?: () => void } const FilterButton = ({ @@ -16,17 +18,25 @@ const FilterButton = ({ label, value, m, + close, }: FilterButtonProps) => { + const { push } = useRouter() return ( - { + event.preventDefault() + if (close != null) { + close() + } + push({ query: { filter: value } }, undefined, { shallow: true }) + }} > {icon != null && ( )} {label} - + ) } diff --git a/src/pages/honkai3rd/battlesuits/index.tsx b/src/pages/honkai3rd/battlesuits/index.tsx index 8d679ec8..352163f0 100644 --- a/src/pages/honkai3rd/battlesuits/index.tsx +++ b/src/pages/honkai3rd/battlesuits/index.tsx @@ -1,7 +1,7 @@ /** @jsxImportSource theme-ui */ -import { Box, Heading, Flex } from '@theme-ui/components' +import { Box, Heading, Flex, Button } from '@theme-ui/components' import { pick } from 'ramda' -import { useMemo } from 'react' +import { useCallback, useMemo, useState } from 'react' import FilterButton from '../../../components/atoms/FilterButton' import Breadcrumb from '../../../components/organisms/Breadcrumb' import Honkai3rdNavigator from '../../../components/organisms/Honkai3rdNavigator' @@ -48,6 +48,11 @@ const valkyrieFilterOptions: { const BattlesuitListPage = ({ battlesuits }: BattlesuitListPageProps) => { const { query, locale } = useRouter() const { t } = useTranslation() + const [hiddenFilters, setHiddenFilters] = useState(true) + + const closeFilters = useCallback(() => { + setHiddenFilters(true) + }, []) const filter = useMemo(() => { if (query.filter == null) { @@ -87,7 +92,26 @@ const BattlesuitListPage = ({ battlesuits }: BattlesuitListPageProps) => { {t('battlesuits-list.heading')} - + + + + {t('battlesuits-list.filter-by-features')} {featureFilterOptions.map(({ value, label, icon, krLabel }) => { @@ -99,6 +123,7 @@ const BattlesuitListPage = ({ battlesuits }: BattlesuitListPageProps) => { label={translate(locale, { 'ko-KR': krLabel }, label)} icon={icon} m={1} + close={closeFilters} /> ) })} @@ -115,6 +140,7 @@ const BattlesuitListPage = ({ battlesuits }: BattlesuitListPageProps) => { label={translate(locale, { 'ko-KR': krLabel }, label)} icon={icon} m={1} + close={closeFilters} /> ) })}