-
Notifications
You must be signed in to change notification settings - Fork 3.3k
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
[Google translate] Add a preference for the default action #12078
Merged
pernielsentikaer
merged 10 commits into
raycast:main
from
Popalay:google-translate-default-action
May 2, 2024
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
6bfd2e5
Add a preference for the default action in Google Translate extension
Popalay d4470f0
refactoring
gebeto be6daa0
add missing sections
gebeto f62772f
remove unused keys
gebeto 68d523d
fix logic
gebeto c8f5b65
remove extra comment
gebeto d76ada2
remove keys
gebeto 4c4d0d3
update configurable actions name
gebeto 1b91d6b
Merge pull request #1 from gebeto/google-translate-default-action-ref…
Popalay 0c64e0d
Use generated ExtensionPreferences.
Popalay File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import React from "react"; | ||
import { Action, getPreferenceValues } from "@raycast/api"; | ||
|
||
interface ActionsOpts { | ||
value: string; | ||
defaultActionsPrefix?: string; | ||
} | ||
|
||
export const ConfigurableCopyPasteActions = ({ defaultActionsPrefix, value }: ActionsOpts) => { | ||
const defaultPreference = getPreferenceValues<ExtensionPreferences>().defaultAction; | ||
|
||
const pasteAction = ( | ||
<Action.Paste title={defaultActionsPrefix ? `Paste ${defaultActionsPrefix}` : `Paste`} content={value} /> | ||
); | ||
const copyAction = ( | ||
<Action.CopyToClipboard title={defaultActionsPrefix ? `Copy ${defaultActionsPrefix}` : `Copy`} content={value} /> | ||
); | ||
|
||
if (defaultPreference === "paste") { | ||
return ( | ||
<> | ||
{pasteAction} | ||
{copyAction} | ||
</> | ||
); | ||
} | ||
|
||
return ( | ||
<> | ||
{copyAction} | ||
{pasteAction} | ||
</> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
@gebeto Just curious why it's needed here?
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.
<></>
is a shorthand for<React.Fragment></React.Fragment>
, when we are assigning thekey
, we need to useReact.Fragment
, because we can't do<key={index}>
we need a
key
right on fragment here because it is an element that we are returning from themap
. Key was used on nested elements before, and you could see an error in the console:More details about
key
you can get in official react docs here: https://react.dev/learn/rendering-listsAnd here is also more details about
Fragments
andkeys
: https://react.dev/reference/react/Fragment#rendering-a-list-of-fragmentslong story short -
key
should be applied to the root element which is returning from themap
, in this case it is a Fragment