aboutsummaryrefslogtreecommitdiff
path: root/src/client
diff options
context:
space:
mode:
Diffstat (limited to 'src/client')
-rw-r--r--src/client/apis/HypothesisAuthenticationManager.tsx164
-rw-r--r--src/client/apis/hypothesis/HypothesisUtils.ts18
-rw-r--r--src/client/util/CurrentUserUtils.ts1
-rw-r--r--src/client/util/SettingsManager.tsx6
-rw-r--r--src/client/views/GlobalKeyHandler.ts2
-rw-r--r--src/client/views/linking/LinkMenuItem.tsx2
6 files changed, 4 insertions, 189 deletions
diff --git a/src/client/apis/HypothesisAuthenticationManager.tsx b/src/client/apis/HypothesisAuthenticationManager.tsx
deleted file mode 100644
index 653f21a7a..000000000
--- a/src/client/apis/HypothesisAuthenticationManager.tsx
+++ /dev/null
@@ -1,164 +0,0 @@
-import { observable, action, reaction, runInAction, IReactionDisposer } from "mobx";
-import { observer } from "mobx-react";
-import * as React from "react";
-import MainViewModal from "../views/MainViewModal";
-import { Opt } from "../../fields/Doc";
-import { Networking } from "../Network";
-import "./HypothesisAuthenticationManager.scss";
-import { Scripting } from "../util/Scripting";
-import { Hypothesis } from "./hypothesis/HypothesisUtils";
-
-const prompt = "Paste authorization code here...";
-
-@observer
-export default class HypothesisAuthenticationManager extends React.Component<{}> {
- public static Instance: HypothesisAuthenticationManager;
- private authenticationLink: Opt<string> = undefined;
- @observable private openState = false;
- @observable private authenticationCode: Opt<string> = undefined;
- @observable private showPasteTargetState = false;
- @observable private success: Opt<boolean> = undefined;
- @observable private displayLauncher = true;
- @observable private credentials: { username: string, apiKey: string } | undefined;
- private disposer: Opt<IReactionDisposer>;
-
- private set isOpen(value: boolean) {
- runInAction(() => this.openState = value);
- }
-
- private set shouldShowPasteTarget(value: boolean) {
- runInAction(() => this.showPasteTargetState = value);
- }
-
- public cancel() {
- this.openState && this.resetState(0, 0);
- }
-
- public fetchAccessToken = async (displayIfFound = false) => {
- const jsonResponse = await Networking.FetchFromServer("/readHypothesisAccessToken");
- const response = jsonResponse !== "" ? JSON.parse(jsonResponse) : undefined;
- // if this is an authentication url, activate the UI to register the new access token
- if (!response) {
- this.isOpen = true;
- this.authenticationLink = response;
- return new Promise<string>(async resolve => {
- this.disposer?.();
- this.disposer = reaction(
- () => this.authenticationCode,
- async authenticationCode => {
- const userProfile = authenticationCode && await Hypothesis.fetchUser(authenticationCode);
- if (userProfile && userProfile.userid !== null) {
- this.disposer?.();
- const hypothesisUsername = Hypothesis.extractUsername(userProfile.userid); // extract username from profile
- Networking.PostToServer("/writeHypothesisAccessToken", { authenticationCode, hypothesisUsername });
- runInAction(() => {
- this.success = true;
- this.credentials = { username: hypothesisUsername, apiKey: authenticationCode! };
- });
- this.resetState();
- resolve(authenticationCode);
- }
- }
- );
- });
- }
-
- if (displayIfFound) {
- runInAction(() => {
- this.success = true;
- this.credentials = response;
- });
- this.resetState(-1, -1);
- this.isOpen = true;
- }
- return response;
- }
-
- resetState = action((visibleForMS: number = 3000, fadesOutInMS: number = 500) => {
- if (!visibleForMS && !fadesOutInMS) {
- runInAction(() => {
- this.isOpen = false;
- this.success = undefined;
- this.displayLauncher = true;
- this.credentials = undefined;
- this.shouldShowPasteTarget = false;
- this.authenticationCode = undefined;
- });
- return;
- }
- this.authenticationCode = undefined;
- this.displayLauncher = false;
- this.shouldShowPasteTarget = false;
- if (visibleForMS > 0 && fadesOutInMS > 0) {
- setTimeout(action(() => {
- this.isOpen = false;
- setTimeout(action(() => {
- this.success = undefined;
- this.displayLauncher = true;
- this.credentials = undefined;
- }), fadesOutInMS);
- }), visibleForMS);
- }
- });
-
- constructor(props: {}) {
- super(props);
- HypothesisAuthenticationManager.Instance = this;
- }
-
- private get renderPrompt() {
- return (
- <div className={'authorize-container'}>
-
- {this.displayLauncher ? <button
- className={"dispatch"}
- onClick={() => {
- this.shouldShowPasteTarget = true;
- }}
- style={{ marginBottom: this.showPasteTargetState ? 15 : 0 }}
- >Authorize a Hypothesis account...</button> : (null)}
- {this.showPasteTargetState ? <input
- className={'paste-target'}
- onChange={action(e => this.authenticationCode = e.currentTarget.value)}
- placeholder={prompt}
- /> : (null)}
- {this.credentials ?
- <>
- <span
- className={'welcome'}
- >Welcome to Dash, {this.credentials.username}
- </span>
- <div
- className={'disconnect'}
- onClick={async () => {
- await Networking.FetchFromServer("/revokeHypothesisAccessToken");
- this.resetState(0, 0);
- }}
- >Disconnect Account</div>
- </> : (null)}
- </div>
- );
- }
-
- private get dialogueBoxStyle() {
- const borderColor = this.success === undefined ? "black" : this.success ? "green" : "red";
- return { borderColor, transition: "0.2s borderColor ease", zIndex: 1002 };
- }
-
- render() {
- return (
- <MainViewModal
- isDisplayed={this.openState}
- interactive={true}
- contents={this.renderPrompt}
- // overlayDisplayedOpacity={0.9}
- dialogueBoxStyle={this.dialogueBoxStyle}
- overlayStyle={{ zIndex: 1001 }}
- closeOnExternalClick={action(() => this.isOpen = false)}
- />
- );
- }
-
-}
-
-Scripting.addGlobal("HypothesisAuthenticationManager", HypothesisAuthenticationManager); \ No newline at end of file
diff --git a/src/client/apis/hypothesis/HypothesisUtils.ts b/src/client/apis/hypothesis/HypothesisUtils.ts
index 8eaad2905..a9d807976 100644
--- a/src/client/apis/hypothesis/HypothesisUtils.ts
+++ b/src/client/apis/hypothesis/HypothesisUtils.ts
@@ -1,5 +1,4 @@
import { StrCast, Cast } from "../../../fields/Types";
-import HypothesisAuthenticationManager from "../HypothesisAuthenticationManager";
import { SearchUtil } from "../../util/SearchUtil";
import { action } from "mobx";
import { Doc } from "../../../fields/Doc";
@@ -8,18 +7,6 @@ import { WebField } from "../../../fields/URLField";
import { DocumentManager } from "../../util/DocumentManager";
export namespace Hypothesis {
- export const fetchUser = async (apiKey: string) => {
- const response = await fetch('https://api.hypothes.is/api/profile', {
- headers: {
- 'Authorization': `Bearer ${apiKey}`,
- },
- });
- if (response.ok) {
- return response.json();
- } else {
- throw new Error('DASH: Error in fetchUser GET request');
- }
- };
// Send Hypothes.is client request to edit an annotation to add a Dash hyperlink
export const makeLink = async (title: string, url: string, annotationId: string) => {
@@ -40,6 +27,7 @@ export namespace Hypothesis {
// Construct an URL which will automatically scroll the web page to a specific annotation's position
export const makeAnnotationUrl = (annotationId: string, baseUrl: string) => {
+ console.log("baseUrl", baseUrl, annotationId);
return `${baseUrl}#annotations:${annotationId}`;
};
@@ -58,8 +46,8 @@ export namespace Hypothesis {
doc.type === DocumentType.WEB && doc.data
);
filteredDocs.forEach(doc => {
- console.log(Cast(doc.data, WebField)?.url.href);
- if (uri === Cast(doc.data, WebField)?.url.href) results.push(doc); // TODO check history? imperfect matches?
+ console.log(uri, Cast(doc.data, WebField)?.url.href, uri === Cast(doc.data, WebField)?.url.href);
+ (uri === Cast(doc.data, WebField)?.url.href) && results.push(doc); // TODO check history? imperfect matches?
});
}));
diff --git a/src/client/util/CurrentUserUtils.ts b/src/client/util/CurrentUserUtils.ts
index ff33d35e0..1fe611b12 100644
--- a/src/client/util/CurrentUserUtils.ts
+++ b/src/client/util/CurrentUserUtils.ts
@@ -441,7 +441,6 @@ export class CurrentUserUtils {
{ toolTip: "Drag a document previewer", title: "Prev", icon: "expand", click: 'openOnRight(getCopy(this.dragFactory, true))', drag: 'getCopy(this.dragFactory,true)', dragFactory: doc.emptyDocHolder as Doc },
{ toolTip: "Toggle a Calculator REPL", title: "repl", icon: "calculator", click: 'addOverlayWindow("ScriptingRepl", { x: 300, y: 100, width: 200, height: 200, title: "Scripting REPL" })' },
{ toolTip: "Connect a Google Account", title: "Google Account", icon: "external-link-alt", click: 'GoogleAuthenticationManager.Instance.fetchOrGenerateAccessToken(true)' },
- { toolTip: "Connect a Hypothesis Account", title: "Hypothesis Account", icon: "heading", click: 'HypothesisAuthenticationManager.Instance.fetchAccessToken(true)' },
];
}
diff --git a/src/client/util/SettingsManager.tsx b/src/client/util/SettingsManager.tsx
index 90d59aa51..a9c2d5e15 100644
--- a/src/client/util/SettingsManager.tsx
+++ b/src/client/util/SettingsManager.tsx
@@ -12,7 +12,6 @@ import { CurrentUserUtils } from "./CurrentUserUtils";
import { Utils } from "../../Utils";
import { Doc } from "../../fields/Doc";
import GroupManager from "./GroupManager";
-import HypothesisAuthenticationManager from "../apis/HypothesisAuthenticationManager";
import GoogleAuthenticationManager from "../apis/GoogleAuthenticationManager";
import { togglePlaygroundMode } from "../../fields/util";
@@ -92,10 +91,6 @@ export default class SettingsManager extends React.Component<{}> {
googleAuthorize = (event: any) => {
GoogleAuthenticationManager.Instance.fetchOrGenerateAccessToken(true);
}
- @action
- hypothesisAuthorize = (event: any) => {
- HypothesisAuthenticationManager.Instance.fetchAccessToken(true);
- }
@action
togglePlaygroundMode = () => {
@@ -118,7 +113,6 @@ export default class SettingsManager extends React.Component<{}> {
<button onClick={this.noviceToggle} value="data">{`Set ${Doc.UserDoc().noviceMode ? "developer" : "novice"} mode`}</button>
<button onClick={this.togglePlaygroundMode}>{`${this.playgroundMode ? "Disable" : "Enable"} playground mode`}</button>
<button onClick={this.googleAuthorize} value="data">{`Link to Google`}</button>
- <button onClick={this.hypothesisAuthorize} value="data">{`Link to Hypothes.is`}</button>
<button onClick={() => GroupManager.Instance.open()}>Manage groups</button>
<button onClick={() => window.location.assign(Utils.prepend("/logout"))}>
{CurrentUserUtils.GuestWorkspace ? "Exit" : "Log Out"}
diff --git a/src/client/views/GlobalKeyHandler.ts b/src/client/views/GlobalKeyHandler.ts
index 086085db5..e1232e6f8 100644
--- a/src/client/views/GlobalKeyHandler.ts
+++ b/src/client/views/GlobalKeyHandler.ts
@@ -7,7 +7,6 @@ import { List } from "../../fields/List";
import { ScriptField } from "../../fields/ScriptField";
import { Cast, PromiseValue } from "../../fields/Types";
import GoogleAuthenticationManager from "../apis/GoogleAuthenticationManager";
-import HypothesisAuthenticationManager from "../apis/HypothesisAuthenticationManager";
import { DocServer } from "../DocServer";
import { DocumentType } from "../documents/DocumentTypes";
import { DictationManager } from "../util/DictationManager";
@@ -107,7 +106,6 @@ export default class KeyManager {
DictationManager.Controls.stop();
// RecommendationsBox.Instance.closeMenu();
GoogleAuthenticationManager.Instance.cancel();
- HypothesisAuthenticationManager.Instance.cancel();
SharingManager.Instance.close();
GroupManager.Instance.close();
CollectionFreeFormViewChrome.Instance.clearKeep();
diff --git a/src/client/views/linking/LinkMenuItem.tsx b/src/client/views/linking/LinkMenuItem.tsx
index 079e130ea..8503bcbeb 100644
--- a/src/client/views/linking/LinkMenuItem.tsx
+++ b/src/client/views/linking/LinkMenuItem.tsx
@@ -156,7 +156,7 @@ export class LinkMenuItem extends React.Component<LinkMenuItemProps> {
const linkDoc = this.props.linkDoc;
if (linkDoc.followLinkLocation === "openExternal" && this.props.destinationDoc.type === DocumentType.WEB) {
- window.open(Hypothesis.makeAnnotationUrl(StrCast(this.props.linkDoc.annotationId), '_blank'));
+ window.open(Hypothesis.makeAnnotationUrl(StrCast(linkDoc.annotationId), StrCast(linkDoc.annotationUri)), '_blank');
return;
}