import React, { useState } from "react"; import { useSettings } from "../../hooks/useSettings"; import { Input } from "../ui/Input"; import { Button } from "../ui/Button"; import { SettingContainer } from "../ui/SettingContainer"; interface CorrectWordsProps { descriptionMode?: "inline" | "tooltip"; grouped?: boolean; } export const CorrectWords: React.FC = React.memo(({ descriptionMode = "tooltip", grouped = false, }) => { const { getSetting, updateSetting, isUpdating } = useSettings(); const [newWord, setNewWord] = useState(""); const correctWords = getSetting("correct_words") || []; const handleAddWord = () => { const trimmedWord = newWord.trim(); const sanitizedWord = trimmedWord.replace(/[<>"'&]/g, ''); if (sanitizedWord && !sanitizedWord.includes(' ') && sanitizedWord.length <= 50 && !correctWords.includes(sanitizedWord)) { updateSetting("correct_words", [...correctWords, sanitizedWord]); setNewWord(""); } }; const handleRemoveWord = (wordToRemove: string) => { updateSetting("correct_words", correctWords.filter((word) => word !== wordToRemove)); }; const handleKeyPress = (e: React.KeyboardEvent) => { if (e.key === "Enter") { e.preventDefault(); handleAddWord(); } }; return ( <>
setNewWord(e.target.value)} onKeyPress={handleKeyPress} placeholder="Add a word" variant="compact" disabled={isUpdating("correct_words")} />
{correctWords.length > 0 && (
{correctWords.map((word) => ( ))}
)} ); });