1
0
mirror of https://github.com/laurent22/joplin.git synced 2024-12-24 10:27:10 +02:00

Mobile: Fixes #10065: New note button crashes app when there are no notebooks (#10087)

This commit is contained in:
Siddhant Paritosh Rao 2024-03-11 20:52:26 +05:30 committed by GitHub
parent 8bdac6ffbf
commit da393f6c34
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 26 additions and 2 deletions

View File

@ -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,

View File

@ -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) {

View File

@ -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);
});
});

View File

@ -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;
}
}