## 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>
126 lines
3.2 KiB
TypeScript
126 lines
3.2 KiB
TypeScript
'use client'
|
|
import React, {
|
|
forwardRef,
|
|
useEffect,
|
|
useImperativeHandle,
|
|
useState,
|
|
} from 'react'
|
|
import { useTranslations } from 'next-intl'
|
|
import { getCookie } from 'cookies-next'
|
|
import { SuggestionProps } from '@tiptap/suggestion'
|
|
import classNames from 'classnames'
|
|
|
|
import styles from './index.module.scss'
|
|
|
|
type Props = Pick<SuggestionProps, 'items' | 'command' | 'query'>
|
|
|
|
export type MentionRef = {
|
|
onKeyDown: (props: { event: KeyboardEvent }) => boolean
|
|
}
|
|
|
|
export type MentionSuggestion = {
|
|
granblue_id: string
|
|
name: {
|
|
[key: string]: string
|
|
en: string
|
|
ja: string
|
|
}
|
|
type: string
|
|
element: number
|
|
}
|
|
|
|
interface MentionProps extends SuggestionProps {
|
|
items: MentionSuggestion[]
|
|
}
|
|
|
|
export const MentionList = forwardRef<MentionRef, Props>(
|
|
({ items, ...props }: Props, forwardedRef) => {
|
|
const locale = (getCookie('NEXT_LOCALE') as string) || 'en'
|
|
|
|
const t = useTranslations('common')
|
|
|
|
const [selectedIndex, setSelectedIndex] = useState(0)
|
|
|
|
const selectItem = (index: number) => {
|
|
const item = items[index]
|
|
|
|
if (item) {
|
|
props.command({ id: item })
|
|
}
|
|
}
|
|
|
|
const upHandler = () => {
|
|
setSelectedIndex((selectedIndex + items.length - 1) % items.length)
|
|
}
|
|
|
|
const downHandler = () => {
|
|
setSelectedIndex((selectedIndex + 1) % items.length)
|
|
}
|
|
|
|
const enterHandler = () => {
|
|
selectItem(selectedIndex)
|
|
}
|
|
|
|
useEffect(() => setSelectedIndex(0), [items])
|
|
|
|
useImperativeHandle(forwardedRef, () => ({
|
|
onKeyDown: ({ event }) => {
|
|
if (event.key === 'ArrowUp') {
|
|
upHandler()
|
|
return true
|
|
}
|
|
|
|
if (event.key === 'ArrowDown') {
|
|
downHandler()
|
|
return true
|
|
}
|
|
|
|
if (event.key === 'Enter') {
|
|
enterHandler()
|
|
return true
|
|
}
|
|
|
|
return false
|
|
},
|
|
}))
|
|
|
|
return (
|
|
<div className={styles.items}>
|
|
{items.length ? (
|
|
items.map((item, index) => (
|
|
<button
|
|
className={classNames({
|
|
[styles.item]: true,
|
|
[styles.selected]: index === selectedIndex,
|
|
})}
|
|
key={index}
|
|
onClick={() => selectItem(index)}
|
|
>
|
|
<div className={styles[item.type]}>
|
|
<img
|
|
alt={item.name[locale]}
|
|
src={
|
|
item.type === 'character'
|
|
? `${process.env.NEXT_PUBLIC_SIERO_IMG_URL}/${item.type}-square/${item.granblue_id}_01.jpg`
|
|
: item.type === 'job'
|
|
? `${process.env.NEXT_PUBLIC_SIERO_IMG_URL}/job-icons/${item.granblue_id}.png`
|
|
: `${process.env.NEXT_PUBLIC_SIERO_IMG_URL}/${item.type}-square/${item.granblue_id}.jpg`
|
|
}
|
|
/>
|
|
</div>
|
|
<span>{item.name[locale]}</span>
|
|
</button>
|
|
))
|
|
) : (
|
|
<div className={styles.noResult}>
|
|
{props.query.length < 3
|
|
? t('search.errors.type')
|
|
: t('search.errors.no_results_generic')}
|
|
</div>
|
|
)}
|
|
</div>
|
|
)
|
|
}
|
|
)
|
|
|
|
MentionList.displayName = 'MentionList'
|