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

display translate button outside of the menu if detected content lang… #390

Merged
merged 3 commits into from
Aug 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions frontend/src/Components/CommentComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {useInterpreter} from '../API/use/useInterpreter';
import OutsideClickHandler from 'react-outside-click-handler';
import {AltTranslateButton, AnnotateButton, TranslateButton} from './ContentButtons';
import {InviewContext} from '../Pages/PostPage';
import {getPreferredLang, getShowInlineTranslateButton} from './UserProfileSettings';

interface CommentProps {
comment: CommentInfo;
Expand Down Expand Up @@ -135,7 +136,7 @@ interface ControlsProps {
setAltContent: (value: string | undefined) => void;
}

function Controls({contentRef, comment, setEditingText, hideRating, onEdit, onAnswer, answerOpen, setAnswerOpen, setAltContent}: ControlsProps) {
function Controls({contentRef, comment, setEditingText, hideRating, onEdit, onAnswer, answerOpen, setAnswerOpen, setAltContent: setCommentAltContent}: ControlsProps) {
const api = useAPI();

const handleVote = useMemo(() => {
Expand Down Expand Up @@ -168,7 +169,10 @@ function Controls({contentRef, comment, setEditingText, hideRating, onEdit, onAn
e.preventDefault();
setAnswerOpen(!answerOpen);
};
useEffect(() => setAltContent(altContent), [altContent]);
useEffect(() => setCommentAltContent(altContent), [setCommentAltContent, altContent]);
const showTranslateButtonInline = useMemo(() => {
return getShowInlineTranslateButton() && comment.language !== getPreferredLang();
}, [comment]);

return (
<div className={styles.controls}>
Expand All @@ -179,9 +183,9 @@ function Controls({contentRef, comment, setEditingText, hideRating, onEdit, onAn
{comment.canEdit && onEdit && <div className={styles.control}><button onClick={handleEdit} className='i i-edit' /></div>}

<div className={styles.control + ' ' + postStyles.options}>
{currentMode === 'translate' &&
{(showTranslateButtonInline || currentMode === 'translate') &&
<div className={styles.control}>
<TranslateButton iconOnly={true} isActive={true} inProgress={inProgress} onClick={translate} />
<TranslateButton iconOnly={true} isActive={currentMode === 'translate'} inProgress={inProgress} onClick={translate} />
</div>}
{currentMode === 'altTranslate' &&
<div className={styles.control}>
Expand All @@ -196,7 +200,7 @@ function Controls({contentRef, comment, setEditingText, hideRating, onEdit, onAn
{showOptions &&
<OutsideClickHandler onOutsideClick={() => setShowOptions(false)}>
<div className={postStyles.optionsList}>
<TranslateButton inProgress={inProgress} onClick={() => {setShowOptions(false);translate();}} isActive={currentMode === 'translate'} />
{!showTranslateButtonInline && <TranslateButton inProgress={inProgress} onClick={() => {setShowOptions(false);translate();}} isActive={currentMode === 'translate'} />}
{calcShowAltTranslate() &&
<AltTranslateButton inProgress={inProgress} onClick={() => {setShowOptions(false);altTranslate();}} isActive={currentMode === 'altTranslate'}/>}
{calcShowAnnotate() &&
Expand Down
10 changes: 7 additions & 3 deletions frontend/src/Components/PostComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {SignatureComponent} from './SignatureComponent';
import Conf from '../Conf';
import {useInterpreter} from '../API/use/useInterpreter';
import {AltTranslateButton, AnnotateButton, TranslateButton, UnwatchButton, WatchButton} from './ContentButtons';
import {getPreferredLang, getShowInlineTranslateButton} from './UserProfileSettings';

interface PostComponentProps {
post: PostInfo;
Expand Down Expand Up @@ -135,6 +136,9 @@ export default function PostComponent(props: PostComponentProps) {

const altMode = currentMode !== undefined || inProgress;
const autoCut = altMode ? undefined : props.autoCut;
const showTranslateButtonInline = useMemo(() => {
return getShowInlineTranslateButton() && props.post.language !== getPreferredLang();
}, [props.post]);

return (
<div className={'postComponent ' + styles.post} ref={contentRef}>
Expand Down Expand Up @@ -172,9 +176,9 @@ export default function PostComponent(props: PostComponentProps) {
{/*<div className={styles.control}><button disabled={true} onClick={toggleBookmark} className={bookmark ? styles.active : ''}><BookmarkIcon /><span className={styles.label}></span></button></div>*/}
{props.post.canEdit && props.onEdit && <div className={styles.control}><button onClick={handleEdit}><EditIcon /></button></div>}
<div className={styles.control + ' ' + styles.options}>
{currentMode === 'translate' &&
{(showTranslateButtonInline || currentMode === 'translate') &&
<div className={styles.control}>
<TranslateButton iconOnly={true} isActive={true} inProgress={inProgress} onClick={translate}/>
<TranslateButton iconOnly={true} isActive={currentMode === 'translate'} inProgress={inProgress} onClick={translate}/>
</div>}
{currentMode === 'altTranslate' &&
<div className={styles.control}>
Expand All @@ -189,7 +193,7 @@ export default function PostComponent(props: PostComponentProps) {
{showOptions &&
<OutsideClickHandler onOutsideClick={() => setShowOptions(false)}>
<div className={styles.optionsList}>
<TranslateButton className={styles.control} inProgress={inProgress} onClick={() => {setShowOptions(false);translate();}} isActive={currentMode === 'translate'} />
{!showTranslateButtonInline && <TranslateButton className={styles.control} inProgress={inProgress} onClick={() => {setShowOptions(false);translate();}} isActive={currentMode === 'translate'} />}
{calcShowAltTranslate() &&
<AltTranslateButton className={styles.control} inProgress={inProgress} onClick={() => {setShowOptions(false);altTranslate();}} isActive={currentMode === 'altTranslate'}/>}
{calcShowAnnotate() &&
Expand Down
Loading
Loading