aboutsummaryrefslogtreecommitdiff
path: root/src/client/views/DocumentButtonBar.tsx
diff options
context:
space:
mode:
authorbobzel <zzzman@gmail.com>2023-12-14 00:07:52 -0500
committerbobzel <zzzman@gmail.com>2023-12-14 00:07:52 -0500
commitcebe9d2a567c20b99c8c394cfa598ee9d4d53ece (patch)
treec33df9a3dc80cb199002610cc38645976023eff9 /src/client/views/DocumentButtonBar.tsx
parent1cf241544f8063e3d71406238a584299b6ced794 (diff)
a bunch more fixes to making things observable. fixed calling super.componentDidUpdate on subsclasses
Diffstat (limited to 'src/client/views/DocumentButtonBar.tsx')
-rw-r--r--src/client/views/DocumentButtonBar.tsx133
1 files changed, 10 insertions, 123 deletions
diff --git a/src/client/views/DocumentButtonBar.tsx b/src/client/views/DocumentButtonBar.tsx
index 50ca3af06..47829d12a 100644
--- a/src/client/views/DocumentButtonBar.tsx
+++ b/src/client/views/DocumentButtonBar.tsx
@@ -3,32 +3,26 @@ import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import { Tooltip } from '@mui/material';
import { action, computed, makeObservable, observable, runInAction } from 'mobx';
import { observer } from 'mobx-react';
+import * as React from 'react';
+import { emptyFunction, returnFalse, setupMoveUpEvents, simulateMouseClick } from '../../Utils';
import { Doc } from '../../fields/Doc';
import { RichTextField } from '../../fields/RichTextField';
-import { Cast, DocCast, NumCast } from '../../fields/Types';
-import { emptyFunction, returnFalse, setupMoveUpEvents, simulateMouseClick } from '../../Utils';
-import { GoogleAuthenticationManager } from '../apis/GoogleAuthenticationManager';
-import { Pulls, Pushes } from '../apis/google_docs/GoogleApiClientUtils';
-import { Docs, DocUtils } from '../documents/Documents';
+import { Cast, DocCast } from '../../fields/Types';
+import { DocUtils } from '../documents/Documents';
import { DragManager } from '../util/DragManager';
import { IsFollowLinkScript } from '../util/LinkFollower';
import { SelectionManager } from '../util/SelectionManager';
import { SharingManager } from '../util/SharingManager';
-import { undoBatch, UndoManager } from '../util/UndoManager';
-import { CollectionDockingView } from './collections/CollectionDockingView';
-import { TabDocView } from './collections/TabDocView';
+import { UndoManager, undoBatch } from '../util/UndoManager';
import './DocumentButtonBar.scss';
+import { ObservableReactComponent } from './ObservableReactComponent';
+import { TabDocView } from './collections/TabDocView';
import { Colors } from './global/globalEnums';
import { LinkPopup } from './linking/LinkPopup';
-import { MetadataEntryMenu } from './MetadataEntryMenu';
import { DocumentLinksButton } from './nodes/DocumentLinksButton';
-import { DocumentView, DocumentViewInternal, OpenWhere, OpenWhereMod } from './nodes/DocumentView';
+import { DocumentView, DocumentViewInternal, OpenWhere } from './nodes/DocumentView';
import { DashFieldView } from './nodes/formattedText/DashFieldView';
-import { GoogleRef } from './nodes/formattedText/FormattedTextBox';
import { PinProps } from './nodes/trails';
-import { TemplateMenu } from './TemplateMenu';
-import * as React from 'react';
-import { ObservableReactComponent } from './ObservableReactComponent';
// import * as higflyout from '@hig/flyout';
// export const { anchorPoints } = higflyout;
// export const Flyout = higflyout.default;
@@ -60,10 +54,10 @@ export class DocumentButtonBar extends ObservableReactComponent<{ views: () => (
public static hasPushedHack = false;
public static hasPulledHack = false;
- constructor(props: { views: () => (DocumentView | undefined)[] }) {
+ constructor(props: any) {
super(props);
- DocumentButtonBar.Instance = this;
makeObservable(this);
+ DocumentButtonBar.Instance = this;
}
public startPullOutcome = action((success: boolean) => {
@@ -115,103 +109,6 @@ export class DocumentButtonBar extends ObservableReactComponent<{ views: () => (
return this._props.views()?.[0];
}
- @computed
- get considerGoogleDocsPush() {
- const targetDoc = this.view0?.Document;
- const published = targetDoc && Doc.GetProto(targetDoc)[GoogleRef] !== undefined;
- const animation = this.isAnimatingPulse ? 'shadow-pulse 1s linear infinite' : 'none';
- return !targetDoc ? null : (
- <Tooltip
- title={
- <>
- <div className="dash-tooltip">{`${published ? 'Push' : 'Publish'} to Google Docs`}</div>
- </>
- }>
- <div
- className="documentButtonBar-button"
- style={{ animation }}
- onClick={async () => {
- await GoogleAuthenticationManager.Instance.fetchOrGenerateAccessToken();
- !published && runInAction(() => (this.isAnimatingPulse = true));
- DocumentButtonBar.hasPushedHack = false;
- targetDoc[Pushes] = NumCast(targetDoc[Pushes]) + 1;
- }}>
- <FontAwesomeIcon className="documentdecorations-icon" icon={published ? (this.pushIcon as any) : cloud} size={published ? 'sm' : 'xs'} />
- </div>
- </Tooltip>
- );
- }
-
- @computed
- get considerGoogleDocsPull() {
- const targetDoc = this.view0?.Document;
- const dataDoc = targetDoc && Doc.GetProto(targetDoc);
- const animation = this.isAnimatingFetch ? 'spin 0.5s linear infinite' : 'none';
-
- const title = (() => {
- switch (this.openHover) {
- default:
- case UtilityButtonState.Default:
- return `${!dataDoc?.googleDocUnchanged ? 'Pull from' : 'Fetch'} Google Docs`;
- case UtilityButtonState.OpenRight:
- return 'Open in Right Split';
- case UtilityButtonState.OpenExternally:
- return 'Open in new Browser Tab';
- }
- })();
-
- return !targetDoc || !dataDoc || !dataDoc[GoogleRef] ? null : (
- <Tooltip title={<div className="dash-tooltip">{title}</div>}>
- <div
- className="documentButtonBar-button"
- style={{ backgroundColor: this.pullColor }}
- onPointerEnter={action(e => {
- if (e.altKey) {
- this.openHover = UtilityButtonState.OpenExternally;
- } else if (e.shiftKey) {
- this.openHover = UtilityButtonState.OpenRight;
- }
- })}
- onPointerLeave={action(() => (this.openHover = UtilityButtonState.Default))}
- onClick={async e => {
- const googleDocUrl = `https://docs.google.com/document/d/${dataDoc[GoogleRef]}/edit`;
- if (e.shiftKey) {
- e.preventDefault();
- let googleDoc = await Cast(dataDoc.googleDoc, Doc);
- if (!googleDoc) {
- const options = { _width: 600, _nativeWidth: 960, _nativeHeight: 800, data_useCors: false };
- googleDoc = Docs.Create.WebDocument(googleDocUrl, options);
- dataDoc.googleDoc = googleDoc;
- }
- CollectionDockingView.AddSplit(googleDoc, OpenWhereMod.right);
- } else if (e.altKey) {
- e.preventDefault();
- window.open(googleDocUrl);
- } else {
- this.clearPullColor();
- DocumentButtonBar.hasPulledHack = false;
- targetDoc[Pulls] = NumCast(targetDoc[Pulls]) + 1;
- dataDoc.googleDocUnchanged && runInAction(() => (this.isAnimatingFetch = true));
- }
- }}>
- <FontAwesomeIcon
- className="documentdecorations-icon"
- size="sm"
- style={{ WebkitAnimation: animation, MozAnimation: animation }}
- icon={(() => {
- // prettier-ignore
- switch (this.openHover) {
- default:
- case UtilityButtonState.Default: return dataDoc.googleDocUnchanged === false ? (this.pullIcon as any) : fetch;
- case UtilityButtonState.OpenRight: return 'arrow-alt-circle-right';
- case UtilityButtonState.OpenExternally: return 'share';
- }
- })()}
- />
- </div>
- </Tooltip>
- );
- }
@observable subFollow = '';
@computed
get followLinkButton() {
@@ -579,8 +476,6 @@ export class DocumentButtonBar extends ObservableReactComponent<{ views: () => (
if (!doc || !this.view0) return null;
const isText = () => doc[this.view0!.LayoutFieldKey] instanceof RichTextField;
- const considerPull = () => isText() && this.considerGoogleDocsPull;
- const considerPush = () => isText() && this.considerGoogleDocsPush;
return (
<div className="documentButtonBar">
<div className="documentButtonBar-button">
@@ -608,14 +503,6 @@ export class DocumentButtonBar extends ObservableReactComponent<{ views: () => (
<div className="documentButtonBar-button">{this.pinButton}</div>
<div className="documentButtonBar-button">{this.recordButton}</div>
{!Doc.UserDoc()['documentLinksButton-fullMenu'] ? null : <div className="documentButtonBar-button">{this.shareButton}</div>}
- {!Doc.UserDoc()['documentLinksButton-fullMenu'] ? null : (
- <div className="documentButtonBar-button" style={{ display: !considerPush() ? 'none' : '' }}>
- {this.considerGoogleDocsPush}
- </div>
- )}
- <div className="documentButtonBar-button" style={{ display: !considerPull() ? 'none' : '' }}>
- {this.considerGoogleDocsPull}
- </div>
<div className="documentButtonBar-button">{this.menuButton}</div>
</div>
);