Ignore:
Timestamp:
03/22/26 17:58:40 (4 months ago)
Author:
kikisrbinoska <srbinoskakristina07@…>
Branches:
main
Children:
73b69b2
Parents:
b62cefc
Message:

Added fixes for the login,stories management and reading lists

File:
1 edited

Legend:

Unmodified
Added
Removed
  • chapterx-frontend/src/pages/story/StoryDetailPage.tsx

    rb62cefc racf690c  
    3939  const myLists = currentUser ? readingLists.filter(l => l.user_id === currentUser.user_id) : []
    4040
    41   const handleAddToList = (listId: number) => {
     41  const handleAddToList = async (listId: number) => {
    4242    const list = readingLists.find(l => l.list_id === listId)
    4343    if (!list) return
     
    5555      genres: story.genres,
    5656    }
    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    }
    5968    setListModalOpen(false)
    6069  }
    6170
    62   const handleCreateList = () => {
     71  const handleCreateList = async () => {
    6372    if (!newListName.trim() || !currentUser) return
    6473    const newList = {
     
    6978      is_public: false,
    7079      created_at: new Date().toISOString(),
    71       stories: [{
     80      stories: [],
     81    }
     82    try {
     83      const realListId = await createReadingList(newList)
     84      await addStoryToList(realListId, {
    7285        item_id: Date.now() + 1,
    73         list_id: Date.now(),
     86        list_id: realListId,
    7487        story_id: story.story_id,
    7588        story_title: story.title,
     
    7790        added_at: new Date().toISOString(),
    7891        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    }
    8397    setNewListName('')
    8498    setListModalOpen(false)
Note: See TracChangeset for help on using the changeset viewer.