diff --git a/src/ts/component/block/bookmark.tsx b/src/ts/component/block/bookmark.tsx index 765e687d28..d0223a20fb 100644 --- a/src/ts/component/block/bookmark.tsx +++ b/src/ts/component/block/bookmark.tsx @@ -268,7 +268,7 @@ const BlockBookmark = observer(class BlockBookmark extends React.Component { }; toggleHoverArea (v: boolean) { - const { block } = this.props; - const obj = $(`#block-${block.id}`); - const hoverArea = obj.find('.hoverArea'); - - v ? hoverArea.addClass('active') : hoverArea.removeClass('active'); + $(`#block-${this.props.block.id} .hoverArea`).toggleClass('active', v); }; resize () { diff --git a/src/ts/component/block/dataview/head.tsx b/src/ts/component/block/dataview/head.tsx index 5fc8b439eb..063efcf21a 100644 --- a/src/ts/component/block/dataview/head.tsx +++ b/src/ts/component/block/dataview/head.tsx @@ -314,12 +314,9 @@ const Head = observer(class Head extends React.Component }; checkInput (isEmpty: boolean) { - if (!this.ref) { - return; + if (this.ref) { + $(this.ref.node).toggleClass('isEmpty', isEmpty) }; - - const node = $(this.ref.node); - isEmpty ? node.addClass('isEmpty') : node.removeClass('isEmpty'); }; save () { diff --git a/src/ts/component/block/dataview/view/grid.tsx b/src/ts/component/block/dataview/view/grid.tsx index 732bcbb4f4..ccc0edec33 100644 --- a/src/ts/component/block/dataview/view/grid.tsx +++ b/src/ts/component/block/dataview/view/grid.tsx @@ -276,7 +276,7 @@ const ViewGrid = observer(class ViewGrid extends React.Component maxWidth ? wrap.addClass('withScroll') : wrap.removeClass('withScroll'); + wrap.toggleClass('withScroll', width > maxWidth); width = Math.max(wrapperWidth, Math.min(maxWidth, width)); obj.css({ @@ -1556,7 +1556,7 @@ const BlockTable = observer(class BlockTable extends React.Component maxWidth ? wrap.addClass('withScroll') : wrap.removeClass('withScroll'); + wrap.toggleClass('withScroll', width > maxWidth); }; }; diff --git a/src/ts/component/form/button.tsx b/src/ts/component/form/button.tsx index fbd0949e13..3ea06022f8 100644 --- a/src/ts/component/form/button.tsx +++ b/src/ts/component/form/button.tsx @@ -88,10 +88,7 @@ const Button = forwardRef(({ useImperativeHandle(ref, () => ({ setLoading: (v: boolean) => setIsLoading(v), - setDisabled: (v: boolean) => { - const node = $(nodeRef.current); - v ? node.addClass('disabled') : node.removeClass('disabled'); - }, + setDisabled: (v: boolean) => $(nodeRef.current).toggleClass('disabled', v), isDisabled: () => $(nodeRef.current).hasClass('disabled'), isLoading: () => isLoading, })); diff --git a/src/ts/component/form/filter.tsx b/src/ts/component/form/filter.tsx index e4704cbd0e..43ccc1531c 100644 --- a/src/ts/component/form/filter.tsx +++ b/src/ts/component/form/filter.tsx @@ -252,9 +252,7 @@ class Filter extends React.Component { }; checkButton () { - const node = $(this.node); - - this.getValue() ? node.addClass('active') : node.removeClass('active'); + $(this.node).toggleClass('active', this.getValue()); this.placeholderCheck(); }; diff --git a/src/ts/component/form/input.tsx b/src/ts/component/form/input.tsx index 155a60b458..b6d9c42327 100644 --- a/src/ts/component/form/input.tsx +++ b/src/ts/component/form/input.tsx @@ -119,10 +119,7 @@ const Input = forwardRef((props, ref) => { setValue: (v: string) => setValue(String(v || '')), getValue: () => String(value || ''), setType: (v: string) => setInputType(v), - setError: (hasError: boolean) => { - const node = $(inputRef.current); - hasError ? node.addClass('withError') : node.removeClass('withError'); - }, + setError: (hasError: boolean) => $(inputRef.current).toggleClass('withError', hasError), getSelectionRect, setPlaceholder: (placeholder: string) => $(inputRef.current).attr({ placeholder }), setRange: (range: I.TextRange) => { diff --git a/src/ts/component/form/switch.tsx b/src/ts/component/form/switch.tsx index 172727d549..26b80f0a65 100644 --- a/src/ts/component/form/switch.tsx +++ b/src/ts/component/form/switch.tsx @@ -72,10 +72,8 @@ class Switch extends React.Component { }; setValue (value: boolean) { - const node = $(this.node); - this.value = value; - value ? node.addClass('active') : node.removeClass('active'); + $(this.node).toggleClass('active', value); }; getValue () { diff --git a/src/ts/component/form/textarea.tsx b/src/ts/component/form/textarea.tsx index fe1b18bf95..bd41fe9fec 100644 --- a/src/ts/component/form/textarea.tsx +++ b/src/ts/component/form/textarea.tsx @@ -183,7 +183,7 @@ class Textarea extends React.Component { }; setError (v: boolean) { - v ? this.addClass('withError') : this.removeClass('withError'); + $(this.node).toggleClass('withError', v); }; addClass (v: string) { diff --git a/src/ts/component/list/popup.tsx b/src/ts/component/list/popup.tsx index 5ce20af4c5..9a6d380cf9 100644 --- a/src/ts/component/list/popup.tsx +++ b/src/ts/component/list/popup.tsx @@ -19,10 +19,7 @@ const ListPopup = observer(class ListPopup extends React.Component 0 ? body.addClass('overPopup') : body.removeClass('overPopup'); + $('body').toggleClass('overPopup', S.Popup.list.length > 0); }; }); diff --git a/src/ts/component/list/previewObject.tsx b/src/ts/component/list/previewObject.tsx index ad93b7fbcd..7faae71ed1 100644 --- a/src/ts/component/list/previewObject.tsx +++ b/src/ts/component/list/previewObject.tsx @@ -256,8 +256,8 @@ class ListObjectPreview extends React.Component { const isFirst = this.page == 0; const isLast = this.page == this.getMaxPage(); - isFirst ? arrowLeft.addClass('dn') : arrowRight.removeClass('dn'); - isLast ? arrowRight.addClass('dn') : arrowRight.removeClass('dn'); + arrowLeft.toggleClass('dn', isFirst); + arrowRight.toggleClass('dn', isLast); }; }; diff --git a/src/ts/component/menu/block/add.tsx b/src/ts/component/menu/block/add.tsx index 3d849a3e22..da86b5eb22 100644 --- a/src/ts/component/menu/block/add.tsx +++ b/src/ts/component/menu/block/add.tsx @@ -246,10 +246,10 @@ const MenuBlockAdd = observer(class MenuBlockAdd extends React.Component }; checkFilter () { + const { getId } = this.props; const { filter } = S.Common; - const obj = $('#menuBlockAdd'); - - filter ? obj.addClass('withFilter') : obj.removeClass('withFilter'); + + $(`#${getId()}`).toggleClass('withFilter', !!filter); }; rebind () { diff --git a/src/ts/component/menu/dataview/filter/values.tsx b/src/ts/component/menu/dataview/filter/values.tsx index 17d210be8e..ae4a0ae58b 100644 --- a/src/ts/component/menu/dataview/filter/values.tsx +++ b/src/ts/component/menu/dataview/filter/values.tsx @@ -728,14 +728,9 @@ const MenuDataviewFilterValues = observer(class MenuDataviewFilterValues extends }; checkClear (v: any) { - if (!this._isMounted) { - return; + if (this._isMounted) { + $(this.node).find('.icon.clear').toggleClass('active', v); }; - - const node = $(this.node); - const clear = node.find('.icon.clear'); - - v ? clear.addClass('active') : clear.removeClass('active'); }; onClear (e: any) { diff --git a/src/ts/component/menu/item/vertical.tsx b/src/ts/component/menu/item/vertical.tsx index ad3f321844..f61118f521 100644 --- a/src/ts/component/menu/item/vertical.tsx +++ b/src/ts/component/menu/item/vertical.tsx @@ -181,12 +181,9 @@ class MenuItemVertical extends React.Component { resize () { const node = $(this.node); - if (node.hasClass('withIcon')) { - return; + if (!node.hasClass('withIcon')) { + node.toggleClass('withIconObject', !!node.find('.iconObject').length); }; - - const icon = node.find('.iconObject'); - icon.length ? node.addClass('withIconObject') : node.removeClass('withIconObject'); }; }; diff --git a/src/ts/component/menu/quickCapture.tsx b/src/ts/component/menu/quickCapture.tsx index 3040cb4c28..f3409c9507 100644 --- a/src/ts/component/menu/quickCapture.tsx +++ b/src/ts/component/menu/quickCapture.tsx @@ -673,7 +673,7 @@ class MenuQuickCapture extends React.Component { obj.find('.item').each((i: number, item: any) => { item = $(item); - item.find('.iconObject').length ? item.addClass('withIcon') : item.removeClass('withIcon'); + item.toggleClass('withIcon', !!item.find('.iconObject').length); }); obj.css({ width: Math.min(ww - J.Size.menuBorder * 2 - sw, Math.ceil(obj.outerWidth())) }); diff --git a/src/ts/component/menu/search/text.tsx b/src/ts/component/menu/search/text.tsx index 92a94b337b..92d0d62e4b 100644 --- a/src/ts/component/menu/search/text.tsx +++ b/src/ts/component/menu/search/text.tsx @@ -195,7 +195,8 @@ class MenuSearchText extends React.Component { }); this.items = this.container.get(0).querySelectorAll(tag) || []; - this.items.length ? switcher.addClass('active') : switcher.removeClass('active'); + + switcher.toggleClass('active', !!this.items.length); this.setCnt(); this.focus(); diff --git a/src/ts/component/menu/select.tsx b/src/ts/component/menu/select.tsx index a4b8d27cea..015ac5bc29 100644 --- a/src/ts/component/menu/select.tsx +++ b/src/ts/component/menu/select.tsx @@ -449,10 +449,10 @@ const MenuSelect = observer(class MenuSelect extends React.Component { content.css({ height }); }; - withFilter ? obj.addClass('withFilter') : obj.removeClass('withFilter'); - withAdd ? obj.addClass('withAdd') : obj.removeClass('withAdd'); - noScroll ? obj.addClass('noScroll') : obj.removeClass('noScroll'); - noVirtualisation ? obj.addClass('noVirtualisation') : obj.removeClass('noVirtualisation'); + obj.toggleClass('withFilter', withFilter); + obj.toggleClass('withAdd', withAdd); + obj.toggleClass('noScroll', noScroll); + obj.toggleClass('noVirtualisation', noVirtualisation); position(); }; diff --git a/src/ts/component/page/elements/head/controlButtons.tsx b/src/ts/component/page/elements/head/controlButtons.tsx index 837aba26ab..7a7b0ad72e 100644 --- a/src/ts/component/page/elements/head/controlButtons.tsx +++ b/src/ts/component/page/elements/head/controlButtons.tsx @@ -215,9 +215,7 @@ const ControlButtons = observer(class ControlButtons extends React.Component { const idx = this.swiper.activeIndex; const length = (this.swiper.slides || []).length; - !idx ? arrowLeft.addClass('hide') : arrowLeft.removeClass('hide'); - idx >= length - 1 ? arrowRight.addClass('hide') : arrowRight.removeClass('hide'); + arrowLeft.toggleClass('hide', !idx); + arrowRight.toggleClass('hide', idx >= length - 1); }; onMenu () { diff --git a/src/ts/component/preview/link.tsx b/src/ts/component/preview/link.tsx index 57598b9b4a..8e634d7cb0 100644 --- a/src/ts/component/preview/link.tsx +++ b/src/ts/component/preview/link.tsx @@ -59,9 +59,8 @@ const PreviewLink = observer(class PreviewLink extends React.Component= max - sw - 1 ? sideRight.addClass('hide') : sideRight.removeClass('hide'); + sideLeft.toggleClass('hide', this.x <= 0); + sideRight.toggleClass('hide', this.x >= max - sw - 1); }; getMaxWidth () { diff --git a/src/ts/component/sidebar/object/item.tsx b/src/ts/component/sidebar/object/item.tsx index 681e7c6722..8f9a27895a 100644 --- a/src/ts/component/sidebar/object/item.tsx +++ b/src/ts/component/sidebar/object/item.tsx @@ -110,8 +110,8 @@ const ObjectItem = observer(class ObjectItem extends React.Component { resize () { const node = $(this.node); - node.find('.iconObject').length ? node.addClass('withIcon') : node.removeClass('withIcon'); - node.find('.descr').length ? node.addClass('withDescr') : node.removeClass('withDescr'); + node.toggleClass('withIcon', !!node.find('.iconObject').length); + node.toggleClass('withDescr', !!node.find('.descr').length); }; }); diff --git a/src/ts/component/widget/index.tsx b/src/ts/component/widget/index.tsx index 792f38a75b..dfd38fbd51 100644 --- a/src/ts/component/widget/index.tsx +++ b/src/ts/component/widget/index.tsx @@ -488,8 +488,9 @@ const WidgetIndex = observer(class WidgetIndex extends React.Component { const isClosed = Storage.checkToggle('widget', block.id); if (!isPreview) { - isClosed ? node.addClass('isClosed') : node.removeClass('isClosed'); - isClosed ? icon.addClass('isClosed') : node.removeClass('isClosed'); + node.toggleClass('isClosed', isClosed); + icon.toggleClass('isClosed', isClosed); + isClosed ? innerWrap.hide() : innerWrap.show(); }; }; diff --git a/src/ts/component/widget/space.tsx b/src/ts/component/widget/space.tsx index 67b6e27b48..2081bf5564 100644 --- a/src/ts/component/widget/space.tsx +++ b/src/ts/component/widget/space.tsx @@ -70,11 +70,10 @@ const WidgetSpace = observer(class WidgetSpace extends React.Component it.isJoining || it.isRemoving).length; const isSpaceOwner = U.Space.isMyOwner(); - const showCnt = isSpaceOwner && requestCnt; + const showCnt = isSpaceOwner && !!requestCnt; showCnt ? cnt.show() : cnt.hide(); - showCnt ? node.addClass('withCnt') : node.removeClass('withCnt'); - + node.toggleClass('withCnt', showCnt); cnt.text(requestCnt); }; diff --git a/src/ts/component/widget/view/gallery/item.tsx b/src/ts/component/widget/view/gallery/item.tsx index 7e2d0309a9..694a0bcea1 100644 --- a/src/ts/component/widget/view/gallery/item.tsx +++ b/src/ts/component/widget/view/gallery/item.tsx @@ -166,9 +166,8 @@ const WidgetBoardItem = observer(class WidgetBoardItem extends React.Component

{ const node = $(this.node); - const icon = node.find('.iconObject'); - icon.length ? node.addClass('withIcon') : node.removeClass('withIcon'); + node.toggleClass('withIcon', !!node.find('.iconObject').length); }); }; diff --git a/src/ts/component/widget/view/list/item.tsx b/src/ts/component/widget/view/list/item.tsx index 085802146f..c8b53e0bb7 100644 --- a/src/ts/component/widget/view/list/item.tsx +++ b/src/ts/component/widget/view/list/item.tsx @@ -184,9 +184,8 @@ const WidgetListItem = observer(class WidgetListItem extends React.Component { const node = $(this.node); - const icon = node.find('.iconObject'); - icon.length ? node.addClass('withIcon') : node.removeClass('withIcon'); + node.toggleClass('withIcon', !!node.find('.iconObject').length); }); }; diff --git a/src/ts/lib/preview.ts b/src/ts/lib/preview.ts index ae79caf957..c625d6c54f 100644 --- a/src/ts/lib/preview.ts +++ b/src/ts/lib/preview.ts @@ -202,7 +202,7 @@ class Preview { }); }; - passThrough ? obj.addClass('passThrough') : obj.removeClass('passThrough'); + obj.toggleClass('passThrough', passThrough); obj.off('mouseleave.preview').on('mouseleave.preview', () => this.previewHide(true)); this.previewHide(true); diff --git a/src/ts/lib/sidebar.ts b/src/ts/lib/sidebar.ts index 02790c7027..a12cb9180d 100644 --- a/src/ts/lib/sidebar.ts +++ b/src/ts/lib/sidebar.ts @@ -44,13 +44,10 @@ class Sidebar { this.resizePage(J.Size.sidebar.width.default, false); }; - if (this.data.isClosed) { - vault.addClass('isClosed'); - this.obj.addClass('isClosed'); - } else { - vault.removeClass('isClosed'); - this.obj.removeClass('isClosed'); - }; + const { isClosed } = this.data; + + vault.toggleClass('isClosed', isClosed); + this.obj.toggleClass('isClosed', isClosed); }; initObjects () { @@ -237,22 +234,14 @@ class Sidebar { this.footer.css({ width: '' }); this.dummy.css({ width: width + vw }); - if (animate) { - this.header.addClass('sidebarAnimation'); - this.page.addClass('sidebarAnimation'); - this.footer.addClass('sidebarAnimation'); - this.dummy.addClass('sidebarAnimation'); - this.toggleButton.addClass('sidebarAnimation'); - } else { - this.header.removeClass('sidebarAnimation'); - this.page.removeClass('sidebarAnimation'); - this.footer.removeClass('sidebarAnimation'); - this.dummy.removeClass('sidebarAnimation'); - this.toggleButton.removeClass('sidebarAnimation'); - }; + this.header.toggleClass('sidebarAnimation', animate); + this.footer.toggleClass('sidebarAnimation', animate); + this.page.toggleClass('sidebarAnimation', animate); + this.dummy.toggleClass('sidebarAnimation', animate); + this.toggleButton.toggleClass('sidebarAnimation', animate); navigation?.position(width + vw, animate); - width ? this.header.addClass('withSidebar') : this.header.removeClass('withSidebar'); + this.header.toggleClass('withSidebar', !!width); this.page.css({ width: pageWidth }); this.loader.css({ width: pageWidth, right: 0 }); diff --git a/src/ts/store/block.ts b/src/ts/store/block.ts index 60bf2620f2..65b6cfa588 100644 --- a/src/ts/store/block.ts +++ b/src/ts/store/block.ts @@ -503,7 +503,7 @@ class BlockStore { toggle (rootId: string, blockId: string, v: boolean) { const element = $(`#block-${blockId}`); - v ? element.addClass('isToggled') : element.removeClass('isToggled'); + element.toggleClass('isToggled', v); Storage.setToggle(rootId, blockId, v); U.Common.triggerResizeEditor(keyboard.isPopup()); diff --git a/src/ts/store/common.ts b/src/ts/store/common.ts index 365d41ee3c..568f820b8c 100644 --- a/src/ts/store/common.ts +++ b/src/ts/store/common.ts @@ -384,11 +384,9 @@ class CommonStore { }; fullscreenSet (v: boolean) { - const body = $('body'); - this.isFullScreen = v; - v ? body.addClass('isFullScreen') : body.removeClass('isFullScreen'); + $('body').toggleClass('isFullScreen', v); $(window).trigger('resize'); }; @@ -512,7 +510,7 @@ class CommonStore { set(this.configObj, newConfig); this.configObj.debug = this.configObj.debug || {}; - this.configObj.debug.ui ? html.addClass('debug') : html.removeClass('debug'); + html.toggleClass('debug', this.configObj.debug.ui); }; spaceStorageSet (value: Partial) { diff --git a/src/ts/store/menu.ts b/src/ts/store/menu.ts index 69bcf5c7f6..596c02bd47 100644 --- a/src/ts/store/menu.ts +++ b/src/ts/store/menu.ts @@ -131,7 +131,7 @@ class MenuStore { }; if (el.length) { - noAnimation ? el.addClass('noAnimation') : el.removeClass('noAnimation'); + el.toggleClass('noAnimation', noAnimation); el.css({ transform: '' }).removeClass('show'); };