Skip to content
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

"Fix code formatting issues and add translation language select component" #25

Merged
merged 1 commit into from
Jul 15, 2024

Conversation

ttizze
Copy link
Owner

@ttizze ttizze commented Jul 15, 2024

This pull request fixes code formatting issues in multiple files and adds a new component called TranslationLanguageSelect. The TranslationLanguageSelect component is a dropdown select menu that allows users to choose a translation language. It is used for selecting the target language for translation.

Summary by CodeRabbit

## リリースノート

### New Feature
- URL翻訳フォームに新しいコンポーネント `TranslationLanguageSelect` を追加し、ユーザーが翻訳言語を選択できるドロップダウンメニューを提供。

### Refactor
- コードフォーマットの修正と不要なインポート文の削除。
- エラーメッセージの日本語化。

### Style
- インデント調整、シングルクォートからダブルクォートへの変更、セミコロンの追加。

### Chore
- `@radix-ui/react-select` の依存関係を追加。
- リンター設定に `noUnusedImports` ルールを追加。

### Test
- テストコードのインポート整理とフォーマット修正。

Copy link

github-actions bot commented Jul 15, 2024

Image description CodeRabbit

以下は、指定された内容に基づく最終的な回答です。


ウォークスルー

この変更セットには、新しいコンポーネント TranslationLanguageSelect の追加、コードフォーマットの修正、インポート文の整理、およびエラーメッセージの日本語化が含まれています。これにより、ユーザーインターフェースの改善とコードの一貫性が向上します。

変更点

ファイル 要約
web/app/routes/components/URLTranslationForm.tsx 新しいコンポーネント TranslationLanguageSelect を追加し、フォームバリデーションと送信ロジックを実装。
web/app/routes/components/translatedList.tsx useLoaderDataのインポート位置を変更し、不要なインポート文を削除。
web/app/routes/reader.$encodedUrl/route.tsx コードフォーマット修正と TranslationLanguageSelect の追加。
web/app/utils.ts インポート文にセミコロンを追加し、cn関数内のコードフォーマットを修正。
web/app/utils/auth.server.ts, web/app/utils/session.server.ts, web/app/utils/signup.server.ts, web/app/utils/userReadHistory.ts, web/app/utils/userService.ts コードフォーマット修正、インデント調整、クォートの変更、セミコロンの追加、エラーメッセージの日本語化。
web/biome.json, web/components.json, web/package.json コードフォーマット修正、新しいコンポーネント TranslationLanguageSelect の追加、リンター設定の更新、依存関係の追加。
web/test/translation.test.ts インポートに関するコードフォーマットの修正と整理。


Uplevel your code reviews with CodeRabbit Pro

CodeRabbit Pro

If 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.

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Image description CodeRabbit

Commits Files that changed from the base of the PR and between 6436101 and 7ffcbae commits.
Files selected (34)
  • web/ tailwind.config.ts (1)
  • web/app/components/GoogleForm.tsx (1)
  • web/app/components/Header.tsx (1)
  • web/app/components/ui/alert.tsx (1)
  • web/app/components/ui/button.tsx (1)
  • web/app/components/ui/card.tsx (1)
  • web/app/components/ui/input.tsx (1)
  • web/app/components/ui/label.tsx (1)
  • web/app/components/ui/select.tsx (1)
  • web/app/components/ui/separator.tsx (1)
  • web/app/entry.server.tsx (6)
  • web/app/root.tsx (2)
  • web/app/routes/_index/route.tsx (4)
  • web/app/routes/_index/utils/gemini.ts (2)
  • web/app/routes/_index/utils/translation.ts (3)
  • web/app/routes/api.auth.callback.google.ts (1)
  • web/app/routes/auth.login.tsx (1)
  • web/app/routes/auth.logout.tsx (1)
  • web/app/routes/auth.signup.tsx (1)
  • web/app/routes/components/TranslationLanguageSelect.tsx (1)
  • web/app/routes/components/URLInputForm.tsx (1)
  • web/app/routes/components/URLTranslationForm.tsx (1)
  • web/app/routes/components/translatedList.tsx (2)
  • web/app/routes/reader.$encodedUrl/route.tsx (2)
  • web/app/utils.ts (1)
  • web/app/utils/auth.server.ts (1)
  • web/app/utils/session.server.ts (1)
  • web/app/utils/signup.server.ts (1)
  • web/app/utils/userReadHistory.ts (1)
  • web/app/utils/userService.ts (1)
  • web/biome.json (1)
  • web/components.json (1)
  • web/package.json (1)
  • web/test/translation.test.ts (1)
