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 CustomWordsProps { descriptionMode?: "inline" | "tooltip"; grouped?: boolean; } export const CustomWords: React.FC = React.memo( ({ descriptionMode = "tooltip", grouped = false }) => { const { getSetting, updateSetting, isUpdating } = useSettings(); const [newWord, setNewWord] = useState(""); const customWords = getSetting("custom_words") || []; const handleAddWord = () => { const trimmedWord = newWord.trim(); const sanitizedWord = trimmedWord.replace(/[<>"'&]/g, ""); if ( sanitizedWord && !sanitizedWord.includes(" ") && sanitizedWord.length <= 50 && !customWords.includes(sanitizedWord) ) { updateSetting("custom_words", [...customWords, sanitizedWord]); setNewWord(""); } }; const handleRemoveWord = (wordToRemove: string) => { updateSetting( "custom_words", customWords.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("custom_words")} />
{customWords.length > 0 && (
{customWords.map((word) => ( ))}
)} ); }, );