Changeset a6e33d1 for chapterx-frontend/src/store/storyStore.ts
- Timestamp:
- 07/02/26 23:35:59 (3 days ago)
- Branches:
- main
- Parents:
- 3ae4bab
- File:
-
- 1 edited
-
chapterx-frontend/src/store/storyStore.ts (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
chapterx-frontend/src/store/storyStore.ts
r3ae4bab ra6e33d1 7 7 Collaboration, 8 8 AISuggestion, 9 SuggestionType, 9 10 Genre, 10 11 ReadingList, … … 105 106 106 107 // AI Suggestion actions 107 fetchSuggestions: ( ) => Promise<void>108 fetchSuggestions: (chapterId: number) => Promise<void> 108 109 acceptSuggestion: (id: number) => Promise<void> 109 110 rejectSuggestion: (id: number) => Promise<void> … … 434 435 }, 435 436 436 fetchSuggestions: async ( ) => {437 try { 438 const res = await axios.get(`${API}/aisuggestions `)439 const data = res.data.aiSuggestions ?? res.data437 fetchSuggestions: async (chapterId) => { 438 try { 439 const res = await axios.get(`${API}/aisuggestions/chapter/${chapterId}`) 440 const data: any[] = res.data ?? [] 440 441 const mapped: AISuggestion[] = data.map((s: any) => ({ 441 442 suggestion_id: s.id, 442 chapter_id: s.storyId,443 chapter_id: chapterId, 443 444 story_id: s.storyId, 444 445 original_text: s.originalText, 445 446 suggested_text: s.suggestedText, 446 suggestion_type: 'style' as const,447 suggestion_type: (s.suggestionTypes?.[0] ?? 'style') as SuggestionType, 447 448 accepted: s.accepted === true ? true : s.accepted === false ? false : null, 448 449 applied_at: s.appliedAt ?? undefined, … … 471 472 suggestedText: s.suggested_text, 472 473 accepted: true, 473 } )474 }, { headers: getAuthHeaders() }) 474 475 } catch { 475 476 // keep optimistic update even if backend fails … … 491 492 suggestedText: s.suggested_text, 492 493 accepted: false, 493 } )494 }, { headers: getAuthHeaders() }) 494 495 } catch { 495 496 // keep optimistic update even if backend fails … … 502 503 set(state => ({ aiSuggestions: [...state.aiSuggestions, { ...suggestion, suggestion_id: tempId }] })) 503 504 try { 504 const res = await axios.post( '${API}/aisuggestions', {505 const res = await axios.post(`${API}/aisuggestions`, { 505 506 originalText: suggestion.original_text, 506 507 suggestedText: suggestion.suggested_text, 507 508 storyId: suggestion.chapter_id, 508 } )509 }, { headers: getAuthHeaders() }) 509 510 const newId = res.data.id ?? tempId 510 511 set(state => ({
Note:
See TracChangeset
for help on using the changeset viewer.
