Changeset 99c1e45 for chapterx-frontend/src/store/storyStore.ts
- Timestamp:
- 06/24/26 16:28:50 (11 days ago)
- Branches:
- main
- Children:
- a8f4a2d
- Parents:
- 0b502c2
- File:
-
- 1 edited
-
chapterx-frontend/src/store/storyStore.ts (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
chapterx-frontend/src/store/storyStore.ts
r0b502c2 r99c1e45 138 138 story_id: s.id, 139 139 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, 143 144 mature_content: s.matureContent, 144 145 status: 'published' as StoryStatus, … … 203 204 addStory: async (story) => { 204 205 set(state => ({ stories: [...state.stories, story] })) 206 const imageUrl = story.cover_image?.startsWith('http') ? story.cover_image : null 205 207 const res = await axios.post(`${API}/stories`, { 206 208 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, 209 212 content: story.content, 210 213 userId: story.user_id, … … 233 236 const story = get().stories.find(s => s.story_id === id) 234 237 if (!story) return 238 const rawImage = partial.cover_image ?? story.cover_image ?? null 239 const imageUrl = rawImage?.startsWith('http') ? rawImage : null 235 240 await axios.put(`${API}/stories/${id}`, { 236 241 id, 237 242 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, 240 246 content: partial.content ?? story.content, 241 247 }, { headers: getAuthHeaders() }) … … 335 341 }, 336 342 337 incrementViewCount: (chapterId) => 343 incrementViewCount: (chapterId) => { 344 const chapter = get().chapters.find(c => c.chapter_id === chapterId) 338 345 set(state => ({ 339 346 chapters: state.chapters.map(c => 340 347 c.chapter_id === chapterId ? { ...c, view_count: c.view_count + 1 } : c 341 348 ), 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 }, 343 355 344 356 addComment: (comment) =>
Note:
See TracChangeset
for help on using the changeset viewer.
