Skip to content

Commit

Permalink
Remove now-unnecessary lastnote-tracking logic
Browse files Browse the repository at this point in the history
  • Loading branch information
personalizedrefrigerator committed Dec 16, 2024
1 parent ec9583d commit 41f1a0d
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 40 deletions.
28 changes: 0 additions & 28 deletions packages/app-mobile/components/screens/Note/Note.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -346,32 +346,4 @@ describe('screens/Note', () => {
await CommandService.instance().execute('toggleVisiblePanes');
await expectToBeEditing(false);
});

it('deselecting all notes should continue displaying the last-selected note', async () => {
const noteId = await openNewNote({
title: 'Title: Test note',
body: '',
});

render(<WrappedNoteScreen />);

const titleInput = await screen.findByDisplayValue('Title: Test note');
expect(titleInput).toBeVisible();

store.dispatch({
type: 'NOTE_UPDATE_ALL',
notes: [],
notesSource: 'test',
});

// Should now have no selected notes
expect(store.getState()).toMatchObject({ selectedNoteIds: [] });

// Should still be possible to edit
await openEditor();

const editor = await getNoteEditorControl();
editor.insertText('Updated body');
await waitForNoteToMatch(noteId, { body: 'Updated body' });
});
});
14 changes: 2 additions & 12 deletions packages/app-mobile/components/screens/Note/Note.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ import { isSupportedLanguage } from '../../../services/voiceTyping/vosk';
import { ChangeEvent as EditorChangeEvent, SelectionRangeChangeEvent, UndoRedoDepthChangeEvent } from '@joplin/editor/events';
import { join } from 'path';
import { Dispatch } from 'redux';
import { RefObject, useContext, useRef } from 'react';
import { RefObject, useContext } from 'react';
import { SelectionRange } from '../../NoteEditor/types';
import { getNoteCallbackUrl } from '@joplin/lib/callbackUrlUtils';
import { AppState } from '../../../utils/types';
Expand Down Expand Up @@ -1615,19 +1615,9 @@ class NoteScreenComponent extends BaseScreenComponent<ComponentProps, State> imp
// which can cause some bugs where previously set state to another note would interfere
// how the new note should be rendered
const NoteScreenWrapper = (props: Props) => {
const lastNonNullNoteIdRef = useRef(props.noteId);
if (props.noteId) {
lastNonNullNoteIdRef.current = props.noteId;
}

// This keeps the current note open even if it's no longer present in selectedNoteIds.
// This might happen, for example, if the selected note is moved to an unselected
// folder.
const noteId = lastNonNullNoteIdRef.current;

const dialogs = useContext(DialogContext);
return (
<NoteScreenComponent key={noteId} dialogs={dialogs} {...props} noteId={noteId} />
<NoteScreenComponent key={props.noteId} dialogs={dialogs} {...props} />
);
};

Expand Down

0 comments on commit 41f1a0d

Please sign in to comment.