mirror of
https://github.com/laurent22/joplin.git
synced 2024-12-24 10:27:10 +02:00
This commit is contained in:
parent
8bdac6ffbf
commit
da393f6c34
@ -6,6 +6,7 @@ import { connect } from 'react-redux';
|
||||
import { FlatList, Text, StyleSheet, Button, View } from 'react-native';
|
||||
import { FolderEntity, NoteEntity } from '@joplin/lib/services/database/types';
|
||||
import { AppState } from '../utils/types';
|
||||
import Folder from '@joplin/lib/models/Folder';
|
||||
|
||||
const { _ } = require('@joplin/lib/locale');
|
||||
const { NoteItem } = require('./note-item.js');
|
||||
@ -90,7 +91,7 @@ class NoteListComponent extends Component<NoteListProps> {
|
||||
keyExtractor={item => item.id}
|
||||
/>;
|
||||
} else {
|
||||
if (!this.props.folders.length) {
|
||||
if (!Folder.atLeastOneRealFolderExists(this.props.folders)) {
|
||||
const noItemMessage = _('You currently have no notebooks.');
|
||||
return (
|
||||
<View style={this.styles().noNotebookView}>
|
||||
@ -106,6 +107,7 @@ class NoteListComponent extends Component<NoteListProps> {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
const NoteList = connect((state: AppState) => {
|
||||
return {
|
||||
items: state.notes,
|
||||
|
@ -238,7 +238,7 @@ class NotesScreenComponent extends BaseScreenComponent<any> {
|
||||
const thisComp = this;
|
||||
|
||||
const makeActionButtonComp = () => {
|
||||
if (this.props.notesParentType === 'Folder' && itemIsInTrash(parent)) return null;
|
||||
if ((this.props.notesParentType === 'Folder' && itemIsInTrash(parent)) || !Folder.atLeastOneRealFolderExists(this.props.folders)) return null;
|
||||
|
||||
const getTargetFolderId = async () => {
|
||||
if (!buttonFolderId && isAllNotes) {
|
||||
|
@ -353,4 +353,20 @@ describe('models/Folder', () => {
|
||||
await expectThrow(async () => Folder.delete(folder2.id, { toTrash: true, toTrashParentId: folder2.id }));
|
||||
});
|
||||
|
||||
it('should tell if at least one folder other than trash and deleted exists', async () => {
|
||||
let folders: FolderEntity[] = [];
|
||||
expect(Folder.atLeastOneRealFolderExists(folders)).toBe(false);
|
||||
|
||||
folders = await Folder.all({ includeTrash: true });
|
||||
expect(Folder.atLeastOneRealFolderExists(folders)).toBe(false);
|
||||
|
||||
const f1 = await Folder.save({ title: 'folder1' });
|
||||
folders = await Folder.all({ includeTrash: true });
|
||||
expect(Folder.atLeastOneRealFolderExists(folders)).toBe(true);
|
||||
|
||||
await Folder.delete(f1.id, { toTrash: true });
|
||||
folders = await Folder.all({ includeTrash: true });
|
||||
expect(Folder.atLeastOneRealFolderExists(folders)).toBe(false);
|
||||
});
|
||||
|
||||
});
|
||||
|
@ -934,4 +934,10 @@ export default class Folder extends BaseItem {
|
||||
return !!folders.find(f => !!f.icon);
|
||||
}
|
||||
|
||||
public static atLeastOneRealFolderExists(folders: FolderEntity[]) {
|
||||
// returns true if at least one folder exists other than trash folder and deleted folders
|
||||
const trashFolderId = getTrashFolderId();
|
||||
return folders.filter((folder) => folder.id !== trashFolderId && folder.deleted_time === 0).length > 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user