Skip to content

Commit

Permalink
fix: use loadBook in sidenav, fix sidenav nesting bug
Browse files Browse the repository at this point in the history
  • Loading branch information
maxakuru committed Oct 2, 2023
1 parent 163bb57 commit 81b7a39
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions prisma/prisma-cloud/blocks/sidenav/sidenav.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
html,
isMobile,
loadArticle,
loadBook,
parseFragment,
render,
} from '../../scripts/scripts.js';
Expand Down Expand Up @@ -508,6 +509,7 @@ function sortBook(book) {
const topics = book.topics.data;
topics.forEach(({ chapter, parent, ...topic }) => {
let parentItem = data.chapters.find(({ key }) => key === chapter);

if (parent) {
const parts = parent.split('/');
while (parts.length) {
Expand All @@ -519,6 +521,7 @@ function sortBook(book) {
parentItem.children = parentItem.children || [];
parentItem.children.push(topic);
});

return data;
}

Expand Down Expand Up @@ -614,13 +617,16 @@ function bookToList(book) {

if (topic.children && topic.children.length) {
if (hasSubtopics(topic)) {
const prevTopicList = current;

addSubList(
topic.name,
`${book.path}/${chapter.key}/${parentKey ? `${parentKey}/` : ''}${topic.key}/${
topic.key
}`,
topic.key,
);

topic.children.forEach((subtopic) => {
processTopic(
subtopic,
Expand All @@ -629,6 +635,9 @@ function bookToList(book) {
}`,
);
});

// revert to previous list level
current = prevTopicList;
} else {
// has children, but not subtopics to render
// this means the link on the parent is actually the child's link
Expand Down Expand Up @@ -744,8 +753,7 @@ function initAdditionalBooks(block, container) {
'mouseenter',
async () => {
container.querySelectorAll('[data-additional-book-href]').forEach((list) => {
store
.fetchJSON(list.dataset.additionalBookHref, ['default', 'chapters', 'topics'], { limit: 10000 })
loadBook(list.dataset.additionalBookHref)
.then((data) => {
const sorted = sortBook(data);
renderTOC(container, sorted, false, list);
Expand Down

0 comments on commit 81b7a39

Please sign in to comment.