refactor: notes state management (#1031)
This commit is contained in:
@@ -88,9 +88,7 @@ export const ChangeEditorMenu: FunctionComponent<ChangeEditorMenuProps> = ({
|
||||
|
||||
const transactions: TransactionalMutation[] = []
|
||||
|
||||
if (application.getAppState().getActiveNoteController()?.isTemplateNote) {
|
||||
await application.getAppState().getActiveNoteController().insertTemplatedNote()
|
||||
}
|
||||
await application.getAppState().notesView.insertCurrentIfTemplate()
|
||||
|
||||
if (note.locked) {
|
||||
application.alertService.alert(STRING_EDIT_LOCKED_ATTEMPT).catch(console.error)
|
||||
|
||||
@@ -31,7 +31,6 @@ export class NoteGroupView extends PureComponent<Props, State> {
|
||||
const controllerGroup = this.application.noteControllerGroup
|
||||
this.removeChangeObserver = this.application.noteControllerGroup.addActiveControllerChangeObserver(() => {
|
||||
const controllers = controllerGroup.noteControllers
|
||||
|
||||
this.setState({
|
||||
controllers: controllers,
|
||||
})
|
||||
@@ -63,7 +62,7 @@ export class NoteGroupView extends PureComponent<Props, State> {
|
||||
{!this.state.showMultipleSelectedNotes && (
|
||||
<>
|
||||
{this.state.controllers.map((controller) => {
|
||||
return <NoteView application={this.application} controller={controller} />
|
||||
return <NoteView key={controller.note.uuid} application={this.application} controller={controller} />
|
||||
})}
|
||||
</>
|
||||
)}
|
||||
|
||||
@@ -42,7 +42,7 @@ export const NoteTag = observer(({ appState, tag }: Props) => {
|
||||
(event: MouseEvent) => {
|
||||
if (tagClicked && event.target !== deleteTagRef.current) {
|
||||
setTagClicked(false)
|
||||
appState.selectedTag = tag
|
||||
appState.tags.selected = tag
|
||||
} else {
|
||||
setTagClicked(true)
|
||||
}
|
||||
|
||||
@@ -30,7 +30,7 @@ export const NotesList: FunctionComponent<Props> = observer(
|
||||
if (hideTags) {
|
||||
return []
|
||||
}
|
||||
const selectedTag = appState.selectedTag
|
||||
const selectedTag = appState.tags.selected
|
||||
if (!selectedTag) {
|
||||
return []
|
||||
}
|
||||
|
||||
@@ -34,6 +34,7 @@ const DeletePermanentlyButton = ({ closeOnBlur, onClick }: DeletePermanentlyButt
|
||||
const iconClass = 'color-neutral mr-2'
|
||||
const iconClassDanger = 'color-danger mr-2'
|
||||
const iconClassWarning = 'color-warning mr-2'
|
||||
const iconClassSuccess = 'color-success mr-2'
|
||||
|
||||
const getWordCount = (text: string) => {
|
||||
if (text.trim().length === 0) {
|
||||
@@ -400,8 +401,8 @@ export const NotesOptions = observer(({ application, appState, closeOnBlur }: No
|
||||
await appState.notes.setTrashSelectedNotes(false)
|
||||
}}
|
||||
>
|
||||
<Icon type="restore" className={iconClass} />
|
||||
Restore
|
||||
<Icon type="restore" className={iconClassSuccess} />
|
||||
<span className="color-success">Restore</span>
|
||||
</button>
|
||||
<DeletePermanentlyButton
|
||||
closeOnBlur={closeOnBlur}
|
||||
|
||||
@@ -35,12 +35,13 @@ export const NotesView: FunctionComponent<Props> = observer(({ application, appS
|
||||
optionsSubtitle,
|
||||
panelTitle,
|
||||
renderedNotes,
|
||||
selectedNotes,
|
||||
searchBarElement,
|
||||
paginate,
|
||||
panelWidth,
|
||||
} = appState.notesView
|
||||
|
||||
const { selectedNotes } = appState.notes
|
||||
|
||||
const createNewNote = useCallback(() => appState.notesView.createNewNote(), [appState])
|
||||
const onFilterEnter = useCallback(() => appState.notesView.onFilterEnter(), [appState])
|
||||
const clearFilterText = useCallback(() => appState.notesView.clearFilterText(), [appState])
|
||||
|
||||
Reference in New Issue
Block a user