Changeset 7fbb91c for chapterx-frontend/src/store/storyStore.ts
- Timestamp:
- 03/24/26 23:03:39 (3 months ago)
- Branches:
- main
- Children:
- a7550ca
- Parents:
- 73b69b2
- File:
-
- 1 edited
-
chapterx-frontend/src/store/storyStore.ts (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
chapterx-frontend/src/store/storyStore.ts
r73b69b2 r7fbb91c 73 73 fetchStories: () => Promise<void> 74 74 fetchChapters: () => Promise<void> 75 fetchCollaborations: () => Promise<void> 75 76 fetchReadingLists: () => Promise<void> 76 77 fetchUserReadingLists: (userId: number) => Promise<void> … … 98 99 99 100 // Collaboration actions 100 addCollaboration: (collab: Collaboration) => void101 addCollaboration: (collab: Collaboration) => Promise<void> 101 102 updateCollaborationPermission: (userId: number, storyId: number, level: PermissionLevel) => void 102 removeCollaboration: (userId: number, storyId: number) => void103 removeCollaboration: (userId: number, storyId: number) => Promise<void> 103 104 104 105 // AI Suggestion actions … … 175 176 } catch { 176 177 // keep mock data on failure 178 } 179 }, 180 181 fetchCollaborations: async () => { 182 try { 183 const res = await axios.get(`${API}/collaborations`) 184 const data: any[] = res.data ?? [] 185 const collaborations: Collaboration[] = data.map((c: any) => ({ 186 collab_id: c.id, 187 story_id: c.storyId, 188 user_id: c.userId, 189 username: c.username ?? '', 190 name: c.name ?? c.username ?? '', 191 story_title: '', 192 role: 'editor' as any, 193 permission_level: 3 as any, 194 joined_at: c.createdAt, 195 })) 196 set({ collaborations }) 197 } catch { 198 // keep existing 177 199 } 178 200 }, … … 364 386 get().likedStories.some(l => l.userId === userId && l.storyId === storyId), 365 387 366 addCollaboration: (collab) => 367 set(state => ({ collaborations: [...state.collaborations, collab] })), 388 addCollaboration: async (collab) => { 389 set(state => ({ collaborations: [...state.collaborations, collab] })) 390 try { 391 await axios.post(`${API}/collaborations`, { 392 userId: collab.user_id, 393 storyId: collab.story_id, 394 role: collab.role, 395 }, { headers: getAuthHeaders() }) 396 } catch { 397 // keep optimistic 398 } 399 }, 368 400 369 401 updateCollaborationPermission: (userId, storyId, level) => … … 376 408 })), 377 409 378 removeCollaboration: (userId, storyId) =>410 removeCollaboration: async (userId, storyId) => { 379 411 set(state => ({ 380 412 collaborations: state.collaborations.filter( 381 413 c => !(c.user_id === userId && c.story_id === storyId) 382 414 ), 383 })), 415 })) 416 try { 417 await axios.delete(`${API}/collaborations/user/${userId}/story/${storyId}`, { headers: getAuthHeaders() }) 418 } catch { 419 // keep optimistic 420 } 421 }, 384 422 385 423 fetchSuggestions: async () => {
Note:
See TracChangeset
for help on using the changeset viewer.
