Merge branch 'develop' into feature/remove-batch-manager

This commit is contained in:
Antonella Sgarlatta
2021-06-14 15:53:06 -03:00
committed by GitHub
17 changed files with 80 additions and 88 deletions

View File

@@ -47,7 +47,9 @@ export const AutocompleteTagInput = observer(({ appState }: Props) => {
const onFormSubmit = async (event: Event) => {
event.preventDefault();
await appState.noteTags.createAndAddNewTag();
if (autocompleteSearchQuery !== '') {
await appState.noteTags.createAndAddNewTag();
}
};
const onKeyDown = (event: KeyboardEvent) => {
@@ -115,8 +117,9 @@ export const AutocompleteTagInput = observer(({ appState }: Props) => {
ref={dropdownRef}
className={`${tags.length > 0 ? 'w-80' : 'w-70 mr-10'} sn-dropdown flex flex-col py-2 absolute`}
style={{ maxHeight: dropdownMaxHeight, maxWidth: tagsContainerMaxWidth }}
onBlur={closeOnBlur}
>
<div className="overflow-y-scroll">
<div className="overflow-y-auto">
{autocompleteTagResults.map((tagResult) => (
<AutocompleteTagResult
key={tagResult.uuid}

View File

@@ -23,9 +23,7 @@ const ConfirmSignoutContainer = observer((props: Props) => {
});
const ConfirmSignoutModal = observer(({ application, appState }: Props) => {
const [deleteLocalBackups, setDeleteLocalBackups] = useState(
application.hasAccount()
);
const [deleteLocalBackups, setDeleteLocalBackups] = useState(false);
const cancelRef = useRef<HTMLButtonElement>();
function close() {

View File

@@ -23,7 +23,7 @@ const NotesContextMenu = observer(({ appState }: Props) => {
return appState.notes.contextMenuOpen ? (
<div
ref={contextMenuRef}
className="sn-dropdown max-h-120 max-w-xs flex flex-col py-2 overflow-y-scroll fixed"
className="sn-dropdown min-w-80 max-h-120 max-w-xs flex flex-col py-2 overflow-y-auto fixed"
style={{
...appState.notes.contextMenuPosition,
maxHeight: appState.notes.contextMenuMaxHeight,

View File

@@ -159,7 +159,7 @@ export const NotesOptions = observer(
maxHeight: tagsMenuMaxHeight,
position: 'fixed',
}}
className="sn-dropdown flex flex-col py-2 max-h-120 max-w-xs fixed overflow-y-scroll"
className="sn-dropdown min-w-80 flex flex-col py-2 max-h-120 max-w-xs fixed overflow-y-auto"
>
{appState.tags.tags.map((tag) => (
<button

View File

@@ -71,7 +71,8 @@ export const NotesOptionsPanel = observer(({ appState }: Props) => {
...position,
maxHeight,
}}
className="sn-dropdown sn-dropdown--animated max-h-120 max-w-xs flex flex-col py-2 overflow-y-scroll fixed"
className="sn-dropdown sn-dropdown--animated min-w-80 max-h-120 max-w-xs flex flex-col py-2 overflow-y-auto fixed"
onBlur={closeOnBlur}
>
{open && (
<NotesOptions

View File

@@ -63,7 +63,8 @@ const SearchOptions = observer(({ appState }: Props) => {
style={{
top: optionsPanelTop,
}}
className="sn-dropdown sn-dropdown--anchor-right sn-dropdown--animated absolute grid gap-2 py-2"
className="sn-dropdown sn-dropdown--anchor-right sn-dropdown--animated min-w-80 absolute grid gap-2 py-2"
onBlur={closeOnBlur}
>
<Switch
className="h-10"

View File

@@ -126,7 +126,7 @@ const SessionsModal: FunctionComponent<{
return (
<>
<Dialog onDismiss={close} className="sessions-modal">
<Dialog onDismiss={close} className="sessions-modal h-90vh">
<div className="sk-modal-content">
<div class="sn-component">
<div class="sk-panel">
@@ -145,7 +145,7 @@ const SessionsModal: FunctionComponent<{
</button>
</div>
</div>
<div class="sk-panel-content">
<div class="sk-panel-content overflow-y-auto">
{refreshing ? (
<>
<div class="sk-spinner small info"></div>

View File

@@ -1,10 +1,8 @@
import { ApplicationService } from '@standardnotes/snjs';
import { WebApplication } from '@/ui_models/application';
import { isDesktopApplication } from '@/utils';
import { AppStateEvent } from '@/ui_models/app_state';
const MILLISECONDS_PER_SECOND = 1000;
const FOCUS_POLL_INTERVAL = 1 * MILLISECONDS_PER_SECOND;
const POLL_INTERVAL = 50;
const LOCK_INTERVAL_NONE = 0;
const LOCK_INTERVAL_IMMEDIATE = 1;
const LOCK_INTERVAL_ONE_MINUTE = 60 * MILLISECONDS_PER_SECOND;
@@ -15,37 +13,21 @@ const STORAGE_KEY_AUTOLOCK_INTERVAL = "AutoLockIntervalKey";
export class AutolockService extends ApplicationService {
private unsubState?: () => void;
private pollFocusInterval: any
private pollInterval: any
private lastFocusState?: 'hidden' | 'visible'
private lockAfterDate?: Date
private lockTimeout?: any
onAppLaunch() {
this.observeVisibility();
if (!isDesktopApplication()) {
this.beginPolling();
}
return super.onAppLaunch();
}
observeVisibility() {
this.unsubState = (this.application as WebApplication).getAppState().addObserver(
async (eventName) => {
if (eventName === AppStateEvent.WindowDidBlur) {
this.documentVisibilityChanged(false);
} else if (eventName === AppStateEvent.WindowDidFocus) {
this.documentVisibilityChanged(true);
}
}
);
if (!isDesktopApplication()) {
this.beginWebFocusPolling();
}
}
deinit() {
this.unsubState?.();
this.cancelAutoLockTimer();
if (this.pollFocusInterval) {
clearInterval(this.pollFocusInterval);
if (this.pollInterval) {
clearInterval(this.pollInterval);
}
}
@@ -85,11 +67,15 @@ export class AutolockService extends ApplicationService {
* Verify document is in focus every so often as visibilitychange event is
* not triggered on a typical window blur event but rather on tab changes.
*/
beginWebFocusPolling() {
this.pollFocusInterval = setInterval(() => {
if (document.hidden) {
/** Native event listeners will have fired */
return;
beginPolling() {
this.pollInterval = setInterval(async () => {
const locked = await this.application.isLocked();
if (
!locked &&
this.lockAfterDate &&
new Date() > this.lockAfterDate
) {
this.lockApplication();
}
const hasFocus = document.hasFocus();
if (hasFocus && this.lastFocusState === 'hidden') {
@@ -99,7 +85,7 @@ export class AutolockService extends ApplicationService {
}
/* Save this to compare against next time around */
this.lastFocusState = hasFocus ? 'visible' : 'hidden';
}, FOCUS_POLL_INTERVAL);
}, POLL_INTERVAL);
}
getAutoLockIntervalOptions() {
@@ -129,14 +115,6 @@ export class AutolockService extends ApplicationService {
async documentVisibilityChanged(visible: boolean) {
if (visible) {
const locked = await this.application.isLocked();
if (
!locked &&
this.lockAfterDate &&
new Date() > this.lockAfterDate
) {
this.lockApplication();
}
this.cancelAutoLockTimer();
} else {
this.beginAutoLockTimer();
@@ -148,29 +126,15 @@ export class AutolockService extends ApplicationService {
if (interval === LOCK_INTERVAL_NONE) {
return;
}
/**
* Use a timeout if possible, but if the computer is put to sleep, timeouts won't
* work. Need to set a date as backup. this.lockAfterDate does not need to be
* persisted, as living in memory is sufficient. If memory is cleared, then the
* application will lock anyway.
*/
const addToNow = (seconds: number) => {
const date = new Date();
date.setSeconds(date.getSeconds() + seconds);
return date;
};
this.lockAfterDate = addToNow(interval / MILLISECONDS_PER_SECOND);
clearTimeout(this.lockTimeout);
this.lockTimeout = setTimeout(() => {
this.cancelAutoLockTimer();
this.lockApplication();
this.lockAfterDate = undefined;
}, interval);
}
cancelAutoLockTimer() {
clearTimeout(this.lockTimeout);
this.lockAfterDate = undefined;
this.lockTimeout = undefined;
}
}

View File

@@ -142,7 +142,7 @@ export class AppState {
this.noAccountWarning.reset();
}
this.actionsMenu.reset();
this.unsubApp();
this.unsubApp?.();
this.unsubApp = undefined;
this.observers.length = 0;
this.appEventObserverRemovers.forEach((remover) => remover());

View File

@@ -198,9 +198,15 @@ export class NoteTagsState {
async removeTagFromActiveNote(tag: SNTag): Promise<void> {
const { activeNote } = this;
if (activeNote) {
await this.application.changeItem(tag.uuid, (mutator) => {
mutator.removeItemAsRelationship(activeNote);
});
const descendantTags = this.application.getTagDescendants(tag);
const tagsToRemove = [...descendantTags, tag];
await Promise.all(
tagsToRemove.map(async (tag) => {
await this.application.changeItem(tag.uuid, (mutator) => {
mutator.removeItemAsRelationship(activeNote);
});
})
);
this.application.sync();
this.reloadTags();
}

View File

@@ -346,13 +346,18 @@ export class NotesState {
async removeTagFromSelectedNotes(tag: SNTag): Promise<void> {
const selectedNotes = Object.values(this.selectedNotes);
await this.application.changeItem(tag.uuid, (mutator) => {
for (const note of selectedNotes) {
mutator.removeItemAsRelationship(note);
}
});
const descendantTags = this.application.getTagDescendants(tag);
const tagsToRemove = [...descendantTags, tag];
await Promise.all(
tagsToRemove.map(async (tag) => {
await this.application.changeItem(tag.uuid, (mutator) => {
for (const note of selectedNotes) {
mutator.removeItemAsRelationship(note);
}
});
})
);
this.application.sync();
}
isTagInSelectedNotes(tag: SNTag): boolean {

View File

@@ -40,8 +40,8 @@ export class PureViewCtrl<P = CtrlProps, S = CtrlState> {
}
deinit(): void {
this.unsubApp();
this.unsubState();
this.unsubApp?.();
this.unsubState?.();
for (const disposer of this.reactionDisposers) {
disposer();
}

View File

@@ -289,10 +289,10 @@ class TagsViewCtrl extends PureViewCtrl<unknown, TagState> {
async saveTag($event: Event, tag: SNTag) {
($event.target! as HTMLInputElement).blur();
if (!this.titles[tag.uuid]?.length) {
return this.undoCreateTag(tag);
}
if (this.getState().templateTag) {
if (!this.titles[tag.uuid]?.length) {
return this.undoCreateTag(tag);
}
return this.saveNewTag();
} else {
return this.saveTagRename(tag);
@@ -314,6 +314,9 @@ class TagsViewCtrl extends PureViewCtrl<unknown, TagState> {
if (newTitle.length === 0) {
this.titles[tag.uuid] = this.editingOriginalName;
this.editingOriginalName = undefined;
await this.setState({
editingTag: undefined
});
return;
}
const existingTag = this.application.findTagByTitle(newTitle);
@@ -345,6 +348,7 @@ class TagsViewCtrl extends PureViewCtrl<unknown, TagState> {
this.application.alertService!.alert(
"A tag with this name already exists."
);
this.undoCreateTag(newTag);
return;
}
const insertedTag = await this.application.insertItem(newTag);