Files not summarized due to errors (1)
  • web/app/routes/auth.signup.tsx (diff tokens exceeds limit)
Files skipped from review due to trivial changes (22)
  • web/ tailwind.config.ts
  • web/app/components/GoogleForm.tsx
  • web/app/components/ui/alert.tsx
  • web/app/components/ui/button.tsx
  • web/app/components/ui/card.tsx
  • web/app/components/ui/input.tsx
  • web/app/components/ui/label.tsx
  • web/app/components/ui/separator.tsx
  • web/app/routes/_index/utils/translation.ts
  • web/app/routes/api.auth.callback.google.ts
  • web/app/routes/auth.logout.tsx
  • web/app/routes/components/translatedList.tsx
  • web/app/routes/reader.$encodedUrl/route.tsx
  • web/app/utils.ts
  • web/app/utils/auth.server.ts
  • web/app/utils/session.server.ts
  • web/app/utils/userReadHistory.ts
  • web/app/utils/userService.ts
  • web/components.json
  • web/test/translation.test.ts
  • web/app/routes/auth.login.tsx (diff too large)
  • web/app/routes/auth.signup.tsx (diff too large)
Review comments generated (22)
  • Review: 6
  • LGTM: 16

Tips

Chat with Image description CodeRabbit Bot (@coderabbitai)

  • Reply on review comments left by this bot to ask follow-up questions. A review comment is a comment on a diff or a file.
  • Invite the bot into a review comment chain by tagging @coderabbitai in a reply.

Code suggestions

  • The bot may make code suggestions, but please review them carefully before committing since the line number ranges may be misaligned.
  • You can edit the comment made by the bot and manually tweak the suggestion if it is slightly off.

Pausing incremental reviews

  • Add @coderabbitai: ignore anywhere in the PR description to pause further reviews from the bot.

