refactor: rename state

This commit is contained in:
Antonella Sgarlatta
2021-06-03 13:53:49 -03:00
parent c42f1cedda
commit 386ca34178
9 changed files with 33 additions and 33 deletions

View File

@@ -10,10 +10,10 @@ type Props = {
export const AutocompleteTagHint = observer( export const AutocompleteTagHint = observer(
({ appState, closeOnBlur }: Props) => { ({ appState, closeOnBlur }: Props) => {
const { autocompleteSearchQuery, autocompleteTagResults } = const { autocompleteSearchQuery, autocompleteTagResults } =
appState.activeNote; appState.noteTags;
const onTagHintClick = async () => { const onTagHintClick = async () => {
await appState.activeNote.createAndAddNewTag(); await appState.noteTags.createAndAddNewTag();
}; };
return ( return (

View File

@@ -17,7 +17,7 @@ export const AutocompleteTagInput = observer(({ appState }: Props) => {
autocompleteTagResults, autocompleteTagResults,
tagElements, tagElements,
tags, tags,
} = appState.activeNote; } = appState.noteTags;
const [dropdownVisible, setDropdownVisible] = useState(false); const [dropdownVisible, setDropdownVisible] = useState(false);
const [dropdownMaxHeight, setDropdownMaxHeight] = const [dropdownMaxHeight, setDropdownMaxHeight] =
@@ -28,7 +28,7 @@ export const AutocompleteTagInput = observer(({ appState }: Props) => {
const [closeOnBlur] = useCloseOnBlur(dropdownRef, (visible: boolean) => { const [closeOnBlur] = useCloseOnBlur(dropdownRef, (visible: boolean) => {
setDropdownVisible(visible); setDropdownVisible(visible);
appState.activeNote.clearAutocompleteSearch(); appState.noteTags.clearAutocompleteSearch();
}); });
const showDropdown = () => { const showDropdown = () => {
@@ -40,18 +40,18 @@ export const AutocompleteTagInput = observer(({ appState }: Props) => {
const onSearchQueryChange = (event: Event) => { const onSearchQueryChange = (event: Event) => {
const query = (event.target as HTMLInputElement).value; const query = (event.target as HTMLInputElement).value;
appState.activeNote.setAutocompleteSearchQuery(query); appState.noteTags.setAutocompleteSearchQuery(query);
appState.activeNote.searchActiveNoteAutocompleteTags(); appState.noteTags.searchActiveNoteAutocompleteTags();
}; };
const onFormSubmit = async (event: Event) => { const onFormSubmit = async (event: Event) => {
event.preventDefault(); event.preventDefault();
await appState.activeNote.createAndAddNewTag(); await appState.noteTags.createAndAddNewTag();
}; };
useEffect(() => { useEffect(() => {
appState.activeNote.searchActiveNoteAutocompleteTags(); appState.noteTags.searchActiveNoteAutocompleteTags();
}, [appState.activeNote]); }, [appState.noteTags]);
return ( return (
<form <form

View File

@@ -11,18 +11,18 @@ type Props = {
export const AutocompleteTagResult = observer( export const AutocompleteTagResult = observer(
({ appState, tagResult, closeOnBlur }: Props) => { ({ appState, tagResult, closeOnBlur }: Props) => {
const { autocompleteSearchQuery } = appState.activeNote; const { autocompleteSearchQuery } = appState.noteTags;
const onTagOptionClick = async (tag: SNTag) => { const onTagOptionClick = async (tag: SNTag) => {
await appState.activeNote.addTagToActiveNote(tag); await appState.noteTags.addTagToActiveNote(tag);
appState.activeNote.clearAutocompleteSearch(); appState.noteTags.clearAutocompleteSearch();
}; };
return ( return (
<button <button
ref={(element) => { ref={(element) => {
if (element) { if (element) {
appState.activeNote.setAutocompleteTagResultElement( appState.noteTags.setAutocompleteTagResultElement(
tagResult, tagResult,
element element
); );

View File

@@ -10,13 +10,13 @@ type Props = {
}; };
export const NoteTag = observer(({ appState, tag }: Props) => { export const NoteTag = observer(({ appState, tag }: Props) => {
const { tagsContainerMaxWidth } = appState.activeNote; const { tagsContainerMaxWidth } = appState.noteTags;
const [showDeleteButton, setShowDeleteButton] = useState(false); const [showDeleteButton, setShowDeleteButton] = useState(false);
const deleteTagRef = useRef<HTMLButtonElement>(); const deleteTagRef = useRef<HTMLButtonElement>();
const deleteTag = () => { const deleteTag = () => {
appState.activeNote.removeTagFromActiveNote(tag); appState.noteTags.removeTagFromActiveNote(tag);
}; };
const onTagClick = () => { const onTagClick = () => {
@@ -43,11 +43,11 @@ export const NoteTag = observer(({ appState, tag }: Props) => {
deleteTag(); deleteTag();
break; break;
case 'ArrowLeft': case 'ArrowLeft':
previousTagElement = appState.activeNote.getPreviousTagElement(tag); previousTagElement = appState.noteTags.getPreviousTagElement(tag);
previousTagElement?.focus(); previousTagElement?.focus();
break; break;
case 'ArrowRight': case 'ArrowRight':
nextTagElement = appState.activeNote.getNextTagElement(tag); nextTagElement = appState.noteTags.getNextTagElement(tag);
nextTagElement?.focus(); nextTagElement?.focus();
break; break;
default: default:
@@ -59,7 +59,7 @@ export const NoteTag = observer(({ appState, tag }: Props) => {
<button <button
ref={(element) => { ref={(element) => {
if (element) { if (element) {
appState.activeNote.setTagElement(tag, element); appState.noteTags.setTagElement(tag, element);
} }
}} }}
className="sn-tag pl-1 pr-2 mr-2" className="sn-tag pl-1 pr-2 mr-2"

View File

@@ -13,11 +13,11 @@ const NoteTagsContainer = observer(({ appState }: Props) => {
const { const {
tags, tags,
tagsContainerMaxWidth, tagsContainerMaxWidth,
} = appState.activeNote; } = appState.noteTags;
useEffect(() => { useEffect(() => {
appState.activeNote.reloadTagsContainerMaxWidth(); appState.noteTags.reloadTagsContainerMaxWidth();
}, [appState.activeNote]); }, [appState.noteTags]);
return ( return (
<div <div

View File

@@ -16,7 +16,7 @@ import { Bridge } from '@/services/bridge';
import { storage, StorageKey } from '@/services/localStorage'; import { storage, StorageKey } from '@/services/localStorage';
import { AccountMenuState } from './account_menu_state'; import { AccountMenuState } from './account_menu_state';
import { ActionsMenuState } from './actions_menu_state'; import { ActionsMenuState } from './actions_menu_state';
import { ActiveNoteState } from './active_note_state'; import { NoteTagsState } from './note_tags_state';
import { NoAccountWarningState } from './no_account_warning_state'; import { NoAccountWarningState } from './no_account_warning_state';
import { SyncState } from './sync_state'; import { SyncState } from './sync_state';
import { SearchOptionsState } from './search_options_state'; import { SearchOptionsState } from './search_options_state';
@@ -63,8 +63,8 @@ export class AppState {
showBetaWarning: boolean; showBetaWarning: boolean;
readonly accountMenu = new AccountMenuState(); readonly accountMenu = new AccountMenuState();
readonly actionsMenu = new ActionsMenuState(); readonly actionsMenu = new ActionsMenuState();
readonly activeNote: ActiveNoteState;
readonly noAccountWarning: NoAccountWarningState; readonly noAccountWarning: NoAccountWarningState;
readonly noteTags: NoteTagsState;
readonly sync = new SyncState(); readonly sync = new SyncState();
readonly searchOptions: SearchOptionsState; readonly searchOptions: SearchOptionsState;
readonly notes: NotesState; readonly notes: NotesState;
@@ -83,11 +83,6 @@ export class AppState {
this.$timeout = $timeout; this.$timeout = $timeout;
this.$rootScope = $rootScope; this.$rootScope = $rootScope;
this.application = application; this.application = application;
this.activeNote = new ActiveNoteState(
application,
this,
this.appEventObserverRemovers
);
this.notes = new NotesState( this.notes = new NotesState(
application, application,
this, this,
@@ -96,6 +91,11 @@ export class AppState {
}, },
this.appEventObserverRemovers, this.appEventObserverRemovers,
); );
this.noteTags = new NoteTagsState(
application,
this,
this.appEventObserverRemovers
);
this.tags = new TagsState( this.tags = new TagsState(
application, application,
this.appEventObserverRemovers, this.appEventObserverRemovers,

View File

@@ -3,7 +3,7 @@ import { action, computed, makeObservable, observable } from 'mobx';
import { WebApplication } from '../application'; import { WebApplication } from '../application';
import { AppState } from './app_state'; import { AppState } from './app_state';
export class ActiveNoteState { export class NoteTagsState {
autocompleteSearchQuery = ''; autocompleteSearchQuery = '';
autocompleteTagResultElements: (HTMLButtonElement | undefined)[] = []; autocompleteTagResultElements: (HTMLButtonElement | undefined)[] = [];
autocompleteTagResults: SNTag[] = []; autocompleteTagResults: SNTag[] = [];

View File

@@ -171,7 +171,7 @@ export class NotesState {
this.activeEditor.setNote(note); this.activeEditor.setNote(note);
} }
this.appState.activeNote.reloadTags(); this.appState.noteTags.reloadTags();
await this.onActiveEditorChanged(); await this.onActiveEditorChanged();
if (note.waitingForKey) { if (note.waitingForKey) {

View File

@@ -410,7 +410,7 @@ class NotesViewCtrl extends PureViewCtrl<unknown, NotesCtrlState> {
await this.appState.createEditor(title); await this.appState.createEditor(title);
await this.flushUI(); await this.flushUI();
await this.reloadNotes(); await this.reloadNotes();
await this.appState.activeNote.reloadTags(); await this.appState.noteTags.reloadTags();
} }
async handleTagChange(tag: SNTag) { async handleTagChange(tag: SNTag) {
@@ -649,7 +649,7 @@ class NotesViewCtrl extends PureViewCtrl<unknown, NotesCtrlState> {
__: boolean, __: boolean,
isCollapsed: boolean isCollapsed: boolean
) { ) {
this.appState.activeNote.reloadTagsContainerMaxWidth(); this.appState.noteTags.reloadTagsContainerMaxWidth();
this.application.setPreference( this.application.setPreference(
PrefKey.NotesPanelWidth, PrefKey.NotesPanelWidth,
newWidth newWidth
@@ -661,7 +661,7 @@ class NotesViewCtrl extends PureViewCtrl<unknown, NotesCtrlState> {
} }
onPanelWidthEvent(): void { onPanelWidthEvent(): void {
this.appState.activeNote.reloadTagsContainerMaxWidth(); this.appState.noteTags.reloadTagsContainerMaxWidth();
} }
paginate() { paginate() {