From 70c998562c8560283a7d6b9a1ae78b9207e3720f Mon Sep 17 00:00:00 2001
From: bobzel <zzzman@gmail.com>
Date: Mon, 31 Oct 2022 13:26:52 -0400
Subject: cleaning up link count icon to be part of documentLinks view and to
 appear on tab views that have links.

---
 src/client/views/nodes/DocumentLinksButton.tsx | 67 ++++++++++++--------------
 1 file changed, 31 insertions(+), 36 deletions(-)

(limited to 'src/client/views/nodes/DocumentLinksButton.tsx')

diff --git a/src/client/views/nodes/DocumentLinksButton.tsx b/src/client/views/nodes/DocumentLinksButton.tsx
index 9ffbf8e37..1d455ad08 100644
--- a/src/client/views/nodes/DocumentLinksButton.tsx
+++ b/src/client/views/nodes/DocumentLinksButton.tsx
@@ -4,19 +4,18 @@ import { action, computed, observable, runInAction } from 'mobx';
 import { observer } from 'mobx-react';
 import { Doc, Opt } from '../../../fields/Doc';
 import { StrCast } from '../../../fields/Types';
-import { TraceMobx } from '../../../fields/util';
 import { emptyFunction, returnFalse, setupMoveUpEvents, StopEvent } from '../../../Utils';
 import { DocUtils } from '../../documents/Documents';
 import { DragManager } from '../../util/DragManager';
 import { Hypothesis } from '../../util/HypothesisUtils';
 import { LinkManager } from '../../util/LinkManager';
 import { undoBatch, UndoManager } from '../../util/UndoManager';
-import { Colors } from '../global/globalEnums';
 import './DocumentLinksButton.scss';
 import { DocumentView } from './DocumentView';
 import { LinkDescriptionPopup } from './LinkDescriptionPopup';
 import { TaskCompletionBox } from './TaskCompletedBox';
 import React = require('react');
+import _ = require('lodash');
 
 const higflyout = require('@hig/flyout');
 export const { anchorPoints } = higflyout;
@@ -24,10 +23,12 @@ export const Flyout = higflyout.default;
 
 interface DocumentLinksButtonProps {
     View: DocumentView;
-    Offset?: (number | undefined)[];
+    Bottom?: boolean;
     AlwaysOn?: boolean;
     InMenu?: boolean;
+    OnHover?: boolean;
     StartLink?: boolean; //whether the link HAS been started (i.e. now needs to be completed)
+    ShowCount?: boolean;
     scaling?: () => number; // how uch doc is scaled so that link buttons can invert it
 }
 @observer
@@ -119,7 +120,6 @@ export class DocumentLinksButton extends React.Component<DocumentLinksButtonProp
                 DocumentLinksButton.StartLink = this.props.View.props.Document;
                 DocumentLinksButton.StartLinkView = this.props.View;
             }
-            //action(() => Doc.BrushDoc(this.props.View.Document));
         }
     };
 
