mirror of
https://github.com/laurent22/joplin.git
synced 2024-12-21 09:38:01 +02:00
Chore: Refactor sidebar utilities to TypeScript
This commit is contained in:
parent
17bdec22ca
commit
97af8cb7f5
@ -662,6 +662,7 @@ packages/lib/components/shared/config/shouldShowMissingPasswordWarning.test.js
|
||||
packages/lib/components/shared/config/shouldShowMissingPasswordWarning.js
|
||||
packages/lib/components/shared/note-screen-shared.js
|
||||
packages/lib/components/shared/reduxSharedMiddleware.js
|
||||
packages/lib/components/shared/side-menu-shared.js
|
||||
packages/lib/database-driver-better-sqlite.js
|
||||
packages/lib/database.js
|
||||
packages/lib/debug/DebugService.js
|
||||
|
1
.gitignore
vendored
1
.gitignore
vendored
@ -642,6 +642,7 @@ packages/lib/components/shared/config/shouldShowMissingPasswordWarning.test.js
|
||||
packages/lib/components/shared/config/shouldShowMissingPasswordWarning.js
|
||||
packages/lib/components/shared/note-screen-shared.js
|
||||
packages/lib/components/shared/reduxSharedMiddleware.js
|
||||
packages/lib/components/shared/side-menu-shared.js
|
||||
packages/lib/database-driver-better-sqlite.js
|
||||
packages/lib/database.js
|
||||
packages/lib/debug/DebugService.js
|
||||
|
@ -27,7 +27,7 @@ import FolderIconBox from '../FolderIconBox';
|
||||
import { Theme } from '@joplin/lib/themes/type';
|
||||
import { RuntimeProps } from './commands/focusElementSideBar';
|
||||
const { connect } = require('react-redux');
|
||||
const shared = require('@joplin/lib/components/shared/side-menu-shared.js');
|
||||
import { renderFolders, renderTags } from '@joplin/lib/components/shared/side-menu-shared';
|
||||
const { themeStyle } = require('@joplin/lib/theme');
|
||||
const bridge = require('@electron/remote').require('./bridge').default;
|
||||
const Menu = bridge().Menu;
|
||||
@ -704,7 +704,7 @@ const SidebarComponent = (props: Props) => {
|
||||
|
||||
if (props.folders.length) {
|
||||
const allNotesSelected = props.notesParentType === 'SmartFilter' && props.selectedSmartFilterId === ALL_NOTES_FILTER_ID;
|
||||
const result = shared.renderFolders(props, renderFolderItem);
|
||||
const result = renderFolders(props, renderFolderItem);
|
||||
const folderItems = [renderAllNotesItem(theme, allNotesSelected)].concat(result.items);
|
||||
folderItemsOrder_.current = result.order;
|
||||
items.push(
|
||||
@ -725,7 +725,7 @@ const SidebarComponent = (props: Props) => {
|
||||
);
|
||||
|
||||
if (props.tags.length) {
|
||||
const result = shared.renderTags(props, renderTag);
|
||||
const result = renderTags(props, renderTag);
|
||||
const tagItems = result.items;
|
||||
tagItemsOrder_.current = result.order;
|
||||
|
||||
|
@ -8,7 +8,7 @@ import Synchronizer from '@joplin/lib/Synchronizer';
|
||||
import NavService from '@joplin/lib/services/NavService';
|
||||
import { _ } from '@joplin/lib/locale';
|
||||
const { themeStyle } = require('./global-style.js');
|
||||
const shared = require('@joplin/lib/components/shared/side-menu-shared.js');
|
||||
import { renderFolders } from '@joplin/lib/components/shared/side-menu-shared';
|
||||
import { FolderEntity, FolderIcon } from '@joplin/lib/services/database/types';
|
||||
import { AppState } from '../utils/types';
|
||||
import Setting from '@joplin/lib/models/Setting';
|
||||
@ -37,6 +37,8 @@ interface Props {
|
||||
opacity: number;
|
||||
profileConfig: ProfileConfig;
|
||||
inboxJopId: string;
|
||||
selectedFolderId: string;
|
||||
selectedTagId: string;
|
||||
}
|
||||
|
||||
const syncIconRotationValue = new Animated.Value(0);
|
||||
@ -488,7 +490,7 @@ const SideMenuContentComponent = (props: Props) => {
|
||||
items.push(renderSidebarButton('folder_header', _('Notebooks'), 'folder'));
|
||||
|
||||
if (props.folders.length) {
|
||||
const result = shared.renderFolders(props, renderFolderItem, false);
|
||||
const result = renderFolders(props, renderFolderItem);
|
||||
const folderItems = result.items;
|
||||
items = items.concat(folderItems);
|
||||
}
|
||||
|
@ -1,9 +1,20 @@
|
||||
const Folder = require('../../models/Folder').default;
|
||||
const BaseModel = require('../../BaseModel').default;
|
||||
import Folder from '../../models/Folder';
|
||||
import BaseModel from '../../BaseModel';
|
||||
import { FolderEntity, TagEntity } from '../../services/database/types';
|
||||
|
||||
const shared = {};
|
||||
interface Props {
|
||||
folders: FolderEntity[];
|
||||
selectedFolderId: string;
|
||||
notesParentType: string;
|
||||
collapsedFolderIds: string[];
|
||||
selectedTagId: string;
|
||||
tags?: TagEntity[];
|
||||
}
|
||||
|
||||
function folderHasChildren_(folders, folderId) {
|
||||
type RenderFolderItem = (folder: FolderEntity, selected: boolean, hasChildren: boolean, depth: number)=> any;
|
||||
type RenderTagItem = (tag: TagEntity, selected: boolean)=> any;
|
||||
|
||||
function folderHasChildren_(folders: FolderEntity[], folderId: string) {
|
||||
for (let i = 0; i < folders.length; i++) {
|
||||
const folder = folders[i];
|
||||
if (folder.parent_id === folderId) return true;
|
||||
@ -11,7 +22,7 @@ function folderHasChildren_(folders, folderId) {
|
||||
return false;
|
||||
}
|
||||
|
||||
function folderIsVisible(folders, folderId, collapsedFolderIds) {
|
||||
function folderIsVisible(folders: FolderEntity[], folderId: string, collapsedFolderIds: string[]) {
|
||||
if (!collapsedFolderIds || !collapsedFolderIds.length) return true;
|
||||
|
||||
while (true) {
|
||||
@ -23,7 +34,7 @@ function folderIsVisible(folders, folderId, collapsedFolderIds) {
|
||||
}
|
||||
}
|
||||
|
||||
function renderFoldersRecursive_(props, renderItem, items, parentId, depth, order) {
|
||||
function renderFoldersRecursive_(props: Props, renderItem: RenderFolderItem, items: any[], parentId: string, depth: number, order: string[]) {
|
||||
const folders = props.folders;
|
||||
for (let i = 0; i < folders.length; i++) {
|
||||
const folder = folders[i];
|
||||
@ -44,11 +55,11 @@ function renderFoldersRecursive_(props, renderItem, items, parentId, depth, orde
|
||||
};
|
||||
}
|
||||
|
||||
shared.renderFolders = function(props, renderItem) {
|
||||
export const renderFolders = (props: Props, renderItem: RenderFolderItem) => {
|
||||
return renderFoldersRecursive_(props, renderItem, [], '', 0, []);
|
||||
};
|
||||
|
||||
shared.renderTags = function(props, renderItem) {
|
||||
export const renderTags = (props: Props, renderItem: RenderTagItem) => {
|
||||
const tags = props.tags.slice();
|
||||
tags.sort((a, b) => {
|
||||
// It seems title can sometimes be undefined (perhaps when syncing
|
||||
@ -75,5 +86,3 @@ shared.renderTags = function(props, renderItem) {
|
||||
order: order,
|
||||
};
|
||||
};
|
||||
|
||||
module.exports = shared;
|
Loading…
Reference in New Issue
Block a user