Changeset acf690c for chapterx-frontend/src/pages/story
- Timestamp:
- 03/22/26 17:58:40 (4 months ago)
- Branches:
- main
- Children:
- 73b69b2
- Parents:
- b62cefc
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
chapterx-frontend/src/pages/story/StoryDetailPage.tsx
rb62cefc racf690c 39 39 const myLists = currentUser ? readingLists.filter(l => l.user_id === currentUser.user_id) : [] 40 40 41 const handleAddToList = (listId: number) => {41 const handleAddToList = async (listId: number) => { 42 42 const list = readingLists.find(l => l.list_id === listId) 43 43 if (!list) return … … 55 55 genres: story.genres, 56 56 } 57 addStoryToList(listId, item) 58 addToast(`Added to "${list.name}"!`) 57 try { 58 await addStoryToList(listId, item) 59 addToast(`Added to "${list.name}"!`) 60 } catch (err: any) { 61 const msg = err?.response?.data?.message || '' 62 if (msg.includes('already') || msg.includes('duplicate') || err?.response?.status === 400) { 63 addToast('Already in this list', 'info') 64 } else { 65 addToast('Failed to add to list.', 'error') 66 } 67 } 59 68 setListModalOpen(false) 60 69 } 61 70 62 const handleCreateList = () => {71 const handleCreateList = async () => { 63 72 if (!newListName.trim() || !currentUser) return 64 73 const newList = { … … 69 78 is_public: false, 70 79 created_at: new Date().toISOString(), 71 stories: [{ 80 stories: [], 81 } 82 try { 83 const realListId = await createReadingList(newList) 84 await addStoryToList(realListId, { 72 85 item_id: Date.now() + 1, 73 list_id: Date.now(),86 list_id: realListId, 74 87 story_id: story.story_id, 75 88 story_title: story.title, … … 77 90 added_at: new Date().toISOString(), 78 91 genres: story.genres, 79 }], 80 } 81 createReadingList(newList) 82 addToast(`Created "${newListName}" and added story!`) 92 }) 93 addToast(`Created "${newListName}" and added story!`) 94 } catch { 95 addToast('Failed to create list.', 'error') 96 } 83 97 setNewListName('') 84 98 setListModalOpen(false)
Note:
See TracChangeset
for help on using the changeset viewer.
