You've already forked joplin
mirror of
https://github.com/laurent22/joplin.git
synced 2025-06-15 23:00:36 +02:00
All: Handle saving collapsed states of sub-notebook
This commit is contained in:
@ -1,5 +1,6 @@
|
||||
const ArrayUtils = require('lib/ArrayUtils');
|
||||
const Folder = require('lib/models/Folder');
|
||||
const BaseModel = require('lib/BaseModel');
|
||||
|
||||
let shared = {};
|
||||
|
||||
@ -11,11 +12,26 @@ function folderHasChildren_(folders, folderId) {
|
||||
return false;
|
||||
}
|
||||
|
||||
function folderIsVisible(folders, folderId, collapsedFolderIds) {
|
||||
if (!collapsedFolderIds || !collapsedFolderIds.length) return true;
|
||||
|
||||
while (true) {
|
||||
let folder = BaseModel.byId(folders, folderId);
|
||||
if (!folder) throw new Error('No folder with id ' + folder.id);
|
||||
if (!folder.parent_id) return true;
|
||||
if (collapsedFolderIds.indexOf(folder.parent_id) >= 0) return false;
|
||||
folderId = folder.parent_id;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
function renderFoldersRecursive_(props, renderItem, items, parentId, depth) {
|
||||
const folders = props.folders;
|
||||
for (let i = 0; i < folders.length; i++) {
|
||||
let folder = folders[i];
|
||||
if (!Folder.idsEqual(folder.parent_id, parentId)) continue;
|
||||
if (!folderIsVisible(props.folders, folder.id, props.collapsedFolderIds)) continue;
|
||||
const hasChildren = folderHasChildren_(folders, folder.id);
|
||||
items.push(renderItem(folder, props.selectedFolderId == folder.id && props.notesParentType == 'Folder', hasChildren, depth));
|
||||
if (hasChildren) items = renderFoldersRecursive_(props, renderItem, items, folder.id, depth + 1);
|
||||
|
Reference in New Issue
Block a user