Comment on lines 64 to +69
return (
<div className="container mx-auto max-w-2xl py-8">
<Card>
<Form method="post" {...getFormProps(form)} className="space-y-4">
<div className="flex space-x-2">
<Input
type="url"
name="url"
placeholder="URLを入力"
required
className="flex-grow"
/>
<Button
type="submit"
disabled={navigation.state === "submitting"}
>
{navigation.state === "submitting" ? "処理中..." : "翻訳を開始"}
</Button>
</div>
</Form>

{actionData?.result.status === "error" && (
<Alert variant="destructive" className="mt-4">
<AlertDescription>
<ul id={field.url.errorId}>
{field.url.errors}
</ul>
</AlertDescription>
</Alert>
)}

{actionData?.result.status === "success" && (
<div className="mt-4">
<Link
to={`/reader/${encodeURIComponent(actionData.url)}`}
className="text-blue-500 hover:underline"
>
<h2 className="text-xl font-semibold">{actionData.title}</h2>
</Link>
</div>
)}
</Card>
</div>
<Card>
<URLTranslationForm />
</Card>
</div>

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Image description CodeRabbit

useActionDatauseNavigationの削除により、フォームのバリデーションやエラーメッセージの表示が失われています。これらの機能を復元するために、以下の修正を提案します。

 export default function Index() {
-  	return (
-  		<div className="container mx-auto max-w-2xl py-8">
-  			<Card>
-  				<URLTranslationForm />
-  			</Card>
-  		</div>
+    const actionData = useActionData<typeof action>();
+    const navigation = useNavigation();
+
+    return (
+        <div className="container mx-auto max-w-2xl py-8">
+            <Card>
+                <Form method="post" className="space-y-4">
+                    <div className="flex space-x-2">
+                        <Input
+                            type="url"
+                            name="url"
+                            placeholder="URLを入力"
+                            required
+                            className="flex-grow"
+                        />
+                        <Button
+                            type="submit"
+                            disabled={navigation.state === "submitting"}
+                        >
+                            {navigation.state === "submitting" ? "処理中..." : "翻訳を開始"}
+                        </Button>
+                    </div>
+                </Form>
+                
+                {actionData?.result.status === "error" && (
+                    <Alert variant="destructive" className="mt-4">
+                        <AlertDescription>
+                            <ul>
+                                {actionData.result.errors.map((error, index) => (
+                                    <li key={index}>{error}</li>
+                                ))}
+                            </ul>
+                        </AlertDescription>
+                    </Alert>
+                )}
+                
+                {actionData?.result.status === "success" && (
+                    <div className="mt-4">
+                        <Link
+                            to={`/reader/${encodeURIComponent(actionData.url)}`}
+                            className="text-blue-500 hover:underline"
+                        >
+                            <h2 className="text-xl font-semibold">{actionData.title}</h2>
+                        </Link>
+                    </div>
+                )}
+            </Card>
+        </div>
 	);
 }

Comment on lines +35 to +37
className="text-blue-600 hover:text-blue-800 font-medium"
>

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Image description CodeRabbit

エラーメッセージの設定が適切に行われていない可能性があります。catchブロック内でerrorオブジェクトが必ずしもmessageプロパティを持つとは限らないため、エラーハンドリングを改善する必要があります。

-      setError(error.message);
+      setError(error instanceof Error ? error.message : "予期しないエラーが発生しました。");


export function URLTranslationForm() {
const navigation = useNavigation();
const [targetLanguage, setTargetLanguage] = useState("ja");

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Image description CodeRabbit

useStateの初期値としてハードコードされた言語コード "ja" を使用していますが、これをコンポーネントのプロパティとして受け取るようにすると、再利用性が向上します。

-	const [targetLanguage, setTargetLanguage] = useState("ja");
+	const [targetLanguage, setTargetLanguage] = useState(props.initialLanguage || "ja");

},
onSubmit(event, { formData }) {
event.preventDefault();
console.log("Form submitted", Object.fromEntries(formData));

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Image description CodeRabbit

デバッグ用の console.log は本番環境では不要です。削除するか、デバッグフラグで制御することを検討してください。

-			console.log("Form submitted", Object.fromEntries(formData));

Comment on lines +62 to +64
<Button type="submit" disabled={navigation.state === "submitting"}>
{navigation.state === "submitting" ? "翻訳中..." : "翻訳開始"}
</Button>

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Image description CodeRabbit

送信ボタンのテキストが動的に変わるのは良いですが、アクセシビリティの観点からも考慮し、ARIA属性を追加するとさらに良くなります。

-					<Button type="submit" disabled={navigation.state === "submitting"}>
+					<Button type="submit" disabled={navigation.state === "submitting"} aria-busy={navigation.state === "submitting"}>

Comment on lines 4 to 6
export const createUser = async (
data: Record<'name' | 'email' | 'password', string>,
data: Record<"name" | "email" | "password", string>,
) => {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Image description CodeRabbit

インデントが不適切です。関数宣言のインデントを修正してください。

export const createUser = async (
    data: Record<"name" | "email" | "password", string>,
) => {

@ttizze ttizze merged commit 368055e into main Jul 15, 2024
3 checks passed
@ttizze ttizze deleted the feature/component branch July 15, 2024 00:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

1 participant