-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
翻訳コンポーネントをホバーじゃなくクリックに #117
Conversation
This PR is linked to issue #113 |
### ウォークスルー
この変更は、翻訳コンポーネントのユーザーインターフェースを改善し、クリックイベントに基づく表示ロジックを導入することを目的としています。また、不要なアイコンやテキストの削除、エラーメッセージのスタイル調整、関数のリファクタリングも行われています。
### 変更点
| ファイル | 要約 |
| --- | --- |
| .github/scripts/determine-issue-type.sh | `.github/issue-type-config.json`を使用してIssueタイトルに基づいてラベルを決定するスクリプトを削除。 |
| web/app/routes/reader.$encodedUrl/components/AddAndVoteTranslations.tsx, web/app/routes/reader.$encodedUrl/components/Translation.tsx | 翻訳コンポーネントのホバーからクリックへの変更、アイコン追加、表示状態切り替えロジック実装。 |
| web/app/routes/reader.$encodedUrl/components/AddTranslationForm.tsx | エラーメッセージのテキストにCSSクラス`text-sm`を追加。 |
| web/app/routes/reader.$encodedUrl/components/TranslationItem.tsx | `sanitizeAndParseText`関数のインポートパスを変更。 |
| web/app/routes/reader.$encodedUrl/functions/get-best-translation.client.ts | `getBestTranslation`関数を追加し、最適な翻訳を選択するロジックを実装。 | Uplevel your code reviews with CodeRabbit ProCodeRabbit ProIf you like this project, please support us by purchasing the Pro version. The Pro version has advanced context, superior noise reduction and several proprietary improvements compared to the open source version. Moreover, CodeRabbit Pro is free for open source projects. |
export function getBestTranslation( | ||
translationsWithVotes: TranslationWithVote[], | ||
): TranslationWithVote { | ||
const upvotedTranslations = translationsWithVotes.filter( | ||
(t) => t.userVote?.isUpvote, | ||
); | ||
if (upvotedTranslations.length > 0) { | ||
return upvotedTranslations.reduce((prev, current) => { | ||
const currentUpdatedAt = current.userVote?.updatedAt ?? new Date(0); | ||
const prevUpdatedAt = prev.userVote?.updatedAt ?? new Date(0); | ||
return currentUpdatedAt > prevUpdatedAt ? current : prev; | ||
}); | ||
} | ||
return translationsWithVotes.reduce((prev, current) => | ||
prev.point > current.point ? prev : current, | ||
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@@ -33,7 +37,7 @@ export function Translation({ | |||
userId, | |||
sourceTextId, | |||
}: TranslationProps) { | |||
const [isHovered, setIsHovered] = useState(false); | |||
const [isExpanded, setIsExpanded] = useState(false); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
<div className="group relative"> | ||
<div className="w-full notranslate mt-2 pt-2 border-t border-gray-200"> | ||
{sanitizedAndParsedText} | ||
<ToggleButton | ||
isExpanded={isExpanded} | ||
onClick={() => setIsExpanded(!isExpanded)} | ||
/> | ||
</div> | ||
<div className="absolute top-0 left-0 right-0 z-10 opacity-0 invisible border bg-white dark:bg-gray-900 rounded-xl shadow-xl dark:shadow-white/10 group-hover:opacity-100 group-hover:visible transition-all duration-500 ease-in-out"> | ||
{isHovered && ( | ||
{isExpanded && ( | ||
<div className="absolute top-0 left-0 right-0 z-10 border bg-white dark:bg-gray-900 rounded-xl shadow-xl dark:shadow-white/10 transition-all duration-500 ease-in-out"> | ||
<AddAndVoteTranslations | ||
bestTranslationWithVote={bestTranslationWithVote} | ||
alternativeTranslationsWithVotes={alternativeTranslationsWithVotes} | ||
userId={userId} | ||
sourceTextId={sourceTextId} | ||
/> | ||
)} | ||
</div> | ||
</div> | ||
)} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
alternativeTranslationsWithVotes
が定義されていないため、エラーが発生します。以下のように修正してください。
<div className="absolute top-0 left-0 right-0 z-10 border bg-white dark:bg-gray-900 rounded-xl shadow-xl dark:shadow-white/10 transition-all duration-500 ease-in-out">
<AddAndVoteTranslations
bestTranslationWithVote={bestTranslationWithVote}
- alternativeTranslationsWithVotes={alternativeTranslationsWithVotes}
+ alternativeTranslationsWithVotes={translationsWithVotes.filter(t => t !== bestTranslationWithVote)}
userId={userId}
sourceTextId={sourceTextId}
/>
</div>
Alternative | ||
</p> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Closes #113
Summary by CodeRabbit