-
Notifications
You must be signed in to change notification settings - Fork 2.4k
feat: Add shortcut hint to auto-approve dropdown #8849
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| import React from "react" | ||
| import { Trans } from "react-i18next" | ||
|
|
||
| import { useAppTranslation } from "@/i18n/TranslationContext" | ||
| import { usePlatform } from "@/hooks/usePlatform" | ||
|
|
||
| interface ShortcutHintProps { | ||
| translationKey: string | ||
| } | ||
|
|
||
| export const ShortcutHint: React.FC<ShortcutHintProps> = ({ translationKey }) => { | ||
| const { t } = useAppTranslation() | ||
| const platform = usePlatform() | ||
|
|
||
| const getShortcut = () => { | ||
| switch (platform) { | ||
| case "mac": | ||
| return "⌘⌥A" | ||
| case "windows": | ||
| case "linux": | ||
| return "Ctrl+Alt+A" | ||
| default: | ||
| return "" | ||
| } | ||
| } | ||
|
|
||
| const shortcut = getShortcut() | ||
|
|
||
| if (!shortcut) { | ||
| return null | ||
| } | ||
|
|
||
| return ( | ||
| <p className="m-0 text-xs text-vscode-descriptionForeground"> | ||
| <Trans | ||
| i18nKey={translationKey} | ||
| components={{ | ||
| shortcut: <code className="p-1 rounded bg-vscode-button-background">{shortcut}</code>, | ||
| }} | ||
| /> | ||
| </p> | ||
| ) | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| import { useState, useEffect } from "react" | ||
|
|
||
| type Platform = "mac" | "windows" | "linux" | "unknown" | ||
|
|
||
| export function usePlatform(): Platform { | ||
| const [platform, setPlatform] = useState<Platform>("unknown") | ||
|
|
||
| useEffect(() => { | ||
| const userAgent = window.navigator.userAgent.toLowerCase() | ||
| if (userAgent.includes("mac")) { | ||
| setPlatform("mac") | ||
| } else if (userAgent.includes("win")) { | ||
| setPlatform("windows") | ||
| } else if (userAgent.includes("linux")) { | ||
| setPlatform("linux") | ||
| } | ||
| }, []) | ||
|
Comment on lines
+5
to
+17
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The hook initializes platform state as "unknown" and updates it in useEffect, causing the component to render twice (first with "unknown", then with the actual platform). While this works in VSCode webviews, consider using |
||
|
|
||
| return platform | ||
| } | ||
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.
The
useAppTranslationhook is imported but never used. The component only uses theTranscomponent directly with thetranslationKeyprop. Consider removing this unused import to keep the code clean.