aboutsummaryrefslogtreecommitdiff
path: root/src/client/views/ContextMenu.tsx
diff options
context:
space:
mode:
authorbobzel <zzzman@gmail.com>2024-05-14 23:15:24 -0400
committerbobzel <zzzman@gmail.com>2024-05-14 23:15:24 -0400
commit3534aaf88a3c30a474b3b5a5b7f04adfe6f15fac (patch)
tree47fb7a8671b209bd4d76e0f755a5b035c6936607 /src/client/views/ContextMenu.tsx
parent87bca251d87b5a95da06b2212400ce9427152193 (diff)
parent5cb7ad90e120123ca572e8ef5b1aa6ca41581134 (diff)
Merge branch 'restoringEslint' into sarah-ai-visualization
Diffstat (limited to 'src/client/views/ContextMenu.tsx')
-rw-r--r--src/client/views/ContextMenu.tsx49
1 files changed, 23 insertions, 26 deletions
diff --git a/src/client/views/ContextMenu.tsx b/src/client/views/ContextMenu.tsx
index ca877b93e..d784a14b8 100644
--- a/src/client/views/ContextMenu.tsx
+++ b/src/client/views/ContextMenu.tsx
@@ -1,16 +1,19 @@
+/* eslint-disable react/no-array-index-key */
+/* eslint-disable react/jsx-props-no-spreading */
+/* eslint-disable default-param-last */
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
-import { action, computed, IReactionDisposer, makeObservable, observable, reaction } from 'mobx';
+import { action, computed, IReactionDisposer, makeObservable, observable } from 'mobx';
import { observer } from 'mobx-react';
import * as React from 'react';
-import { StrCast } from '../../fields/Types';
-import { SettingsManager } from '../util/SettingsManager';
+import { DivHeight, DivWidth } from '../../ClientUtils';
+import { SnappingManager } from '../util/SnappingManager';
import './ContextMenu.scss';
import { ContextMenuItem, ContextMenuProps, OriginalMenuProps } from './ContextMenuItem';
import { ObservableReactComponent } from './ObservableReactComponent';
-import { DivHeight, DivWidth } from '../../Utils';
@observer
export class ContextMenu extends ObservableReactComponent<{}> {
+ // eslint-disable-next-line no-use-before-define
static Instance: ContextMenu;
private _ignoreUp = false;
@@ -124,8 +127,8 @@ export class ContextMenu extends ObservableReactComponent<{}> {
@action
displayMenu = (x: number, y: number, initSearch = '', showSearch = false, onDisplay?: () => void) => {
- //maxX and maxY will change if the UI/font size changes, but will work for any amount
- //of items added to the menu
+ // maxX and maxY will change if the UI/font size changes, but will work for any amount
+ // of items added to the menu
this._showSearch = showSearch;
this._pageX = x;
@@ -147,15 +150,13 @@ export class ContextMenu extends ObservableReactComponent<{}> {
@computed get filteredItems(): (OriginalMenuProps | string[])[] {
const searchString = this._searchString.toLowerCase().split(' ');
- const matches = (descriptions: string[]): boolean => {
- return searchString.every(s => descriptions.some(desc => desc.toLowerCase().includes(s)));
- };
+ const matches = (descriptions: string[]) => searchString.every(s => descriptions.some(desc => desc.toLowerCase().includes(s)));
const flattenItems = (items: ContextMenuProps[], groupFunc: (groupName: any) => string[]) => {
let eles: (OriginalMenuProps | string[])[] = [];
const leaves: OriginalMenuProps[] = [];
- for (const item of items) {
- const description = item.description;
+ items.forEach(item => {
+ const { description } = item;
const path = groupFunc(description);
if ('subitems' in item) {
const children = flattenItems(item.subitems, name => [...groupFunc(description), name]);
@@ -163,13 +164,10 @@ export class ContextMenu extends ObservableReactComponent<{}> {
eles.push(path);
eles = eles.concat(children);
}
- } else {
- if (!matches(path)) {
- continue;
- }
+ } else if (matches(path)) {
leaves.push(item);
}
- }
+ });
eles = [...leaves, ...eles];
@@ -192,7 +190,7 @@ export class ContextMenu extends ObservableReactComponent<{}> {
key={index + value.join(' -> ')}
className="contextMenu-group"
style={{
- background: StrCast(SettingsManager.userVariantColor),
+ background: SnappingManager.userVariantColor,
}}>
<div className="contextMenu-description">{value.join(' -> ')}</div>
</div>
@@ -224,11 +222,11 @@ export class ContextMenu extends ObservableReactComponent<{}> {
display: this._display ? '' : 'none',
left: this.pageX,
...(this._yRelativeToTop ? { top: Math.max(0, this.pageY) } : { bottom: this.pageY }),
- background: SettingsManager.userBackgroundColor,
- color: SettingsManager.userColor,
+ background: SnappingManager.userBackgroundColor,
+ color: SnappingManager.userColor,
}}>
{!this.itemsNeedSearch ? null : (
- <span className={'search-icon'}>
+ <span className="search-icon">
<span className="icon-background">
<FontAwesomeIcon icon="search" size="lg" />
</span>
@@ -241,6 +239,7 @@ export class ContextMenu extends ObservableReactComponent<{}> {
value={this._searchString}
onKeyDown={this.onKeyDown}
onChange={this.onChange}
+ // eslint-disable-next-line jsx-a11y/no-autofocus
autoFocus
/>
</span>
@@ -267,7 +266,7 @@ export class ContextMenu extends ObservableReactComponent<{}> {
if (item) {
item.event({ x: this.pageX, y: this.pageY });
} else {
- //if (this._searchString.startsWith(this._defaultPrefix)) {
+ // if (this._searchString.startsWith(this._defaultPrefix)) {
this._defaultItem?.(this._searchString.substring(this._defaultPrefix.length));
}
this.closeMenu();
@@ -281,12 +280,10 @@ export class ContextMenu extends ObservableReactComponent<{}> {
this._searchString = e.target.value;
if (!this._searchString) {
this._selectedIndex = -1;
+ } else if (this._selectedIndex === -1) {
+ this._selectedIndex = 0;
} else {
- if (this._selectedIndex === -1) {
- this._selectedIndex = 0;
- } else {
- this._selectedIndex = Math.min(this.flatItems.length - 1, this._selectedIndex);
- }
+ this._selectedIndex = Math.min(this.flatItems.length - 1, this._selectedIndex);
}
};
}