refactor: notes state management (#1031)

This commit is contained in:
Mo
2022-05-17 20:02:34 -05:00
committed by GitHub
parent 2f89f5dbb2
commit aeae2b644f
13 changed files with 255 additions and 266 deletions

View File

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

View File

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

View File

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

View File

@@ -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 []
}

View File

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

View File

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