Skip to content

Commit

Permalink
fix: Hide toolbar buttons until a translation is provided
Browse files Browse the repository at this point in the history
  • Loading branch information
neet committed Jan 18, 2025
1 parent 47a45ee commit e7dcc27
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 15 deletions.
4 changes: 2 additions & 2 deletions src/components/Composer/Composer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -224,8 +224,8 @@ export const Composer: FC<ComposerProps> = (props) => {
count={count}
pending={pending}
source={source}
ready={ready}
dirty={dirty}
hasTranslation={ready}
textareaRef={textareaRef}
onChangeSource={handleChangeSource}
onChangeText={handleChangeText}
Expand All @@ -239,8 +239,8 @@ export const Composer: FC<ComposerProps> = (props) => {
translationTranscription={translationTranscription}
dirty={dirty}
pending={pending}
ready={ready}
target={target}
hasTranslation={ready}
onChangeTarget={handleChangeTarget}
onPlayOutput={handlePlayOutput}
onCopy={handleCopy}
Expand Down
10 changes: 6 additions & 4 deletions src/components/Composer/ComposerInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export type ComposerInputProps = {
dialect?: string;
};
pending: boolean;
ready: boolean;
hasTranslation: boolean;
dirty: boolean;
textTranscription?: t.Transcription;
count: number;
Expand All @@ -47,7 +47,7 @@ export const ComposerInput: FC<ComposerInputProps> = (props) => {
const {
source,
defaultValues,
ready,
hasTranslation,
dirty,
pending,
textTranscription,
Expand Down Expand Up @@ -124,7 +124,7 @@ export const ComposerInput: FC<ComposerInputProps> = (props) => {
</Text>

<Transcription>
{!dirty && ready && textTranscription
{!dirty && hasTranslation && textTranscription
? textTranscription.text
: undefined}
</Transcription>
Expand All @@ -147,11 +147,13 @@ export const ComposerInput: FC<ComposerInputProps> = (props) => {
<Tooltip content={t("play")}>
<IconButton
variant="soft"
hidden={count <= 0}
size="2"
onClick={onPlayInput}
type="button"
title={t("play")}
style={{
visibility: count > 0 ? "visible" : "hidden",
}}
>
<FiVolume2 aria-hidden />
</IconButton>
Expand Down
24 changes: 15 additions & 9 deletions src/components/Composer/ComposerOutput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import { Transcription } from "./Transcription";
import { Translation } from "./Translation";

export type ComposerOutputProps = {
ready: boolean;
hasTranslation: boolean;
dirty: boolean;
target: string;
pending: boolean;
Expand All @@ -47,7 +47,7 @@ export type ComposerOutputProps = {

export const ComposerOutput: FC<ComposerOutputProps> = (props) => {
const {
ready,
hasTranslation,
dirty,
pending,
target,
Expand Down Expand Up @@ -104,7 +104,7 @@ export const ComposerOutput: FC<ComposerOutputProps> = (props) => {
</Text>

<Transcription>
{ready && translationTranscription
{hasTranslation && translationTranscription
? translationTranscription.text
: undefined}
</Transcription>
Expand All @@ -113,12 +113,14 @@ export const ComposerOutput: FC<ComposerOutputProps> = (props) => {
<Flex justify="between" mt="2">
<Tooltip content={t("play")}>
<IconButton
hidden={!ready}
type="button"
variant="soft"
size="2"
aria-label={t("play")}
onClick={onPlayOutput}
style={{
visibility: hasTranslation ? "visible" : "hidden",
}}
>
<FiVolume2 aria-hidden />
</IconButton>
Expand All @@ -127,25 +129,29 @@ export const ComposerOutput: FC<ComposerOutputProps> = (props) => {
<Flex justify="end" gap="1">
<Tooltip content={t("share")}>
<IconButton
hidden={!ready}
type="button"
variant="soft"
size="2"
aria-label={t("share")}
onClick={onShare}
style={{
visibility: hasTranslation ? "visible" : "hidden",
}}
>
<FiShare aria-hidden />
</IconButton>
</Tooltip>

<Tooltip content={t("copy")}>
<IconButton
hidden={!ready}
type="button"
variant="soft"
size="2"
aria-label={t("copy")}
onClick={onCopy}
style={{
visibility: hasTranslation ? "visible" : "hidden",
}}
>
<FiCopy aria-hidden />
</IconButton>
Expand Down Expand Up @@ -184,20 +190,20 @@ export const ComposerOutput: FC<ComposerOutputProps> = (props) => {
</Callout.Root>
)}

{ready && (
{hasTranslation && (
<Box>
<Disclaimer />
</Box>
)}
</Flex>

{ready && (
{hasTranslation && (
<ExampleSentences
exampleSentencesPromise={props.exampleSentencesPromise}
/>
)}

{ready && (
{hasTranslation && (
<AlternativeTranslations
alternativeTranslationsPromise={props.alternativeTranslationsPromise}
/>
Expand Down

0 comments on commit e7dcc27

Please sign in to comment.