hensei-web/components/uncap/TranscendencePopover/index.tsx
Justin Edmund 3d67622353
Fix i18n migration to next-intl (#430)
## 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>
2025-09-03 16:25:59 -07:00

116 lines
2.9 KiB
TypeScript

import React, { PropsWithChildren, useEffect, useState } from 'react'
import { useTranslations } from 'next-intl'
import classNames from 'classnames'
import { Popover } from '@radix-ui/react-popover'
import {
PopoverAnchor,
PopoverContent,
} from '~components/common/PopoverContent'
import TranscendenceStar from '~components/uncap/TranscendenceStar'
import styles from './index.module.scss'
interface Props
extends React.DetailedHTMLProps<
React.DialogHTMLAttributes<HTMLDivElement>,
HTMLDivElement
> {
type: 'character' | 'summon' | 'weapon'
starRef: React.RefObject<HTMLDivElement>
open: boolean
stage: number
onOpenChange?: (open: boolean) => void
sendValue?: (stage: number) => void
}
const TranscendencePopover = ({
open: popoverOpen,
starRef,
children,
type,
stage,
tabIndex,
onOpenChange,
sendValue,
}: PropsWithChildren<Props>) => {
const t = useTranslations('common')
const [open, setOpen] = useState(false)
const [baseLevel, setBaseLevel] = useState(0)
const [currentStage, setCurrentStage] = useState(0)
const popoverRef = React.createRef<HTMLDivElement>()
const levelClasses = classNames({
[styles.pending]: stage != currentStage,
})
useEffect(() => {
setOpen(popoverOpen)
}, [popoverOpen])
useEffect(() => {
if (stage) setCurrentStage(stage)
}, [stage])
useEffect(() => {
if (type === 'character') setBaseLevel(100)
else if (['weapon', 'summon'].includes(type)) setBaseLevel(200)
}, [type])
function handleFragmentClicked(newStage: number) {
setCurrentStage(newStage)
if (sendValue) sendValue(newStage)
}
function handleFragmentHovered(newStage: number) {
setCurrentStage(newStage)
}
function closePopover() {
setOpen(false)
if (onOpenChange) onOpenChange(false)
}
function handlePointerDownOutside(
event: CustomEvent<{ originalEvent: PointerEvent }>
) {
const target = event.detail.originalEvent.target as Element
if (
target &&
starRef.current &&
target.closest('.TranscendenceStar') !== starRef.current
) {
closePopover()
}
}
return (
<Popover open={open}>
<PopoverAnchor>{children}</PopoverAnchor>
<PopoverContent
className="transcendence"
ref={popoverRef}
tabIndex={tabIndex}
onEscapeKeyDown={closePopover}
onPointerDownOutside={handlePointerDownOutside}
>
<TranscendenceStar
className="interactive base"
editable={true}
interactive={true}
stage={stage}
onFragmentClick={handleFragmentClicked}
onFragmentHover={handleFragmentHovered}
/>
<h4 className="name">
<span>{t('level')}&nbsp;</span>
<span className={levelClasses}>{baseLevel + 10 * currentStage}</span>
</h4>
</PopoverContent>
</Popover>
)
}
export default TranscendencePopover