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 { MarkdownViewer } from '@renderer/components/chat/viewers/MarkdownViewer';
|
||||||
import { ReplyQuoteBlock } from '@renderer/components/team/activity/ReplyQuoteBlock';
|
import { ReplyQuoteBlock } from '@renderer/components/team/activity/ReplyQuoteBlock';
|
||||||
|
|
@ -54,11 +54,15 @@ export const TaskCommentsSection = ({
|
||||||
const [expandedCommentIds, setExpandedCommentIds] = useState<Set<string>>(new Set());
|
const [expandedCommentIds, setExpandedCommentIds] = useState<Set<string>>(new Set());
|
||||||
const [visibleCount, setVisibleCount] = useState(INITIAL_VISIBLE_COMMENTS);
|
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);
|
setVisibleCount(INITIAL_VISIBLE_COMMENTS);
|
||||||
setExpandedCommentIds(new Set());
|
setExpandedCommentIds(new Set());
|
||||||
setReplyTo(null);
|
setReplyTo(null);
|
||||||
}, [teamIdKey(teamName, taskId)]);
|
}
|
||||||
|
|
||||||
const toggleCommentExpanded = useCallback((commentId: string) => {
|
const toggleCommentExpanded = useCallback((commentId: string) => {
|
||||||
setExpandedCommentIds((prev) => {
|
setExpandedCommentIds((prev) => {
|
||||||
|
|
|
||||||
|
|
@ -37,22 +37,31 @@ export const QuickOpenDialog = ({
|
||||||
const [allFiles, setAllFiles] = useState<QuickOpenFile[]>([]);
|
const [allFiles, setAllFiles] = useState<QuickOpenFile[]>([]);
|
||||||
const [loading, setLoading] = useState(true);
|
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(() => {
|
useEffect(() => {
|
||||||
let cancelled = false;
|
let cancelled = false;
|
||||||
setLoading(true);
|
|
||||||
|
|
||||||
window.electronAPI.editor
|
const fetchFiles = async (): Promise<void> => {
|
||||||
.listFiles()
|
try {
|
||||||
.then((files) => {
|
const files = await window.electronAPI.editor.listFiles();
|
||||||
if (!cancelled) {
|
if (!cancelled) {
|
||||||
setAllFiles(files);
|
setAllFiles(files);
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
}
|
}
|
||||||
})
|
} catch {
|
||||||
.catch(() => {
|
|
||||||
if (!cancelled) setLoading(false);
|
if (!cancelled) setLoading(false);
|
||||||
});
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
void fetchFiles();
|
||||||
|
|
||||||
return () => {
|
return () => {
|
||||||
cancelled = true;
|
cancelled = true;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue