Commit ed30ec57 authored by Yannis Barlas's avatar Yannis Barlas
Browse files

port chapter number implementation from old repo

parent b4311f14
......@@ -36,6 +36,7 @@ export class Division extends React.Component {
},
lock: null,
number: group === 'chapter' ? (chapters.filter(item => item.subCategory === 'chapter').length + 1) : undefined,
index: chapters.length || 0,
kind: 'chapter',
title: (type === 'body') ? 'Untitled' : 'Choose Component',
......@@ -77,6 +78,7 @@ export class Division extends React.Component {
const { book, chapters, update } = this.props
const dragChapter = chapters[dragIndex]
const hoverChapter = chapters[hoverIndex]
let toUpdate = []
......@@ -88,10 +90,12 @@ export class Division extends React.Component {
})
// build the patches for the chapters' updates
const patches = _.map(toModify, chapter => {
const patches = _.map(toModify, (chapter) => {
const number = (chapter.number ? chapter.number + 1 : undefined)
return {
id: chapter.id,
index: (chapter.index + 1)
index: (chapter.index + 1),
number: (dragChapter.subCategory === 'part') ? undefined : number
}
})
......@@ -106,10 +110,12 @@ export class Division extends React.Component {
return c.index <= hoverIndex && c.index > dragIndex
})
const patches = _.map(toModify, chapter => {
const patches = _.map(toModify, (chapter) => {
const number = (chapter.number ? chapter.number - 1 : undefined)
return {
id: chapter.id,
index: (chapter.index - 1)
index: (chapter.index - 1),
number: (dragChapter.subCategory === 'part') ? undefined : number
}
})
......@@ -119,7 +125,8 @@ export class Division extends React.Component {
// add the dragged chapter to the list of patches that are needed
const draggedPatch = {
id: dragChapter.id,
index: hoverIndex
index: hoverIndex,
number: (hoverChapter.number ? hoverChapter.number : undefined)
}
toUpdate.push(draggedPatch)
......
......@@ -24,7 +24,7 @@ import Dashboard from 'pubsweet-component-editoria-dashboard/src/Dashboard'
// Pass configuration to editor
const Editor = WithConfig(Wax, {
layout: 'default',
layout: 'editoria',
lockWhenEditing: true
})
......
......@@ -95,6 +95,7 @@ module.exports = {
index: Joi.number(),
kind: Joi.string(),
lock: Joi.object().allow(null),
number: Joi.number(),
progress: Joi.object(),
source: Joi.string().allow(''),
status: Joi.string(),
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment