2023-09-28 10:48:32 +03:00
|
|
|
import { Menu, MenuItem } from '@szhsin/react-menu';
|
|
|
|
import { useState } from 'preact/hooks';
|
2023-10-01 09:39:44 +03:00
|
|
|
import { useSnapshot } from 'valtio';
|
|
|
|
|
|
|
|
import getTranslateTargetLanguage from '../utils/get-translate-target-language';
|
|
|
|
import localeMatch from '../utils/locale-match';
|
|
|
|
import states from '../utils/states';
|
2023-09-28 10:48:32 +03:00
|
|
|
|
|
|
|
import Icon from './icon';
|
2023-11-18 16:11:07 +03:00
|
|
|
import Menu2 from './menu2';
|
2023-09-28 10:48:32 +03:00
|
|
|
import TranslationBlock from './translation-block';
|
|
|
|
|
2023-09-30 18:23:34 +03:00
|
|
|
export default function MediaAltModal({ alt, lang, onClose }) {
|
2023-10-01 09:39:44 +03:00
|
|
|
const snapStates = useSnapshot(states);
|
2023-09-28 10:48:32 +03:00
|
|
|
const [forceTranslate, setForceTranslate] = useState(false);
|
2023-10-01 09:39:44 +03:00
|
|
|
const targetLanguage = getTranslateTargetLanguage(true);
|
|
|
|
const contentTranslationHideLanguages =
|
|
|
|
snapStates.settings.contentTranslationHideLanguages || [];
|
|
|
|
const differentLanguage =
|
|
|
|
!!lang &&
|
|
|
|
lang !== targetLanguage &&
|
|
|
|
!localeMatch([lang], [targetLanguage]) &&
|
|
|
|
!contentTranslationHideLanguages.find(
|
|
|
|
(l) => lang === l || localeMatch([lang], [l]),
|
|
|
|
);
|
|
|
|
|
2023-09-28 10:48:32 +03:00
|
|
|
return (
|
2023-10-25 21:18:39 +03:00
|
|
|
<div class="sheet" tabindex="-1">
|
2023-09-28 10:48:32 +03:00
|
|
|
{!!onClose && (
|
|
|
|
<button type="button" class="sheet-close outer" onClick={onClose}>
|
|
|
|
<Icon icon="x" />
|
|
|
|
</button>
|
|
|
|
)}
|
|
|
|
<header class="header-grid">
|
|
|
|
<h2>Media description</h2>
|
|
|
|
<div class="header-side">
|
2023-11-18 16:11:07 +03:00
|
|
|
<Menu2
|
2023-09-28 10:48:32 +03:00
|
|
|
align="end"
|
|
|
|
menuButton={
|
|
|
|
<button type="button" class="plain4">
|
|
|
|
<Icon icon="more" alt="More" size="xl" />
|
|
|
|
</button>
|
|
|
|
}
|
|
|
|
>
|
|
|
|
<MenuItem
|
|
|
|
disabled={forceTranslate}
|
|
|
|
onClick={() => {
|
|
|
|
setForceTranslate(true);
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
<Icon icon="translate" />
|
|
|
|
<span>Translate</span>
|
|
|
|
</MenuItem>
|
2023-11-18 16:11:07 +03:00
|
|
|
</Menu2>
|
2023-09-28 10:48:32 +03:00
|
|
|
</div>
|
|
|
|
</header>
|
2023-09-30 18:23:34 +03:00
|
|
|
<main lang={lang} dir="auto">
|
2023-09-28 10:48:32 +03:00
|
|
|
<p
|
|
|
|
style={{
|
|
|
|
whiteSpace: 'pre-wrap',
|
2023-11-02 08:00:07 +03:00
|
|
|
textWrap: 'pretty',
|
2023-09-28 10:48:32 +03:00
|
|
|
}}
|
|
|
|
>
|
|
|
|
{alt}
|
|
|
|
</p>
|
2023-10-01 09:39:44 +03:00
|
|
|
{(differentLanguage || forceTranslate) && (
|
|
|
|
<TranslationBlock
|
|
|
|
forceTranslate={forceTranslate}
|
|
|
|
sourceLanguage={lang}
|
|
|
|
text={alt}
|
|
|
|
/>
|
2023-09-28 10:48:32 +03:00
|
|
|
)}
|
|
|
|
</main>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|