feat(series): flat series sequence + cosmetic chapter dividers (#789 Phase 1)
Reframe a series from "ordered chapters that own pages" to ONE flat, series-global ordered run of pages with optional cosmetic chapter DIVIDERS over it. A chapter no longer wraps content — it's a labeled divider anchored to the page that begins it; a page's chapter is derived as the nearest preceding divider. This is what lets installments assembled from multiple sources sit in one continuous, correctly-numbered sequence (operator's Goblin Juice case). - migration 0047: flatten each series to a series-global page_number (preserving today's reading order); convert each existing chapter to a divider anchored at its first page (keeping title/stated_part); drop series_page.chapter_id; reshape series_chapter (anchor_page_id UNIQUE FK, drop chapter_number/is_placeholder/stated_page_start/end). Loss-safe for content; drops empty placeholder chapters + a redundant page-1 divider. - series_page: page_number is now the series-global order; no chapter_id. - series_chapter: anchored divider (anchor_page_id, title, stated_part). - series_service: flat list_pages (one run + derived dividers + per-page source_post + part_gaps), series-wide reorder/renumber, divider CRUD (create/update/move/delete); retired per-chapter reorder/merge/placement. - api/tags: drop chapter_id from add; /chapters endpoints are divider create/update/delete (removed chapter reorder/merge/page-reorder). - series_match_service: series "end" reads max(series_page.stated_page); accept appends via add_post. tag_service series-merge appends src's pages after tgt's max so the merged series stays one clean run. - frontend: seriesManage store + SeriesManageView → one continuous drag-reorder grid with inline divider bars + series-global page numbers; reader walks the flat run, headings from dividers; PostSeriesMenu copy. - tests reworked across the series suite for the divider model. Phase 2 (pending staging for add-from-post) is separate. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -13,17 +13,14 @@ function stubFetch(handler) {
|
||||
})
|
||||
}
|
||||
|
||||
// FC-6.x: a flat page run + cosmetic chapter dividers.
|
||||
const SERIES_BODY = {
|
||||
series: { id: 7, name: 'V' },
|
||||
chapters: [
|
||||
{
|
||||
id: 1, chapter_number: 1, title: null, is_placeholder: false,
|
||||
stated_page_start: null, stated_page_end: null,
|
||||
pages: [{ image_id: 1, page_number: 1, thumbnail_url: 't' }]
|
||||
}
|
||||
pages: [{ image_id: 1, page_number: 1, thumbnail_url: 't', source_post: null }],
|
||||
dividers: [
|
||||
{ id: 1, anchor_image_id: 1, page_number: 1, title: null, stated_part: null }
|
||||
],
|
||||
gaps: [],
|
||||
pages: [{ image_id: 1, page_number: 1, thumbnail_url: 't' }]
|
||||
part_gaps: []
|
||||
}
|
||||
|
||||
describe('seriesManage', () => {
|
||||
@@ -35,17 +32,17 @@ describe('seriesManage', () => {
|
||||
expect(moveItem([1, 2, 3], 0, 2)).toEqual([2, 3, 1])
|
||||
})
|
||||
|
||||
it('load fetches chapters + series and picks a default target', async () => {
|
||||
it('load fetches the flat pages + dividers + series', async () => {
|
||||
const s = useSeriesManageStore()
|
||||
stubFetch(() => ({ status: 200, body: SERIES_BODY }))
|
||||
await s.load(7)
|
||||
expect(s.series).toEqual({ id: 7, name: 'V' })
|
||||
expect(s.chapters.map(c => c.id)).toEqual([1])
|
||||
expect(s.pages.map(p => p.image_id)).toEqual([1])
|
||||
expect(s.dividers.map(d => d.id)).toEqual([1])
|
||||
expect(s.pageCount).toBe(1)
|
||||
expect(s.targetChapterId).toBe(1)
|
||||
})
|
||||
|
||||
it('reorderPages posts ordered ids to the chapter reorder route', async () => {
|
||||
it('reorder posts ordered ids to the series reorder route', async () => {
|
||||
const s = useSeriesManageStore()
|
||||
s.tagId = 7
|
||||
const calls = []
|
||||
@@ -54,28 +51,29 @@ describe('seriesManage', () => {
|
||||
if (url.includes('/reorder')) return { status: 200, body: { ok: true } }
|
||||
return { status: 200, body: SERIES_BODY }
|
||||
})
|
||||
await s.reorderPages(3, [30, 10, 20])
|
||||
const r = calls.find(c => c.url.includes('/chapters/3/reorder'))
|
||||
expect(r.url).toContain('/api/series/7/chapters/3/reorder')
|
||||
await s.reorder([30, 10, 20])
|
||||
const r = calls.find(c => c.url.includes('/reorder'))
|
||||
expect(r.url).toContain('/api/series/7/reorder')
|
||||
expect(r.body).toEqual({ image_ids: [30, 10, 20] })
|
||||
})
|
||||
|
||||
it('moveChapter reorders via the chapter id list', async () => {
|
||||
it('createDivider posts the anchor image + labels', async () => {
|
||||
const s = useSeriesManageStore()
|
||||
s.tagId = 7
|
||||
s.chapters = [{ id: 1 }, { id: 2 }, { id: 3 }]
|
||||
const calls = []
|
||||
stubFetch((url, init) => {
|
||||
calls.push({ url, body: init.body ? JSON.parse(init.body) : null })
|
||||
if (url.includes('/chapters/reorder')) return { status: 200, body: { ok: true } }
|
||||
calls.push({ url, method: init.method, body: init.body ? JSON.parse(init.body) : null })
|
||||
if (init.method === 'POST' && url.endsWith('/chapters'))
|
||||
return { status: 200, body: { id: 2, anchor_image_id: 5 } }
|
||||
return { status: 200, body: SERIES_BODY }
|
||||
})
|
||||
await s.moveChapter(2, -1)
|
||||
const r = calls.find(c => c.url.includes('/chapters/reorder'))
|
||||
expect(r.body).toEqual({ chapter_ids: [2, 1, 3] })
|
||||
await s.createDivider(5, { title: 'X', statedPart: 2 })
|
||||
const c = calls.find(x => x.method === 'POST' && x.url.endsWith('/chapters'))
|
||||
expect(c.url).toContain('/api/series/7/chapters')
|
||||
expect(c.body).toEqual({ anchor_image_id: 5, title: 'X', stated_part: 2 })
|
||||
})
|
||||
|
||||
it('setChapterPart patches stated_part on the chapter', async () => {
|
||||
it('setDividerPart patches stated_part on the divider', async () => {
|
||||
const s = useSeriesManageStore()
|
||||
s.tagId = 7
|
||||
const calls = []
|
||||
@@ -84,7 +82,7 @@ describe('seriesManage', () => {
|
||||
if (init.method === 'PATCH') return { status: 200, body: { ok: true } }
|
||||
return { status: 200, body: SERIES_BODY }
|
||||
})
|
||||
await s.setChapterPart(1, 2)
|
||||
await s.setDividerPart(1, 2)
|
||||
const p = calls.find(c => c.method === 'PATCH')
|
||||
expect(p.url).toContain('/api/series/7/chapters/1')
|
||||
expect(p.body).toEqual({ stated_part: 2 })
|
||||
@@ -94,18 +92,25 @@ describe('seriesManage', () => {
|
||||
const s = useSeriesManageStore()
|
||||
stubFetch(() => ({
|
||||
status: 200,
|
||||
body: { ...SERIES_BODY, part_gaps: [{ after_chapter_id: 1, start: 2, end: 2 }] }
|
||||
body: { ...SERIES_BODY, part_gaps: [{ after_divider_id: 1, start: 2, end: 2 }] }
|
||||
}))
|
||||
await s.load(7)
|
||||
expect(s.partGaps).toHaveLength(1)
|
||||
expect(s.partGapAfter(1)).toEqual({ after_chapter_id: 1, start: 2, end: 2 })
|
||||
expect(s.partGapAfter(1)).toEqual({ after_divider_id: 1, start: 2, end: 2 })
|
||||
expect(s.partGapAfter(99)).toBeNull()
|
||||
})
|
||||
|
||||
it('addSelected posts selection + target chapter then clears', async () => {
|
||||
it('dividerAt finds a divider by its anchor image', async () => {
|
||||
const s = useSeriesManageStore()
|
||||
stubFetch(() => ({ status: 200, body: SERIES_BODY }))
|
||||
await s.load(7)
|
||||
expect(s.dividerAt(1)?.id).toBe(1)
|
||||
expect(s.dividerAt(99)).toBeNull()
|
||||
})
|
||||
|
||||
it('addSelected posts the selection (no chapter) then clears', async () => {
|
||||
const s = useSeriesManageStore()
|
||||
s.tagId = 7
|
||||
s.targetChapterId = 5
|
||||
s.pickerSelection = [9, 10]
|
||||
const calls = []
|
||||
stubFetch((url, init) => {
|
||||
@@ -116,7 +121,7 @@ describe('seriesManage', () => {
|
||||
})
|
||||
await s.addSelected()
|
||||
const add = calls.find(c => c.url.endsWith('/api/series/7/pages'))
|
||||
expect(add.body).toEqual({ image_ids: [9, 10], chapter_id: 5 })
|
||||
expect(add.body).toEqual({ image_ids: [9, 10] })
|
||||
expect(s.pickerSelection).toEqual([])
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user