import React, { useState } from 'react'; import { useApp } from '../../context/AppContext'; import { currentUser, hapticImpact, hapticNotification } from '../../services/auth'; import { api } from '../../services/api'; import './CreateCard.css'; const MAX_LENGTH = 150; export default function CreateCard({ onBack }) { const { showToast, closeMenu, handleApiResponse } = useApp(); const [choiceA, setChoiceA] = useState(''); const [choiceB, setChoiceB] = useState(''); const [isSending, setIsSending] = useState(false); const canSubmit = choiceA.trim().length > 0 && choiceB.trim().length > 0 && !isSending; async function handleSubmit() { if (!canSubmit) return; setIsSending(true); hapticImpact('light'); try { const result = await api.addCard(choiceA.trim(), choiceB.trim(), currentUser.id); handleApiResponse(result); if (!result.error) { hapticNotification('success'); showToast('Карточка отправлена на модерацию!'); setTimeout(() => { closeMenu(); }, 1800); } else { hapticNotification('error'); showToast(typeof result.result === 'string' ? result.result : 'Ошибка модерации или отправки'); setIsSending(false); } } catch (err) { console.error('Add card error:', err); hapticNotification('error'); showToast('Ошибка отправки'); setIsSending(false); } } const handleBack = () => { hapticImpact('light'); onBack(); }; return (
💡 Правила публикации: Запрещены нецензурные выражения, оскорбления и спам-ссылки. Все карточки проверяются перед публикацией.