this repo has no description
2
fork

Configure Feed

Select the types of activity you want to include in your feed.

fix: filters being cleared when newText == ""

+16 -31
+16 -31
mast-react-vite/src/App.tsx
··· 28 28 clearFilters 29 29 } = useFilter(); 30 30 const [currentAction, setCurrentAction] = useState("add"); 31 + const [savedText, setSavedText] = useState(""); 31 32 32 33 // Get current conditions and parameters for SQL query 33 34 const { conditions: newConditions, params: newParams } = getWhereClause(); ··· 53 54 ...todo, 54 55 priority: todo.priority === '1' 55 56 })); 56 - 57 - // Keep newText in sync with filterText when in filter mode 58 - useEffect(() => { 59 - // Only update if we're in filter mode 60 - if (currentAction === "filter") { 61 - setNewText(filterText); 62 - } 63 - }, [filterText, currentAction]); 64 57 65 58 // Listen for filter update events from sidebar - primarily for debugging 66 59 useEffect(() => { ··· 165 158 } 166 159 }, [parsedCommand, todos, selectedItems]); 167 160 168 - // When parsed command changes to a filter action, update the filter text 169 - useEffect(() => { 170 - if (parsedCommand.action === "filter") { 171 - // Set the filter text in the context when a filter command is parsed 172 - setFilterText(newText); 173 - } 174 - }, [parsedCommand, newText, setFilterText]); 175 - 176 161 const handleActionChange = (action: string) => { 177 - // If switching to filter action, use the current filter text from context 162 + // If switching to filter action, save current text and use filter text from context 178 163 if (action === "filter") { 164 + setSavedText(newText); 165 + setCurrentAction(action); 166 + // If there is saved filter text, use that 179 167 if (filterText) { 180 168 setNewText(filterText); 181 - } 169 + } else { 170 + // otherwise adopt current text as filter text 171 + setFilterText(newText) 172 + } 182 173 } else if (currentAction === "filter" && action !== "filter") { 183 - // If switching away from filter, clear the text input but keep the filter active 184 - setNewText(""); 174 + // If switching away from filter, set action first then restore the saved text 175 + setCurrentAction(action); 176 + if (savedText !== "") { 177 + setNewText(savedText) 178 + } 179 + } else { 180 + setCurrentAction(action); 185 181 } 186 - 187 - setCurrentAction(action); 188 182 }; 189 183 190 184 const handleNewTextChange = (text: string) => { 191 - // Update the local state 192 185 setNewText(text); 193 186 194 - // If the current action is filter, also update the filter text in the context 195 - // This enables real-time filtering as the user types 196 187 if (currentAction === "filter") { 197 - // Only update the filter text if it's different to avoid circular updates 198 188 if (text !== filterText) { 199 189 setFilterText(text); 200 190 } ··· 244 234 const handleEnter = (e) => { 245 235 if (e.key === "Enter") { 246 236 executeCommand(); 247 - } 248 - if (e.keyCode === 8) { 249 - if (newText.trim().length === 0) { 250 - clearFilters(); 251 - } 252 237 } 253 238 }; 254 239