## Summary
- Fixed translation key format compatibility with next-intl
- Fixed pluralization format from i18next to next-intl format
- Fixed dynamic translation key error handling
- Updated server components to match API response structure
- Fixed useSearchParams import location
## Changes
- Changed pluralization from `{{count}} items` to `{count} items` format
- Added proper error handling for missing translation keys
- Fixed import paths for next-intl hooks
- Fixed PartyPageClient trying to set non-existent appState.parties
## Test plan
- [x] Verified translations render correctly
- [x] Tested pluralization works with different counts
- [x] Confirmed no console errors about missing translations
- [x] Tested party page functionality
🤖 Generated with [Claude Code](https://claude.ai/code)
---------
Co-authored-by: Claude <noreply@anthropic.com>
120 lines
2.9 KiB
TypeScript
120 lines
2.9 KiB
TypeScript
'use client'
|
|
import React, { useEffect, useState } from 'react'
|
|
import { getCookie } from 'cookies-next'
|
|
import { useTranslations } from 'next-intl'
|
|
import classNames from 'classnames'
|
|
|
|
import * as ToggleGroup from '@radix-ui/react-toggle-group'
|
|
import styles from './index.module.scss'
|
|
|
|
interface Props {
|
|
currentElement: number
|
|
sendValue: (value: number) => void
|
|
}
|
|
|
|
const ElementToggle = ({ currentElement, sendValue, ...props }: Props) => {
|
|
// Localization
|
|
const locale = (getCookie('NEXT_LOCALE') as string) || 'en'
|
|
|
|
const t = useTranslations('common')
|
|
|
|
// State: Component
|
|
const [element, setElement] = useState(currentElement)
|
|
|
|
// Methods: Handlers
|
|
const handleElementChange = (value: string) => {
|
|
const newElement = parseInt(value)
|
|
setElement(newElement)
|
|
sendValue(newElement)
|
|
}
|
|
|
|
// Methods: Rendering
|
|
return (
|
|
<ToggleGroup.Root
|
|
className={styles.group}
|
|
type="single"
|
|
value={`${element}`}
|
|
aria-label="Element"
|
|
onValueChange={handleElementChange}
|
|
>
|
|
<ToggleGroup.Item
|
|
className={classNames({
|
|
[styles.item]: true,
|
|
[styles[`${locale}`]]: true,
|
|
})}
|
|
value="0"
|
|
aria-label="null"
|
|
>
|
|
{t('elements.null')}
|
|
</ToggleGroup.Item>
|
|
<ToggleGroup.Item
|
|
className={classNames({
|
|
[styles.item]: true,
|
|
[styles.wind]: true,
|
|
[styles[`${locale}`]]: true,
|
|
})}
|
|
value="1"
|
|
aria-label="wind"
|
|
>
|
|
{t('elements.wind')}
|
|
</ToggleGroup.Item>
|
|
<ToggleGroup.Item
|
|
className={classNames({
|
|
[styles.item]: true,
|
|
[styles.fire]: true,
|
|
[styles[`${locale}`]]: true,
|
|
})}
|
|
value="2"
|
|
aria-label="fire"
|
|
>
|
|
{t('elements.fire')}
|
|
</ToggleGroup.Item>
|
|
<ToggleGroup.Item
|
|
className={classNames({
|
|
[styles.item]: true,
|
|
[styles.water]: true,
|
|
[styles[`${locale}`]]: true,
|
|
})}
|
|
value="3"
|
|
aria-label="water"
|
|
>
|
|
{t('elements.water')}
|
|
</ToggleGroup.Item>
|
|
<ToggleGroup.Item
|
|
className={classNames({
|
|
[styles.item]: true,
|
|
[styles.earth]: true,
|
|
[styles[`${locale}`]]: true,
|
|
})}
|
|
value="4"
|
|
aria-label="earth"
|
|
>
|
|
{t('elements.earth')}
|
|
</ToggleGroup.Item>
|
|
<ToggleGroup.Item
|
|
className={classNames({
|
|
[styles.item]: true,
|
|
[styles.dark]: true,
|
|
[styles[`${locale}`]]: true,
|
|
})}
|
|
value="5"
|
|
aria-label="dark"
|
|
>
|
|
{t('elements.dark')}
|
|
</ToggleGroup.Item>
|
|
<ToggleGroup.Item
|
|
className={classNames({
|
|
[styles.item]: true,
|
|
[styles.light]: true,
|
|
[styles[`${locale}`]]: true,
|
|
})}
|
|
value="6"
|
|
aria-label="light"
|
|
>
|
|
{t('elements.light')}
|
|
</ToggleGroup.Item>
|
|
</ToggleGroup.Root>
|
|
)
|
|
}
|
|
|
|
export default ElementToggle
|