2026-01-13 20:55:44 +03:00
|
|
|
|
import React, { useState, useEffect, useRef } from 'react'
|
2026-01-11 21:12:26 +03:00
|
|
|
|
import { useAuth } from './auth/AuthContext'
|
|
|
|
|
|
import LoadingError from './LoadingError'
|
|
|
|
|
|
import './Wishlist.css'
|
|
|
|
|
|
|
|
|
|
|
|
const API_URL = '/api/wishlist'
|
2026-01-13 20:55:44 +03:00
|
|
|
|
const CACHE_KEY = 'wishlist_cache'
|
|
|
|
|
|
const CACHE_COMPLETED_KEY = 'wishlist_completed_cache'
|
2026-01-11 21:12:26 +03:00
|
|
|
|
|
2026-01-13 20:55:44 +03:00
|
|
|
|
function Wishlist({ onNavigate, refreshTrigger = 0, isActive = false }) {
|
2026-01-11 21:12:26 +03:00
|
|
|
|
const { authFetch } = useAuth()
|
|
|
|
|
|
const [items, setItems] = useState([])
|
|
|
|
|
|
const [completed, setCompleted] = useState([])
|
2026-01-12 17:42:51 +03:00
|
|
|
|
const [completedCount, setCompletedCount] = useState(0)
|
2026-01-11 21:12:26 +03:00
|
|
|
|
const [loading, setLoading] = useState(true)
|
|
|
|
|
|
const [error, setError] = useState('')
|
|
|
|
|
|
const [completedExpanded, setCompletedExpanded] = useState(false)
|
|
|
|
|
|
const [completedLoading, setCompletedLoading] = useState(false)
|
|
|
|
|
|
const [selectedItem, setSelectedItem] = useState(null)
|
2026-01-13 20:55:44 +03:00
|
|
|
|
const fetchingRef = useRef(false)
|
|
|
|
|
|
const fetchingCompletedRef = useRef(false)
|
|
|
|
|
|
const initialFetchDoneRef = useRef(false)
|
|
|
|
|
|
const prevIsActiveRef = useRef(isActive)
|
2026-01-11 21:12:26 +03:00
|
|
|
|
|
2026-01-13 20:55:44 +03:00
|
|
|
|
// Проверка наличия кэша
|
|
|
|
|
|
const hasCache = () => {
|
|
|
|
|
|
try {
|
|
|
|
|
|
return localStorage.getItem(CACHE_KEY) !== null
|
|
|
|
|
|
} catch (err) {
|
|
|
|
|
|
return false
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2026-01-11 21:12:26 +03:00
|
|
|
|
|
2026-01-13 20:55:44 +03:00
|
|
|
|
// Загрузка основных данных из кэша
|
|
|
|
|
|
const loadFromCache = () => {
|
2026-01-12 17:42:51 +03:00
|
|
|
|
try {
|
2026-01-13 20:55:44 +03:00
|
|
|
|
const cached = localStorage.getItem(CACHE_KEY)
|
|
|
|
|
|
if (cached) {
|
|
|
|
|
|
const data = JSON.parse(cached)
|
|
|
|
|
|
setItems(data.items || [])
|
|
|
|
|
|
setCompletedCount(data.completedCount || 0)
|
|
|
|
|
|
return true
|
2026-01-12 17:42:51 +03:00
|
|
|
|
}
|
2026-01-13 20:55:44 +03:00
|
|
|
|
} catch (err) {
|
|
|
|
|
|
console.error('Error loading from cache:', err)
|
|
|
|
|
|
}
|
|
|
|
|
|
return false
|
|
|
|
|
|
}
|
2026-01-12 17:42:51 +03:00
|
|
|
|
|
2026-01-13 20:55:44 +03:00
|
|
|
|
// Загрузка завершённых из кэша
|
|
|
|
|
|
const loadCompletedFromCache = () => {
|
|
|
|
|
|
try {
|
|
|
|
|
|
const cached = localStorage.getItem(CACHE_COMPLETED_KEY)
|
|
|
|
|
|
if (cached) {
|
|
|
|
|
|
const data = JSON.parse(cached)
|
|
|
|
|
|
setCompleted(data || [])
|
|
|
|
|
|
return true
|
2026-01-12 17:42:51 +03:00
|
|
|
|
}
|
|
|
|
|
|
} catch (err) {
|
2026-01-13 20:55:44 +03:00
|
|
|
|
console.error('Error loading completed from cache:', err)
|
2026-01-12 17:42:51 +03:00
|
|
|
|
}
|
2026-01-13 20:55:44 +03:00
|
|
|
|
return false
|
2026-01-12 17:42:51 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-01-13 20:55:44 +03:00
|
|
|
|
// Сохранение основных данных в кэш
|
|
|
|
|
|
const saveToCache = (itemsData, count) => {
|
|
|
|
|
|
try {
|
|
|
|
|
|
localStorage.setItem(CACHE_KEY, JSON.stringify({
|
|
|
|
|
|
items: itemsData,
|
|
|
|
|
|
completedCount: count,
|
|
|
|
|
|
timestamp: Date.now()
|
|
|
|
|
|
}))
|
|
|
|
|
|
} catch (err) {
|
|
|
|
|
|
console.error('Error saving to cache:', err)
|
2026-01-11 21:12:26 +03:00
|
|
|
|
}
|
2026-01-13 20:55:44 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Сохранение завершённых в кэш
|
|
|
|
|
|
const saveCompletedToCache = (completedData) => {
|
|
|
|
|
|
try {
|
|
|
|
|
|
localStorage.setItem(CACHE_COMPLETED_KEY, JSON.stringify(completedData))
|
|
|
|
|
|
} catch (err) {
|
|
|
|
|
|
console.error('Error saving completed to cache:', err)
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2026-01-11 21:12:26 +03:00
|
|
|
|
|
2026-01-13 20:55:44 +03:00
|
|
|
|
// Загрузка основного списка
|
2026-01-12 17:42:51 +03:00
|
|
|
|
const fetchWishlist = async () => {
|
2026-01-13 20:55:44 +03:00
|
|
|
|
if (fetchingRef.current) return
|
|
|
|
|
|
fetchingRef.current = true
|
|
|
|
|
|
|
2026-01-11 21:12:26 +03:00
|
|
|
|
try {
|
2026-01-13 20:55:44 +03:00
|
|
|
|
const hasDataInState = items.length > 0 || completedCount > 0
|
|
|
|
|
|
const cacheExists = hasCache()
|
|
|
|
|
|
if (!hasDataInState && !cacheExists) {
|
|
|
|
|
|
setLoading(true)
|
|
|
|
|
|
}
|
2026-01-11 21:12:26 +03:00
|
|
|
|
|
2026-01-12 17:42:51 +03:00
|
|
|
|
const response = await authFetch(API_URL)
|
2026-01-11 21:12:26 +03:00
|
|
|
|
|
|
|
|
|
|
if (!response.ok) {
|
|
|
|
|
|
throw new Error('Ошибка при загрузке желаний')
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const data = await response.json()
|
|
|
|
|
|
const allItems = [...(data.unlocked || []), ...(data.locked || [])]
|
2026-01-12 17:42:51 +03:00
|
|
|
|
const count = data.completed_count || 0
|
|
|
|
|
|
|
2026-01-13 20:55:44 +03:00
|
|
|
|
setItems(allItems)
|
|
|
|
|
|
setCompletedCount(count)
|
|
|
|
|
|
saveToCache(allItems, count)
|
2026-01-11 21:12:26 +03:00
|
|
|
|
setError('')
|
|
|
|
|
|
} catch (err) {
|
|
|
|
|
|
setError(err.message)
|
2026-01-13 20:55:44 +03:00
|
|
|
|
if (!hasCache()) {
|
|
|
|
|
|
setItems([])
|
|
|
|
|
|
setCompletedCount(0)
|
|
|
|
|
|
}
|
2026-01-11 21:12:26 +03:00
|
|
|
|
} finally {
|
|
|
|
|
|
setLoading(false)
|
2026-01-13 20:55:44 +03:00
|
|
|
|
fetchingRef.current = false
|
2026-01-12 17:42:51 +03:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-01-13 20:55:44 +03:00
|
|
|
|
// Загрузка завершённых
|
2026-01-12 17:42:51 +03:00
|
|
|
|
const fetchCompleted = async () => {
|
2026-01-13 20:55:44 +03:00
|
|
|
|
if (fetchingCompletedRef.current) return
|
|
|
|
|
|
fetchingCompletedRef.current = true
|
|
|
|
|
|
|
2026-01-12 17:42:51 +03:00
|
|
|
|
try {
|
|
|
|
|
|
setCompletedLoading(true)
|
2026-01-13 20:55:44 +03:00
|
|
|
|
const response = await authFetch(`${API_URL}/completed`)
|
2026-01-12 17:42:51 +03:00
|
|
|
|
|
|
|
|
|
|
if (!response.ok) {
|
|
|
|
|
|
throw new Error('Ошибка при загрузке завершённых желаний')
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const data = await response.json()
|
2026-01-13 20:55:44 +03:00
|
|
|
|
const completedData = Array.isArray(data) ? data : []
|
|
|
|
|
|
setCompleted(completedData)
|
|
|
|
|
|
saveCompletedToCache(completedData)
|
2026-01-12 17:42:51 +03:00
|
|
|
|
} catch (err) {
|
|
|
|
|
|
console.error('Error fetching completed items:', err)
|
|
|
|
|
|
setCompleted([])
|
|
|
|
|
|
} finally {
|
2026-01-11 21:12:26 +03:00
|
|
|
|
setCompletedLoading(false)
|
2026-01-13 20:55:44 +03:00
|
|
|
|
fetchingCompletedRef.current = false
|
2026-01-11 21:12:26 +03:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-01-13 20:55:44 +03:00
|
|
|
|
// Первая инициализация
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
|
if (!initialFetchDoneRef.current) {
|
|
|
|
|
|
initialFetchDoneRef.current = true
|
|
|
|
|
|
|
|
|
|
|
|
// Загружаем из кэша
|
|
|
|
|
|
const cacheLoaded = loadFromCache()
|
|
|
|
|
|
if (cacheLoaded) {
|
|
|
|
|
|
setLoading(false)
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Загружаем свежие данные
|
|
|
|
|
|
fetchWishlist()
|
|
|
|
|
|
|
|
|
|
|
|
// Если список завершённых раскрыт - загружаем их тоже
|
|
|
|
|
|
if (completedExpanded) {
|
|
|
|
|
|
loadCompletedFromCache()
|
|
|
|
|
|
fetchCompleted()
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}, [])
|
|
|
|
|
|
|
|
|
|
|
|
// Обработка активации/деактивации таба
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
|
const wasActive = prevIsActiveRef.current
|
|
|
|
|
|
prevIsActiveRef.current = isActive
|
|
|
|
|
|
|
|
|
|
|
|
// Пропускаем первую инициализацию (она обрабатывается отдельно)
|
|
|
|
|
|
if (!initialFetchDoneRef.current) return
|
|
|
|
|
|
|
|
|
|
|
|
// Когда таб становится видимым
|
|
|
|
|
|
if (isActive && !wasActive) {
|
|
|
|
|
|
// Показываем кэш, если есть данные
|
|
|
|
|
|
const hasDataInState = items.length > 0 || completedCount > 0
|
|
|
|
|
|
if (!hasDataInState) {
|
|
|
|
|
|
const cacheLoaded = loadFromCache()
|
|
|
|
|
|
if (cacheLoaded) {
|
|
|
|
|
|
setLoading(false)
|
|
|
|
|
|
} else {
|
|
|
|
|
|
setLoading(true)
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Всегда загружаем свежие данные основного списка
|
|
|
|
|
|
fetchWishlist()
|
|
|
|
|
|
|
|
|
|
|
|
// Если список завершённых раскрыт - загружаем их тоже
|
|
|
|
|
|
if (completedExpanded && completedCount > 0) {
|
|
|
|
|
|
fetchCompleted()
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}, [isActive])
|
|
|
|
|
|
|
|
|
|
|
|
// Обновляем данные при изменении refreshTrigger
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
|
if (refreshTrigger > 0) {
|
|
|
|
|
|
fetchWishlist()
|
|
|
|
|
|
if (completedExpanded && completedCount > 0) {
|
|
|
|
|
|
fetchCompleted()
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}, [refreshTrigger])
|
|
|
|
|
|
|
2026-01-11 21:12:26 +03:00
|
|
|
|
const handleToggleCompleted = () => {
|
|
|
|
|
|
const newExpanded = !completedExpanded
|
|
|
|
|
|
setCompletedExpanded(newExpanded)
|
2026-01-13 20:55:44 +03:00
|
|
|
|
|
|
|
|
|
|
// При раскрытии загружаем завершённые
|
|
|
|
|
|
if (newExpanded && completedCount > 0) {
|
|
|
|
|
|
// Показываем из кэша если есть
|
|
|
|
|
|
if (completed.length === 0) {
|
|
|
|
|
|
loadCompletedFromCache()
|
|
|
|
|
|
}
|
|
|
|
|
|
// Загружаем свежие данные
|
2026-01-12 17:42:51 +03:00
|
|
|
|
fetchCompleted()
|
2026-01-11 21:12:26 +03:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const handleAddClick = () => {
|
|
|
|
|
|
onNavigate?.('wishlist-form', { wishlistId: undefined })
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const handleItemClick = (item) => {
|
|
|
|
|
|
onNavigate?.('wishlist-detail', { wishlistId: item.id })
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const handleMenuClick = (item, e) => {
|
|
|
|
|
|
e.stopPropagation()
|
|
|
|
|
|
setSelectedItem(item)
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const handleEdit = () => {
|
|
|
|
|
|
if (selectedItem) {
|
|
|
|
|
|
onNavigate?.('wishlist-form', { wishlistId: selectedItem.id })
|
|
|
|
|
|
setSelectedItem(null)
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const handleDelete = async () => {
|
|
|
|
|
|
if (!selectedItem) return
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
const response = await authFetch(`${API_URL}/${selectedItem.id}`, {
|
|
|
|
|
|
method: 'DELETE',
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
if (!response.ok) {
|
|
|
|
|
|
throw new Error('Ошибка при удалении')
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
setSelectedItem(null)
|
2026-01-13 20:55:44 +03:00
|
|
|
|
await fetchWishlist()
|
|
|
|
|
|
if (completedExpanded) {
|
|
|
|
|
|
await fetchCompleted()
|
|
|
|
|
|
}
|
2026-01-11 21:12:26 +03:00
|
|
|
|
} catch (err) {
|
|
|
|
|
|
setError(err.message)
|
|
|
|
|
|
setSelectedItem(null)
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const handleComplete = async () => {
|
|
|
|
|
|
if (!selectedItem) return
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
const response = await authFetch(`${API_URL}/${selectedItem.id}/complete`, {
|
|
|
|
|
|
method: 'POST',
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
if (!response.ok) {
|
|
|
|
|
|
throw new Error('Ошибка при завершении')
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
setSelectedItem(null)
|
2026-01-13 20:55:44 +03:00
|
|
|
|
await fetchWishlist()
|
|
|
|
|
|
if (completedExpanded) {
|
|
|
|
|
|
await fetchCompleted()
|
|
|
|
|
|
}
|
2026-01-11 21:12:26 +03:00
|
|
|
|
} catch (err) {
|
|
|
|
|
|
setError(err.message)
|
|
|
|
|
|
setSelectedItem(null)
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-01-12 17:42:51 +03:00
|
|
|
|
const handleCopy = async () => {
|
|
|
|
|
|
if (!selectedItem) return
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
2026-01-13 20:55:44 +03:00
|
|
|
|
const response = await authFetch(`${API_URL}/${selectedItem.id}/copy`, {
|
2026-01-12 17:42:51 +03:00
|
|
|
|
method: 'POST',
|
|
|
|
|
|
})
|
|
|
|
|
|
|
2026-01-13 20:55:44 +03:00
|
|
|
|
if (!response.ok) {
|
|
|
|
|
|
throw new Error('Ошибка при копировании')
|
2026-01-12 17:42:51 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-01-13 20:55:44 +03:00
|
|
|
|
const newItem = await response.json()
|
2026-01-12 17:42:51 +03:00
|
|
|
|
|
|
|
|
|
|
setSelectedItem(null)
|
|
|
|
|
|
onNavigate?.('wishlist-form', { wishlistId: newItem.id })
|
|
|
|
|
|
} catch (err) {
|
|
|
|
|
|
setError(err.message)
|
|
|
|
|
|
setSelectedItem(null)
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-01-11 21:12:26 +03:00
|
|
|
|
const formatPrice = (price) => {
|
|
|
|
|
|
return new Intl.NumberFormat('ru-RU', {
|
|
|
|
|
|
style: 'currency',
|
|
|
|
|
|
currency: 'RUB',
|
|
|
|
|
|
minimumFractionDigits: 0,
|
|
|
|
|
|
maximumFractionDigits: 0,
|
|
|
|
|
|
}).format(price)
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-01-12 17:42:51 +03:00
|
|
|
|
const findFirstUnmetCondition = (item) => {
|
|
|
|
|
|
if (!item.unlock_conditions || item.unlock_conditions.length === 0) {
|
|
|
|
|
|
return null
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
for (const condition of item.unlock_conditions) {
|
|
|
|
|
|
let isMet = false
|
|
|
|
|
|
|
|
|
|
|
|
if (condition.type === 'task_completion') {
|
|
|
|
|
|
isMet = condition.task_completed === true
|
|
|
|
|
|
} else if (condition.type === 'project_points') {
|
|
|
|
|
|
const currentPoints = condition.current_points || 0
|
|
|
|
|
|
const requiredPoints = condition.required_points || 0
|
|
|
|
|
|
isMet = currentPoints >= requiredPoints
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (!isMet) {
|
|
|
|
|
|
return condition
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return null
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-01-11 21:12:26 +03:00
|
|
|
|
const renderUnlockCondition = (item) => {
|
2026-01-12 17:42:51 +03:00
|
|
|
|
if (item.completed) return null
|
2026-01-11 21:12:26 +03:00
|
|
|
|
|
2026-01-12 17:42:51 +03:00
|
|
|
|
const condition = findFirstUnmetCondition(item)
|
|
|
|
|
|
if (!condition) return null
|
2026-01-11 21:12:26 +03:00
|
|
|
|
|
|
|
|
|
|
let conditionText = ''
|
|
|
|
|
|
if (condition.type === 'task_completion') {
|
|
|
|
|
|
conditionText = condition.task_name || 'Задача'
|
|
|
|
|
|
} else {
|
|
|
|
|
|
const points = condition.required_points || 0
|
|
|
|
|
|
const project = condition.project_name || 'Проект'
|
2026-01-12 17:42:51 +03:00
|
|
|
|
let dateText = ''
|
|
|
|
|
|
if (condition.start_date) {
|
|
|
|
|
|
const date = new Date(condition.start_date + 'T00:00:00')
|
|
|
|
|
|
dateText = ` с ${date.toLocaleDateString('ru-RU')}`
|
|
|
|
|
|
} else {
|
|
|
|
|
|
dateText = ' за всё время'
|
2026-01-11 21:12:26 +03:00
|
|
|
|
}
|
2026-01-12 17:42:51 +03:00
|
|
|
|
conditionText = `${points} в ${project}${dateText}`
|
2026-01-11 21:12:26 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
|
<div className="unlock-condition-wrapper">
|
|
|
|
|
|
<div className="unlock-condition-line">
|
|
|
|
|
|
<div className="unlock-condition">
|
|
|
|
|
|
<svg className="lock-icon" width="12" height="12" viewBox="0 0 24 24" fill="currentColor">
|
|
|
|
|
|
<path d="M18 8h-1V6c0-2.76-2.24-5-5-5S7 3.24 7 6v2H6c-1.1 0-2 .9-2 2v10c0 1.1.9 2 2 2h12c1.1 0 2-.9 2-2V10c0-1.1-.9-2-2-2zM9 6c0-1.66 1.34-3 3-3s3 1.34 3 3v2H9V6zm9 14H6V10h12v10zm-6-3c1.1 0 2-.9 2-2s-.9-2-2-2-2 .9-2 2 .9 2 2 2z"/>
|
|
|
|
|
|
</svg>
|
|
|
|
|
|
<span className="condition-text">{conditionText}</span>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
)
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const renderItem = (item) => {
|
|
|
|
|
|
const isFaded = (!item.unlocked && !item.completed) || item.completed
|
|
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
|
<div
|
|
|
|
|
|
key={item.id}
|
|
|
|
|
|
className={`wishlist-card ${isFaded ? 'faded' : ''}`}
|
|
|
|
|
|
onClick={() => handleItemClick(item)}
|
|
|
|
|
|
>
|
|
|
|
|
|
<button
|
|
|
|
|
|
className="card-menu-button"
|
|
|
|
|
|
onClick={(e) => handleMenuClick(item, e)}
|
|
|
|
|
|
title="Меню"
|
|
|
|
|
|
>
|
|
|
|
|
|
⋮
|
|
|
|
|
|
</button>
|
|
|
|
|
|
|
|
|
|
|
|
<div className="card-image">
|
|
|
|
|
|
{item.image_url ? (
|
|
|
|
|
|
<img src={item.image_url} alt={item.name} />
|
|
|
|
|
|
) : (
|
|
|
|
|
|
<div className="placeholder">
|
|
|
|
|
|
<svg width="48" height="48" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2">
|
|
|
|
|
|
<rect x="3" y="3" width="18" height="18" rx="2" ry="2"/>
|
|
|
|
|
|
<circle cx="8.5" cy="8.5" r="1.5"/>
|
|
|
|
|
|
<polyline points="21 15 16 10 5 21"/>
|
|
|
|
|
|
</svg>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
)}
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
<div className="card-name">{item.name}</div>
|
|
|
|
|
|
|
2026-01-12 17:42:51 +03:00
|
|
|
|
{(() => {
|
|
|
|
|
|
const unmetCondition = findFirstUnmetCondition(item)
|
|
|
|
|
|
if (unmetCondition && !item.completed) {
|
|
|
|
|
|
return renderUnlockCondition(item)
|
|
|
|
|
|
}
|
|
|
|
|
|
if (item.price) {
|
|
|
|
|
|
return <div className="card-price">{formatPrice(item.price)}</div>
|
|
|
|
|
|
}
|
|
|
|
|
|
return null
|
|
|
|
|
|
})()}
|
2026-01-11 21:12:26 +03:00
|
|
|
|
</div>
|
|
|
|
|
|
)
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (loading) {
|
|
|
|
|
|
return (
|
|
|
|
|
|
<div className="wishlist">
|
|
|
|
|
|
<div className="fixed inset-0 bottom-20 flex justify-center items-center">
|
|
|
|
|
|
<div className="flex flex-col items-center">
|
|
|
|
|
|
<div className="w-12 h-12 border-4 border-indigo-200 border-t-indigo-600 rounded-full animate-spin mb-4"></div>
|
|
|
|
|
|
<div className="text-gray-600 font-medium">Загрузка...</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
)
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (error) {
|
|
|
|
|
|
return (
|
|
|
|
|
|
<div className="wishlist">
|
|
|
|
|
|
<LoadingError onRetry={() => fetchWishlist()} />
|
|
|
|
|
|
</div>
|
|
|
|
|
|
)
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
|
<div className="wishlist">
|
|
|
|
|
|
{/* Кнопка добавления */}
|
|
|
|
|
|
<button onClick={handleAddClick} className="add-wishlist-button">
|
|
|
|
|
|
Добавить
|
|
|
|
|
|
</button>
|
|
|
|
|
|
|
|
|
|
|
|
{/* Основной список (разблокированные и заблокированные вместе) */}
|
|
|
|
|
|
{items.length > 0 && (
|
|
|
|
|
|
<div className="wishlist-grid">
|
|
|
|
|
|
{items.map(renderItem)}
|
|
|
|
|
|
</div>
|
|
|
|
|
|
)}
|
|
|
|
|
|
|
2026-01-12 17:42:51 +03:00
|
|
|
|
{/* Завершённые - показываем только если есть завершённые желания */}
|
|
|
|
|
|
{completedCount > 0 && (
|
2026-01-11 21:12:26 +03:00
|
|
|
|
<>
|
2026-01-12 17:42:51 +03:00
|
|
|
|
<div className="section-divider">
|
|
|
|
|
|
<button
|
|
|
|
|
|
className="completed-toggle"
|
|
|
|
|
|
onClick={handleToggleCompleted}
|
|
|
|
|
|
>
|
|
|
|
|
|
<span className="completed-toggle-icon">
|
|
|
|
|
|
{completedExpanded ? '▼' : '▶'}
|
|
|
|
|
|
</span>
|
|
|
|
|
|
<span>Завершённые</span>
|
|
|
|
|
|
</button>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
{completedExpanded && (
|
|
|
|
|
|
<>
|
|
|
|
|
|
{completedLoading ? (
|
|
|
|
|
|
<div className="loading-completed">
|
|
|
|
|
|
<div className="w-8 h-8 border-4 border-indigo-200 border-t-indigo-600 rounded-full animate-spin"></div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
) : (
|
|
|
|
|
|
<div className="wishlist-grid">
|
|
|
|
|
|
{completed.map(renderItem)}
|
|
|
|
|
|
</div>
|
|
|
|
|
|
)}
|
|
|
|
|
|
</>
|
2026-01-11 21:12:26 +03:00
|
|
|
|
)}
|
|
|
|
|
|
</>
|
|
|
|
|
|
)}
|
|
|
|
|
|
|
|
|
|
|
|
{/* Модальное окно для действий */}
|
|
|
|
|
|
{selectedItem && (
|
|
|
|
|
|
<div className="wishlist-modal-overlay" onClick={() => setSelectedItem(null)}>
|
|
|
|
|
|
<div className="wishlist-modal" onClick={(e) => e.stopPropagation()}>
|
|
|
|
|
|
<div className="wishlist-modal-header">
|
|
|
|
|
|
<h3>{selectedItem.name}</h3>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<div className="wishlist-modal-actions">
|
|
|
|
|
|
<button className="wishlist-modal-edit" onClick={handleEdit}>
|
|
|
|
|
|
Редактировать
|
|
|
|
|
|
</button>
|
2026-01-12 17:42:51 +03:00
|
|
|
|
<button className="wishlist-modal-copy" onClick={handleCopy}>
|
|
|
|
|
|
Копировать
|
|
|
|
|
|
</button>
|
2026-01-11 21:12:26 +03:00
|
|
|
|
<button className="wishlist-modal-delete" onClick={handleDelete}>
|
|
|
|
|
|
Удалить
|
|
|
|
|
|
</button>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
)}
|
|
|
|
|
|
</div>
|
|
|
|
|
|
)
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
export default Wishlist
|
|
|
|
|
|
|