Desktop: drag and drop profile photo; share drop-zone hook with post form

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
SlimusMinus
2026-10-26 23:27:40 +03:00
parent abd6f83535
commit 16b886081b
9 changed files with 209 additions and 45 deletions

View File

@@ -24,15 +24,24 @@ function ImageUpload({
fileInputRef,
onFileChange,
onRemove,
// Перетаскивание фото (десктоп): обработчики зоны и «файл над зоной».
// Пустые props — перетаскивание выключено (мобильная раскладка).
dropZoneProps = {},
dragOver = false,
}) {
const { t } = useTranslation();
const dropEnabled = Object.keys(dropZoneProps).length > 0;
return (
<div className="f-m-group">
<div
className={`f-m-group${dropEnabled ? " f-img-drop-zone" : ""}${dragOver ? " is-dragover" : ""}`}
{...dropZoneProps}
>
<label className="f-m-label">{t('profile.photoLabel')}</label>
{displayImage ? (
<div className="f-img-preview-wrap">
<img src={displayImage} alt="profile" className="f-img-preview" />
{dragOver && <span className="f-img-drop-overlay">{t('profile.dropReplace')}</span>}
<button
className="f-img-remove"
onClick={onRemove}
@@ -52,7 +61,16 @@ function ImageUpload({
className="f-img-input"
disabled={compressing}
/>
{compressing ? <span>{t('profile.processing')}</span> : <span>{t('profile.addPhoto')}</span>}
{compressing ? (
<span>{t('profile.processing')}</span>
) : dragOver ? (
<span>{t('profile.dropRelease')}</span>
) : (
<span className="f-img-upload-text">
<span>{t('profile.addPhoto')}</span>
{dropEnabled && <span className="f-img-upload-sub">{t('profile.dropHint')}</span>}
</span>
)}
</label>
)}
{imgError && <p className="f-err-msg">{imgError}</p>}