@@ -256,28 +256,32 @@ export class DocumentLinksButton extends React.Component<DocumentLinksButtonProp
      * todo:glr / anh seperate functionality such as onClick onPointerDown of link menu button
      */
     @computed get linkButtonInner() {
-        const btnDim = '30px';
-        const link = <img style={{ width: '22px', height: '16px' }} src={`/assets/${'link.png'}`} />;
+        const btnDim = 30;
         const isActive = DocumentLinksButton.StartLink === this.props.View.props.Document && this.props.StartLink;
-        return !this.props.InMenu ? (
-            <div className="documentLinksButton-cont" style={{ left: this.props.Offset?.[0], top: this.props.Offset?.[1], right: this.props.Offset?.[2], bottom: this.props.Offset?.[3] }}>
-                <div
-                    className={'documentLinksButton'}
-                    onPointerDown={this.onLinkMenuOpen}
-                    onClick={this.onLinkClick}
-                    style={{
-                        backgroundColor: Colors.LIGHT_BLUE,
-                        color: Colors.BLACK,
-                        fontSize: '20px',
-                        width: btnDim,
-                        height: btnDim,
-                    }}>
-                    {Array.from(this.filteredLinks).length}
-                </div>
+        const scaling = Math.min(1, this.props.scaling?.() || 1);
+        const showLinkCount = (onHover?: boolean, offset?: boolean) => (
+            <div
+                className="documentLinksButton-showCount"
+                onPointerDown={this.onLinkMenuOpen}
+                style={{
+                    fontSize: (onHover ? btnDim / 2 : 20) * scaling,
+                    width: (onHover ? btnDim / 2 : btnDim) * scaling,
+                    height: (onHover ? btnDim / 2 : btnDim) * scaling,
+                    bottom: offset ? 5 * scaling : onHover ? (-btnDim / 2) * scaling : undefined,
+                }}>
+                <span style={{ width: '100%', display: 'inline-block', textAlign: 'center' }}>{Array.from(this.filteredLinks).length}</span>
             </div>
+        );
+        return this.props.ShowCount ? (
+            showLinkCount(this.props.OnHover, this.props.Bottom)
         ) : (
             <div className="documentLinksButton-menu">
-                {this.props.InMenu && !this.props.StartLink && DocumentLinksButton.StartLink !== this.props.View.props.Document ? ( //if the origin node is not this node
+                {this.props.StartLink ? ( //if link has been started from current node, then set behavior of link button to deactivate linking when clicked again
+                    <div className={`documentLinksButton ${isActive ? `startLink` : ``}`} ref={this._linkButton} onPointerDown={isActive ? StopEvent : this.onLinkButtonDown} onClick={isActive ? this.clearLinks : this.onLinkClick}>
+                        <FontAwesomeIcon className="documentdecorations-icon" icon="link" />
+                    </div>
+                ) : null}
+                {!this.props.StartLink && DocumentLinksButton.StartLink !== this.props.View.props.Document ? ( //if the origin node is not this node
                     <div
                         className={'documentLinksButton-endLink'}
                         ref={this._linkButton}
@@ -286,34 +290,25 @@ export class DocumentLinksButton extends React.Component<DocumentLinksButtonProp
                         <FontAwesomeIcon className="documentdecorations-icon" icon="link" />
                     </div>
                 ) : null}
-                {this.props.InMenu && this.props.StartLink ? ( //if link has been started from current node, then set behavior of link button to deactivate linking when clicked again
-                    <div className={`documentLinksButton ${isActive ? `startLink` : ``}`} ref={this._linkButton} onPointerDown={isActive ? StopEvent : this.onLinkButtonDown} onClick={isActive ? this.clearLinks : this.onLinkClick}>
-                        <FontAwesomeIcon className="documentdecorations-icon" icon="link" />
-                    </div>
-                ) : null}
             </div>
         );
     }
 
     render() {
-        TraceMobx();
-
         const menuTitle = this.props.StartLink ? 'Drag or tap to start link' : 'Tap to complete link';
         const buttonTitle = 'Tap to view links; double tap to open link collection';
-        const title = this.props.InMenu ? menuTitle : buttonTitle;
+        const title = this.props.ShowCount ? buttonTitle : menuTitle;
 
         //render circular tooltip if it isn't set to invisible and show the number of doc links the node has, and render inner-menu link button for starting/stopping links if currently in menu
         return !Array.from(this.filteredLinks).length && !this.props.AlwaysOn ? null : (
             <div
                 className="documentLinksButton-wrapper"
                 style={{
-                    transform: `scale(${this.props.scaling?.() || 1})`,
+                    position: this.props.InMenu ? 'relative' : 'absolute',
+                    top: 0,
+                    pointerEvents: 'none',
                 }}>
-                {(this.props.InMenu && (DocumentLinksButton.StartLink || this.props.StartLink)) || (!DocumentLinksButton.LinkEditorDocView && !this.props.InMenu) ? (
-                    <Tooltip title={<div className="dash-tooltip">{title}</div>}>{this.linkButtonInner}</Tooltip>
-                ) : (
-                    this.linkButtonInner
-                )}
+                <Tooltip title={!DocumentLinksButton.LinkEditorDocView ? <div className="dash-tooltip">{title}</div> : <></>}>{this.linkButtonInner}</Tooltip>
             </div>
         );
     }
-- 
cgit v1.2.3-70-g09d2

