add image conver button
This commit is contained in:
@@ -14,7 +14,7 @@ interface initMessageBody {
|
|||||||
token?: string
|
token?: string
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function fileUpload(messageBody: initMessageBody) {
|
export async function fileUpload(messageBody: initMessageBody, needConvert: boolean | undefined) {
|
||||||
const token = await getSessionData('token');
|
const token = await getSessionData('token');
|
||||||
if (!token) {
|
if (!token) {
|
||||||
return;
|
return;
|
||||||
@@ -23,6 +23,9 @@ export async function fileUpload(messageBody: initMessageBody) {
|
|||||||
message.action = 'init';
|
message.action = 'init';
|
||||||
message.token = token;
|
message.token = token;
|
||||||
|
|
||||||
|
// нужно будет добавить свойство needConvert в тело запроса.
|
||||||
|
// console.log(needConvert);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await fetch(`${API_BASE_URL}/api/v1/data`, {
|
const response = await fetch(`${API_BASE_URL}/api/v1/data`, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
|
|||||||
@@ -695,7 +695,7 @@ export default function TanstakFilesTable({ fileType }: { fileType: string }) {
|
|||||||
</h3>
|
</h3>
|
||||||
<ModalWindow children={openWindowChildren} state={openWindow} callBack={setOpenWindow} />
|
<ModalWindow children={openWindowChildren} state={openWindow} callBack={setOpenWindow} />
|
||||||
{/* Фильтры */}
|
{/* Фильтры */}
|
||||||
<div className="tanstak-table-filtres" style={{ display: "none" }}>
|
<div className="tanstak-table-filtres">
|
||||||
<div className="table-filtres-wrapper">
|
<div className="table-filtres-wrapper">
|
||||||
<div className="table-filtres-item">
|
<div className="table-filtres-item">
|
||||||
<div className="table-filtres-label">{t('date-filter')}:</div>
|
<div className="table-filtres-label">{t('date-filter')}:</div>
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ interface SelectedFile {
|
|||||||
progress: number;
|
progress: number;
|
||||||
status: 'pending' | 'uploading' | 'completed' | 'error' | 'cancelled';
|
status: 'pending' | 'uploading' | 'completed' | 'error' | 'cancelled';
|
||||||
error?: string;
|
error?: string;
|
||||||
|
needConvert?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface FileUploadInitResponse {
|
interface FileUploadInitResponse {
|
||||||
@@ -238,7 +239,7 @@ export default function UploadSectionFile({
|
|||||||
file_size: fileInfo.file.size
|
file_size: fileInfo.file.size
|
||||||
};
|
};
|
||||||
|
|
||||||
const response = await fileUpload(initMessageBody) as FileUploadInitResponse;
|
const response = await fileUpload(initMessageBody, fileInfo.needConvert) as FileUploadInitResponse;
|
||||||
|
|
||||||
if (!response?.upload_id) {
|
if (!response?.upload_id) {
|
||||||
throw new Error('Failed to get upload_id');
|
throw new Error('Failed to get upload_id');
|
||||||
@@ -392,6 +393,18 @@ export default function UploadSectionFile({
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
function converButtonHandler(file: SelectedFile) {
|
||||||
|
setSelectedFiles(selectedFiles.map(selectedFile => {
|
||||||
|
if (selectedFile.name === file.name) {
|
||||||
|
return {
|
||||||
|
...selectedFile,
|
||||||
|
needConvert: !selectedFile.needConvert
|
||||||
|
};
|
||||||
|
}
|
||||||
|
return selectedFile;
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="upload-section" >
|
<div className="upload-section" >
|
||||||
@@ -529,34 +542,54 @@ export default function UploadSectionFile({
|
|||||||
}
|
}
|
||||||
</div>
|
</div>
|
||||||
<div className="selected-file-right-block">
|
<div className="selected-file-right-block">
|
||||||
<span className={
|
{
|
||||||
`upload-progress ${file.status === 'completed' ? 'text-green-600' :
|
(fileType === 'image' && file.status === 'pending') && (
|
||||||
file.status === 'uploading' ? 'text-blue-600' :
|
<button
|
||||||
'text-gray-600'
|
className={`btn-convert ${file.needConvert ? 'active' : ''}`}
|
||||||
}`
|
onClick={() => {
|
||||||
}>
|
converButtonHandler(file);
|
||||||
{file.progress} %
|
}}
|
||||||
</span>
|
>
|
||||||
< button
|
{t('convert-image')} jpg
|
||||||
className="btn btn-cancel"
|
</button>
|
||||||
onClick={() => handleClearFile(file.uploadId || file.name)}
|
)
|
||||||
type="button"
|
}
|
||||||
>
|
<div>
|
||||||
{t('remove')}
|
<span className={
|
||||||
</button>
|
`upload-progress ${file.status === 'completed' ? 'text-green-600' :
|
||||||
|
file.status === 'uploading' ? 'text-blue-600' :
|
||||||
|
'text-gray-600'
|
||||||
|
}`
|
||||||
|
}>
|
||||||
|
{file.progress} %
|
||||||
|
</span>
|
||||||
|
< button
|
||||||
|
className="btn btn-cancel"
|
||||||
|
onClick={() => handleClearFile(file.uploadId || file.name)}
|
||||||
|
type="button"
|
||||||
|
>
|
||||||
|
{t('remove')}
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{
|
{
|
||||||
(fileType === 'image' && file.preview) && (
|
(fileType === 'image' && file.preview) && (
|
||||||
<img
|
<div
|
||||||
src={file.preview}
|
className="image-preview-wrapper"
|
||||||
alt="Предпросмотр загруженного изображения"
|
>
|
||||||
className="uploaded-image"
|
<img
|
||||||
onError={() => setError('Не удалось загрузить превью изображения')
|
src={file.preview}
|
||||||
}
|
alt="Предпросмотр загруженного изображения"
|
||||||
/>
|
className="uploaded-image"
|
||||||
)}
|
onError={() => setError('Не удалось загрузить превью изображения')
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
file.status === 'pending' && (
|
file.status === 'pending' && (
|
||||||
|
|||||||
@@ -410,6 +410,25 @@
|
|||||||
border: 1px solid #d1d5db;
|
border: 1px solid #d1d5db;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.btn-convert {
|
||||||
|
background: v.$white;
|
||||||
|
color: v.$p-color;
|
||||||
|
border: 2px solid v.$p-color;
|
||||||
|
padding: 5px 15px;
|
||||||
|
border-radius: 12px;
|
||||||
|
cursor: pointer;
|
||||||
|
font-weight: 600;
|
||||||
|
font-size: 16px;
|
||||||
|
transition: 0.3s;
|
||||||
|
min-width: 120px;
|
||||||
|
|
||||||
|
&.active {
|
||||||
|
background: #00a63e;
|
||||||
|
border: 2px solid #00a63e;
|
||||||
|
color: v.$white;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
.btn-confirm {
|
.btn-confirm {
|
||||||
background: linear-gradient(45deg, v.$p-color 50%, v.$s-color 100%);
|
background: linear-gradient(45deg, v.$p-color 50%, v.$s-color 100%);
|
||||||
color: v.$white;
|
color: v.$white;
|
||||||
@@ -469,7 +488,10 @@
|
|||||||
|
|
||||||
.selected-file-right-block {
|
.selected-file-right-block {
|
||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
flex-direction: column;
|
||||||
|
gap: 10px;
|
||||||
|
align-items: end;
|
||||||
|
/* align-items: center; */
|
||||||
|
|
||||||
@media (max-width: 500px) {
|
@media (max-width: 500px) {
|
||||||
flex-direction: column-reverse;
|
flex-direction: column-reverse;
|
||||||
|
|||||||
@@ -225,7 +225,8 @@
|
|||||||
"pending": "Pending",
|
"pending": "Pending",
|
||||||
"all-content": "All content",
|
"all-content": "All content",
|
||||||
"monitoring": "Monitoring",
|
"monitoring": "Monitoring",
|
||||||
"efficiency": "Efficiency"
|
"efficiency": "Efficiency",
|
||||||
|
"convert-image": "Convert image to"
|
||||||
},
|
},
|
||||||
"Login-register-form": {
|
"Login-register-form": {
|
||||||
"and": "and",
|
"and": "and",
|
||||||
|
|||||||
@@ -163,7 +163,7 @@
|
|||||||
"you-sure-you-want-to-delete": "Уверены, что хотите удалить?",
|
"you-sure-you-want-to-delete": "Уверены, что хотите удалить?",
|
||||||
"reports-and-analytics": "Отчёты и аналитика",
|
"reports-and-analytics": "Отчёты и аналитика",
|
||||||
"file-has-been-deleted": "Файл удален",
|
"file-has-been-deleted": "Файл удален",
|
||||||
"error": "Ошбка",
|
"error": "Ошибка",
|
||||||
"failed-to-download-file": "Не удалось скачать файл",
|
"failed-to-download-file": "Не удалось скачать файл",
|
||||||
"file-is-downloading": "Скачивается файл",
|
"file-is-downloading": "Скачивается файл",
|
||||||
"status": "статус",
|
"status": "статус",
|
||||||
@@ -225,7 +225,8 @@
|
|||||||
"pending": "В ожидании",
|
"pending": "В ожидании",
|
||||||
"all-content": "Весь контент",
|
"all-content": "Весь контент",
|
||||||
"monitoring": "Мониторинг",
|
"monitoring": "Мониторинг",
|
||||||
"efficiency": "Эффективность"
|
"efficiency": "Эффективность",
|
||||||
|
"convert-image": "Конвертировать изображение в"
|
||||||
},
|
},
|
||||||
"Login-register-form": {
|
"Login-register-form": {
|
||||||
"and": "и",
|
"and": "и",
|
||||||
|
|||||||
Reference in New Issue
Block a user