6.6.0: Извлечение ссылки из текста в желании
All checks were successful
Build and Push Docker Image / build-and-push (push) Successful in 1m5s
All checks were successful
Build and Push Docker Image / build-and-push (push) Successful in 1m5s
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "play-life-web",
|
"name": "play-life-web",
|
||||||
"version": "6.5.0",
|
"version": "6.6.0",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "vite",
|
"dev": "vite",
|
||||||
|
|||||||
@@ -4,6 +4,13 @@ import { useAuth } from './auth/AuthContext'
|
|||||||
import Toast from './Toast'
|
import Toast from './Toast'
|
||||||
import './WishlistForm.css'
|
import './WishlistForm.css'
|
||||||
|
|
||||||
|
// Извлекает первый URL из текста
|
||||||
|
function extractUrl(text) {
|
||||||
|
if (!text) return ''
|
||||||
|
const match = text.match(/https?:\/\/[^\s<>"'`,;!)\]]+/i)
|
||||||
|
return match ? match[0] : text
|
||||||
|
}
|
||||||
|
|
||||||
const API_URL = '/api/wishlist'
|
const API_URL = '/api/wishlist'
|
||||||
const TASKS_API_URL = '/api/tasks'
|
const TASKS_API_URL = '/api/tasks'
|
||||||
const PROJECTS_API_URL = '/projects'
|
const PROJECTS_API_URL = '/projects'
|
||||||
@@ -359,15 +366,18 @@ function WishlistForm({ onNavigate, wishlistId, editConditionIndex, newTaskId: n
|
|||||||
setToastMessage({ text: 'Введите ссылку', type: 'error' })
|
setToastMessage({ text: 'Введите ссылку', type: 'error' })
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const extracted = extractUrl(link)
|
||||||
|
setLink(extracted)
|
||||||
|
|
||||||
// Проверяем валидность URL
|
// Проверяем валидность URL
|
||||||
try {
|
try {
|
||||||
new URL(link)
|
new URL(extracted)
|
||||||
} catch {
|
} catch {
|
||||||
setToastMessage({ text: 'Некорректная ссылка', type: 'error' })
|
setToastMessage({ text: 'Некорректная ссылка', type: 'error' })
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
setFetchingMetadata(true)
|
setFetchingMetadata(true)
|
||||||
try {
|
try {
|
||||||
const response = await authFetch(`${API_URL}/metadata`, {
|
const response = await authFetch(`${API_URL}/metadata`, {
|
||||||
@@ -375,7 +385,7 @@ function WishlistForm({ onNavigate, wishlistId, editConditionIndex, newTaskId: n
|
|||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
},
|
},
|
||||||
body: JSON.stringify({ url: link.trim() }),
|
body: JSON.stringify({ url: extracted.trim() }),
|
||||||
})
|
})
|
||||||
|
|
||||||
if (response.ok) {
|
if (response.ok) {
|
||||||
@@ -477,7 +487,9 @@ function WishlistForm({ onNavigate, wishlistId, editConditionIndex, newTaskId: n
|
|||||||
|
|
||||||
// Загрузка картинки по ссылке с последующим кропом
|
// Загрузка картинки по ссылке с последующим кропом
|
||||||
const loadImageFromUrl = async () => {
|
const loadImageFromUrl = async () => {
|
||||||
const url = imageUrlInput?.trim()
|
const extracted = extractUrl(imageUrlInput)
|
||||||
|
setImageUrlInput(extracted)
|
||||||
|
const url = extracted?.trim()
|
||||||
if (!url) {
|
if (!url) {
|
||||||
setToastMessage({ text: 'Введите ссылку на картинку', type: 'error' })
|
setToastMessage({ text: 'Введите ссылку на картинку', type: 'error' })
|
||||||
return
|
return
|
||||||
@@ -800,9 +812,10 @@ function WishlistForm({ onNavigate, wishlistId, editConditionIndex, newTaskId: n
|
|||||||
<div className="link-input-wrapper">
|
<div className="link-input-wrapper">
|
||||||
<input
|
<input
|
||||||
id="link"
|
id="link"
|
||||||
type="url"
|
type="text"
|
||||||
value={link}
|
value={link}
|
||||||
onChange={(e) => setLink(e.target.value)}
|
onChange={(e) => setLink(e.target.value)}
|
||||||
|
onBlur={() => setLink(extractUrl(link))}
|
||||||
placeholder="https://..."
|
placeholder="https://..."
|
||||||
className="form-input"
|
className="form-input"
|
||||||
disabled={fetchingMetadata}
|
disabled={fetchingMetadata}
|
||||||
@@ -907,9 +920,10 @@ function WishlistForm({ onNavigate, wishlistId, editConditionIndex, newTaskId: n
|
|||||||
<div className="image-url-row">
|
<div className="image-url-row">
|
||||||
<span className="image-url-label">Ссылка:</span>
|
<span className="image-url-label">Ссылка:</span>
|
||||||
<input
|
<input
|
||||||
type="url"
|
type="text"
|
||||||
value={imageUrlInput}
|
value={imageUrlInput}
|
||||||
onChange={(e) => setImageUrlInput(e.target.value)}
|
onChange={(e) => setImageUrlInput(e.target.value)}
|
||||||
|
onBlur={() => setImageUrlInput(extractUrl(imageUrlInput))}
|
||||||
placeholder="https://..."
|
placeholder="https://..."
|
||||||
className="form-input image-url-input"
|
className="form-input image-url-input"
|
||||||
disabled={loadingImageFromUrl}
|
disabled={loadingImageFromUrl}
|
||||||
|
|||||||
Reference in New Issue
Block a user