Frontend — store (Zustand) - xxriny/KNU-PROJECT GitHub Wiki

1. src/store/useAppStore.js

라인 코드 설명
1–38 import + 초기 상태 zustand, 슬라이스, 헬퍼 함수, WS/파이프라인/결과/뷰포트/채팅/세션 상태
40–91 _handleWsMessage() WS 메시지 type 분기: 'status' / 'thinking' / 'result' / 'error' / 'pong'
92–131 파이프라인 실행 startAnalysis()(L92), startRevision()(L116), sendIdeaChat()(L132) — sendWsMessage() 호출
163–188 _processResult() 파이프라인 결과 → spreadResultData() 통해 각 필드 분배
189–240 Viewport/Tab 관리 activateCodeTab()(L189), activateOutputTab()(L191), openFile()(L196), updateOpenFileContent()(L209), closeFile()(L222)
241–261 채팅/파일 addChatMessage()(L241), setChatInput()(L247), clearChat()(L249), setFileTree()(L259)
263–390 프로젝트 관리 ensureProjectFolderAccess()(L263), selectAndScanFolder()(L286), openProjectFile()(L310), detectLanguage()(L391)
411–517 세션 CRUD createSession()(L411), saveCurrentSession()(L448), loadSession()(L481), deleteSession()(L518)
565–581 resetPipeline() 파이프라인 상태 초기화

2. src/store/storeHelpers.js

라인 코드 설명
5 SESSION_STORAGE_KEY localStorage 키
6 DEFAULT_VIEWPORT_TAB 기본 뷰포트 탭
8 MODE_TO_ACTION_TYPE UI 모드 → 백엔드 액션 타입 매핑
14 MODE_TO_PIPELINE_TYPE UI 모드 → 파이프라인 타입 매핑
20 normalizeMode() 문자열 정규화(create/update/reverse)
24–37 세션 유틸 loadSessions()/persistSessions() — localStorage JSON 직렬화
38–51 탭/결과 유틸 cloneViewportTab(), normalizeOutputTabId(), extractRunId()
59–71 inferPipelineTypeFromResult() 결과 구조에서 파이프라인 타입 추론
72–91 EMPTY_RESULT_FIELDS 빈 결과 상태 초기값
92–117 spreadResultData() 파이프라인 결과 → 스토어 각 필드 분배

3. src/store/slices/wsSlice.js

라인 코드 설명
1–9 초기 상태 WS 연결 상태, setBackendPort(), setWsStatus()
11–48 connectWebSocket() new WebSocket(), onmessage_handleWsMessage() 위임, onclose → 3초 후 재연결
49–58 sendWsMessage() JSON 직렬화 전송

4. src/store/slices/configSlice.js

라인 코드 설명
1–30 createConfigSlice() apiKey, model, fetchConfig()GET /api/config → 기본 모델/버전 수신

5. src/store/debounce.js

라인 코드 설명
1–12 debounce() 범용 디바운스(기본 500ms) — 자동저장에 사용