fix: resolve lint errors — setState-during-render instead of useEffect
This commit is contained in:
parent
3472f27c3a
commit
d8655df838
2 changed files with 24 additions and 11 deletions
|
|
@ -1,4 +1,4 @@
|
|||
import { useCallback, useEffect, useMemo, useState } from 'react';
|
||||
import { useCallback, useMemo, useState } from 'react';
|
||||
|
||||
import { MarkdownViewer } from '@renderer/components/chat/viewers/MarkdownViewer';
|
||||
import { ReplyQuoteBlock } from '@renderer/components/team/activity/ReplyQuoteBlock';
|
||||
|
|
@ -54,11 +54,15 @@ export const TaskCommentsSection = ({
|
|||
const [expandedCommentIds, setExpandedCommentIds] = useState<Set<string>>(new Set());
|
||||
const [visibleCount, setVisibleCount] = useState(INITIAL_VISIBLE_COMMENTS);
|
||||
|
||||
useEffect(() => {
|
||||
// Reset state when task changes (React-approved setState-during-render pattern)
|
||||
const resetKey = teamIdKey(teamName, taskId);
|
||||
const [prevResetKey, setPrevResetKey] = useState(resetKey);
|
||||
if (prevResetKey !== resetKey) {
|
||||
setPrevResetKey(resetKey);
|
||||
setVisibleCount(INITIAL_VISIBLE_COMMENTS);
|
||||
setExpandedCommentIds(new Set());
|
||||
setReplyTo(null);
|
||||
}, [teamIdKey(teamName, taskId)]);
|
||||
}
|
||||
|
||||
const toggleCommentExpanded = useCallback((commentId: string) => {
|
||||
setExpandedCommentIds((prev) => {
|
||||
|
|
|
|||
|
|
@ -37,22 +37,31 @@ export const QuickOpenDialog = ({
|
|||
const [allFiles, setAllFiles] = useState<QuickOpenFile[]>([]);
|
||||
const [loading, setLoading] = useState(true);
|
||||
|
||||
// Load all project files on mount via backend API
|
||||
// Reset state when projectPath changes (React-approved setState-during-render pattern)
|
||||
const [prevProjectPath, setPrevProjectPath] = useState(projectPath);
|
||||
if (prevProjectPath !== projectPath) {
|
||||
setPrevProjectPath(projectPath);
|
||||
setLoading(true);
|
||||
setAllFiles([]);
|
||||
}
|
||||
|
||||
// Load all project files via backend API
|
||||
useEffect(() => {
|
||||
let cancelled = false;
|
||||
setLoading(true);
|
||||
|
||||
window.electronAPI.editor
|
||||
.listFiles()
|
||||
.then((files) => {
|
||||
const fetchFiles = async (): Promise<void> => {
|
||||
try {
|
||||
const files = await window.electronAPI.editor.listFiles();
|
||||
if (!cancelled) {
|
||||
setAllFiles(files);
|
||||
setLoading(false);
|
||||
}
|
||||
})
|
||||
.catch(() => {
|
||||
} catch {
|
||||
if (!cancelled) setLoading(false);
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
void fetchFiles();
|
||||
|
||||
return () => {
|
||||
cancelled = true;
|
||||
|
|
|
|||
Loading…
Reference in a new issue