Add functionality to restore and save test answers in localStorage for task editing; enhance user experience by preserving input across sessions.
This commit is contained in:
@@ -54,6 +54,39 @@ export const TaskFormPage: React.FC = () => {
|
|||||||
}
|
}
|
||||||
}, [task])
|
}, [task])
|
||||||
|
|
||||||
|
// Восстановление сохранённого тестового ответа для конкретной задачи
|
||||||
|
useEffect(() => {
|
||||||
|
if (!isEdit || !id) return
|
||||||
|
if (typeof window === 'undefined') return
|
||||||
|
|
||||||
|
const key = `challenge-admin.task-test-answer.${id}`
|
||||||
|
try {
|
||||||
|
const saved = window.localStorage.getItem(key)
|
||||||
|
if (saved) {
|
||||||
|
setTestAnswer(saved)
|
||||||
|
}
|
||||||
|
} catch {
|
||||||
|
// ignore localStorage errors
|
||||||
|
}
|
||||||
|
}, [isEdit, id])
|
||||||
|
|
||||||
|
// Сохранение тестового ответа в localStorage
|
||||||
|
useEffect(() => {
|
||||||
|
if (!isEdit || !id) return
|
||||||
|
if (typeof window === 'undefined') return
|
||||||
|
|
||||||
|
const key = `challenge-admin.task-test-answer.${id}`
|
||||||
|
try {
|
||||||
|
if (testAnswer.trim()) {
|
||||||
|
window.localStorage.setItem(key, testAnswer)
|
||||||
|
} else {
|
||||||
|
window.localStorage.removeItem(key)
|
||||||
|
}
|
||||||
|
} catch {
|
||||||
|
// ignore localStorage errors
|
||||||
|
}
|
||||||
|
}, [isEdit, id, testAnswer])
|
||||||
|
|
||||||
const handleSubmit = async (e: React.FormEvent) => {
|
const handleSubmit = async (e: React.FormEvent) => {
|
||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user