Ignore:
Timestamp:
06/24/26 16:28:50 (11 days ago)
Author:
kikisrbinoska <srbinoskakristina07@…>
Branches:
main
Children:
a8f4a2d
Parents:
0b502c2
Message:

Fixed writer section and admin management

File:
1 edited

Legend:

Unmodified
Added
Removed
  • chapterx-frontend/src/store/storyStore.ts

    r0b502c2 r99c1e45  
    138138        story_id: s.id,
    139139        user_id: s.userId,
    140         title: s.shortDescription,
    141         short_description: s.shortDescription,
    142         content: s.content,
     140        title: s.title ?? '',
     141        short_description: s.shortDescription ?? '',
     142        content: s.content ?? '',
     143        cover_image: s.image ?? undefined,
    143144        mature_content: s.matureContent,
    144145        status: 'published' as StoryStatus,
     
    203204  addStory: async (story) => {
    204205    set(state => ({ stories: [...state.stories, story] }))
     206    const imageUrl = story.cover_image?.startsWith('http') ? story.cover_image : null
    205207    const res = await axios.post(`${API}/stories`, {
    206208      matureContent: story.mature_content,
    207       shortDescription: story.short_description || story.title,
    208       image: null,
     209      title: story.title,
     210      shortDescription: story.short_description,
     211      image: imageUrl,
    209212      content: story.content,
    210213      userId: story.user_id,
     
    233236      const story = get().stories.find(s => s.story_id === id)
    234237      if (!story) return
     238      const rawImage = partial.cover_image ?? story.cover_image ?? null
     239      const imageUrl = rawImage?.startsWith('http') ? rawImage : null
    235240      await axios.put(`${API}/stories/${id}`, {
    236241        id,
    237242        matureContent: partial.mature_content ?? story.mature_content,
    238         shortDescription: partial.title ?? partial.short_description ?? story.title ?? story.short_description,
    239         image: null,
     243        title: partial.title ?? story.title,
     244        shortDescription: partial.short_description ?? story.short_description,
     245        image: imageUrl,
    240246        content: partial.content ?? story.content,
    241247      }, { headers: getAuthHeaders() })
     
    335341  },
    336342
    337   incrementViewCount: (chapterId) =>
     343  incrementViewCount: (chapterId) => {
     344    const chapter = get().chapters.find(c => c.chapter_id === chapterId)
    338345    set(state => ({
    339346      chapters: state.chapters.map(c =>
    340347        c.chapter_id === chapterId ? { ...c, view_count: c.view_count + 1 } : c
    341348      ),
    342     })),
     349      stories: state.stories.map(s =>
     350        s.story_id === chapter?.story_id ? { ...s, total_views: s.total_views + 1 } : s
     351      ),
     352    }))
     353    axios.patch(`${API}/chapters/${chapterId}/view`, null, { headers: getAuthHeaders() }).catch(() => {})
     354  },
    343355
    344356  addComment: (comment) =>
Note: See TracChangeset for help on using the changeset viewer.