Skip to content

Commit 87e371f

Browse files
committed
Added prevention of nested chapters on sort
1 parent b649738 commit 87e371f

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

resources/js/components/book-sort.js

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,8 @@ export class BookSort extends Component {
260260
animation: 150,
261261
fallbackOnBody: true,
262262
swapThreshold: 0.65,
263-
onSort: () => {
263+
onSort: (event) => {
264+
this.ensureNoNestedChapters()
264265
this.updateMapInput();
265266
this.updateMoveActionStateForAll();
266267
},
@@ -273,6 +274,20 @@ export class BookSort extends Component {
273274
}
274275
}
275276

277+
/**
278+
* Handle nested chapters by moving them to the parent book.
279+
* Needed since sorting with multi-sort only checks group rules based on the active item,
280+
* not all in group, therefore need to manually check after a sort.
281+
* Must be done before updating the map input.
282+
*/
283+
ensureNoNestedChapters() {
284+
const nestedChapters = this.container.querySelectorAll('[data-type="chapter"] [data-type="chapter"]');
285+
for (const chapter of nestedChapters) {
286+
const parentChapter = chapter.parentElement.closest('[data-type="chapter"]');
287+
parentChapter.insertAdjacentElement('afterend', chapter);
288+
}
289+
}
290+
276291
/**
277292
* Update the input with our sort data.
278293
*/

0 commit comments

Comments
 (0)