diff --git a/src/components/GameManagementModal.jsx b/src/components/GameManagementModal.jsx
index 2029225..26a7a91 100644
--- a/src/components/GameManagementModal.jsx
+++ b/src/components/GameManagementModal.jsx
@@ -46,6 +46,9 @@ const GameManagementModal = ({
const [selectedPack, setSelectedPack] = useState(null)
const [packQuestions, setPackQuestions] = useState([])
const [selectedQuestionIndices, setSelectedQuestionIndices] = useState(new Set())
+ const [searchQuery, setSearchQuery] = useState('')
+ const [viewingQuestion, setViewingQuestion] = useState(null)
+ const [showAnswers, setShowAnswers] = useState(false)
if (!isOpen) return null
@@ -244,6 +247,9 @@ const GameManagementModal = ({
if (!packId) {
setPackQuestions([])
setSelectedPack(null)
+ setSearchQuery('')
+ setViewingQuestion(null)
+ setShowAnswers(false)
return
}
@@ -252,12 +258,70 @@ const GameManagementModal = ({
setPackQuestions(response.data.questions || [])
setSelectedPack(packId)
setSelectedQuestionIndices(new Set())
+ setSearchQuery('')
+ setViewingQuestion(null)
+ setShowAnswers(false)
} catch (error) {
console.error('Error fetching pack:', error)
setJsonError('Ошибка загрузки пака вопросов')
}
}
+ // Фильтрация вопросов по поисковому запросу
+ const filteredPackQuestions = packQuestions.filter((q) => {
+ if (!searchQuery.trim()) return true
+ const questionText = (q.text || q.question || '').toLowerCase()
+ return questionText.includes(searchQuery.toLowerCase())
+ })
+
+ // Выбор всех видимых вопросов
+ const handleSelectAll = () => {
+ const allVisibleIndices = new Set(
+ filteredPackQuestions.map((q) => {
+ const originalIndex = packQuestions.findIndex(pq => pq === q)
+ return originalIndex
+ }).filter(idx => idx !== -1)
+ )
+ const newSelected = new Set(selectedQuestionIndices)
+ allVisibleIndices.forEach(idx => newSelected.add(idx))
+ setSelectedQuestionIndices(newSelected)
+ }
+
+ // Снятие выбора со всех видимых вопросов
+ const handleDeselectAll = () => {
+ const visibleIndices = new Set(
+ filteredPackQuestions.map((q) => {
+ const originalIndex = packQuestions.findIndex(pq => pq === q)
+ return originalIndex
+ }).filter(idx => idx !== -1)
+ )
+ const newSelected = new Set(selectedQuestionIndices)
+ visibleIndices.forEach(idx => newSelected.delete(idx))
+ setSelectedQuestionIndices(newSelected)
+ }
+
+ // Проверка, выбраны ли все видимые вопросы
+ const areAllVisibleSelected = () => {
+ if (filteredPackQuestions.length === 0) return false
+ const visibleIndices = filteredPackQuestions.map((q) => {
+ const originalIndex = packQuestions.findIndex(pq => pq === q)
+ return originalIndex
+ }).filter(idx => idx !== -1)
+ return visibleIndices.every(idx => selectedQuestionIndices.has(idx))
+ }
+
+ // Просмотр вопроса
+ const handleViewQuestion = (question) => {
+ setViewingQuestion(question)
+ setShowAnswers(false)
+ }
+
+ // Закрытие просмотра вопроса
+ const handleCloseViewer = () => {
+ setViewingQuestion(null)
+ setShowAnswers(false)
+ }
+
const handleToggleQuestion = (index) => {
const newSelected = new Set(selectedQuestionIndices)
if (newSelected.has(index)) {
@@ -272,16 +336,17 @@ const GameManagementModal = ({
const indices = Array.from(selectedQuestionIndices)
const questionsToImport = indices.map(idx => packQuestions[idx]).filter(Boolean)
- const copiedQuestions = questionsToImport.map(q => ({
- id: Date.now() + Math.random(),
- text: q.text,
- answers: q.answers.map(a => ({ text: a.text, points: a.points })),
+ const copiedQuestions = questionsToImport.map((q, idx) => ({
+ id: Date.now() + Math.random() + idx, // Generate new ID
+ text: q.text || q.question || '',
+ answers: (q.answers || []).map(a => ({ text: a.text, points: a.points })),
}))
const updatedQuestions = [...questions, ...copiedQuestions]
onUpdateQuestions(updatedQuestions)
setSelectedQuestionIndices(new Set())
+ setSearchQuery('')
setShowPackImport(false)
setJsonError('')
alert(`Импортировано ${copiedQuestions.length} вопросов`)
@@ -577,8 +642,42 @@ const GameManagementModal = ({
{packQuestions.length > 0 && (
+ {/* Поиск */}
+
+ setSearchQuery(e.target.value)}
+ placeholder="🔍 Поиск вопросов..."
+ className="pack-search-input"
+ />
+
+
-
Выберите вопросы для импорта:
+
+
Выберите вопросы для импорта:
+
+ {filteredPackQuestions.length > 0 && (
+ <>
+ {areAllVisibleSelected() ? (
+
+ ) : (
+
+ )}
+ >
+ )}
+
+