Skip to content

Commit

Permalink
run prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
dowdiness committed Jan 15, 2024
1 parent 5e9de60 commit 24b81fe
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 9 deletions.
30 changes: 23 additions & 7 deletions app/javascript/components/Users/FilterByRegion.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@ import useSWR from 'swr'
// helper
import fetcher from '../../fetcher'

function RegionCard({ region, numberOfUsersByRegion, updateSelectedSubdivisionOrCountry }) {
function RegionCard({
region,
numberOfUsersByRegion,
updateSelectedSubdivisionOrCountry
}) {
return (
<nav className="page-nav a-card">
<header className="page-nav__header">
Expand All @@ -23,7 +27,9 @@ function RegionCard({ region, numberOfUsersByRegion, updateSelectedSubdivisionOr
{Object.keys(numberOfUsersByRegion).map((subdivisionOrCountry) => (
<li key={subdivisionOrCountry} className="page-nav__item">
<button
onClick={() => updateSelectedSubdivisionOrCountry(region, subdivisionOrCountry)}
onClick={() =>
updateSelectedSubdivisionOrCountry(region, subdivisionOrCountry)
}
className="page-nav__item-link a-text-link">
{`${subdivisionOrCountry}${numberOfUsersByRegion[subdivisionOrCountry]})`}
</button>
Expand All @@ -38,12 +44,20 @@ function RegionCard({ region, numberOfUsersByRegion, updateSelectedSubdivisionOr
* 都道府県を指定しないデフォルトでは東京都が選択されます
*/
export default function FilterByRegion({ numberOfUsersByRegion }) {
const [searchParams, setSearchParams] = useSearchParams({ subdivision_or_country: '東京都' })
const [searchParams, setSearchParams] = useSearchParams({
subdivision_or_country: '東京都'
})
const apiUrl = '/api/users/regions?'
const { data: users, error, mutate } = useSWR(apiUrl + searchParams, fetcher)

const updateSelectedSubdivisionOrCountry = async (region, subdivisionOrCountry) => {
const search = new URLSearchParams({ region, subdivision_or_country: subdivisionOrCountry })
const updateSelectedSubdivisionOrCountry = async (
region,
subdivisionOrCountry
) => {
const search = new URLSearchParams({
region,
subdivision_or_country: subdivisionOrCountry
})
const newUsers = await fetcher(apiUrl + search).catch((error) => {
console.error(error)
})
Expand Down Expand Up @@ -72,13 +86,15 @@ export default function FilterByRegion({ numberOfUsersByRegion }) {

return (
<MultiColumns data-testid="regions" isReverse>
<MultiColumns.Sub className='is-sm'>
<MultiColumns.Sub className="is-sm">
{Object.keys(numberOfUsersByRegion).map((region) => (
<RegionCard
key={region}
region={region}
numberOfUsersByRegion={numberOfUsersByRegion[region]}
updateSelectedSubdivisionOrCountry={updateSelectedSubdivisionOrCountry}
updateSelectedSubdivisionOrCountry={
updateSelectedSubdivisionOrCountry
}
/>
))}
</MultiColumns.Sub>
Expand Down
9 changes: 7 additions & 2 deletions app/javascript/components/layout/MultiColumns.jsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
import React from 'react'
import clsx from 'clsx'

export const MultiColumns = ({ className, children, isReverse = false, ...props}) => {
export const MultiColumns = ({
className,
children,
isReverse = false,
...props
}) => {
return (
<div className={clsx('page-body', className)} {...props}>
<div className="container is-lg">
<div className={clsx('page-body__columns', isReverse && 'is-reverse' )}>
<div className={clsx('page-body__columns', isReverse && 'is-reverse')}>
{children}
</div>
</div>
Expand Down

0 comments on commit 24b81fe

Please sign in to comment.