From 42ee138ccff5f3f7c0dfae529f42e0df0a03da65 Mon Sep 17 00:00:00 2001 From: Jonathan Carlson Date: Tue, 19 Jan 2021 15:18:36 -0800 Subject: [PATCH 1/6] Adds an endpoint variable for consistency in functions that call makeServerRequest --- src/lib/fetch.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/lib/fetch.js b/src/lib/fetch.js index 16d4871f..0977969d 100644 --- a/src/lib/fetch.js +++ b/src/lib/fetch.js @@ -85,7 +85,8 @@ export const updatePrograms = (uid = "", programs) => { export const createUser = (uid) => { console.log("creating user"); - return makeServerRequest({ uid }, "user/create", "post"); + const endpoint = `user/create`; + return makeServerRequest({ uid }, endpoint, "post"); }; /** @@ -106,7 +107,8 @@ export const updateUserData = (uid = "", userData) => { export const createSketch = (data) => { const { uid, ...rest } = data; - return makeServerRequest({ uid, program: rest }, "program/create"); + const endpoint = `program/create`; + return makeServerRequest({ uid, program: rest }, endpoint); }; /** @@ -116,7 +118,8 @@ export const createSketch = (data) => { export const deleteSketch = (data) => { const { uid, name } = data; - return makeServerRequest({ uid, pid: name }, "program/delete", "delete"); + const endpoint = `program/delete`; + return makeServerRequest({ uid, pid: name }, endpoint, "delete"); }; /** From bf96af0489d173e345b5e2503c0265c10b8daf93 Mon Sep 17 00:00:00 2001 From: Jonathan Carlson Date: Tue, 2 Feb 2021 19:27:50 -0800 Subject: [PATCH 2/6] adds createCollab method to fetch lib --- src/lib/fetch.js | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/lib/fetch.js b/src/lib/fetch.js index 0977969d..07409fe8 100644 --- a/src/lib/fetch.js +++ b/src/lib/fetch.js @@ -134,3 +134,14 @@ export const getSketch = async (docID) => { let sketch = await result.json(); return { ok, sketch }; }; + +/** + * creates a CollabSession with passed-in data + * @param {string} data //required data to create program + */ + +export const createCollab = async (data) => { + const { uid } = data; + const endpoint = `collab/create`; + return makeServerRequest({ uid }, endpoint); +}; From 7e0ff7a4364cc1989858036adab2436b47d23b93 Mon Sep 17 00:00:00 2001 From: Jonathan Carlson Date: Tue, 16 Feb 2021 14:20:38 -0800 Subject: [PATCH 3/6] puts a share collab session under share this sketch --- .../TextEditor/components/ShareSketchModal.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/components/TextEditor/components/ShareSketchModal.js b/src/components/TextEditor/components/ShareSketchModal.js index 9ef1f06d..236fcd77 100644 --- a/src/components/TextEditor/components/ShareSketchModal.js +++ b/src/components/TextEditor/components/ShareSketchModal.js @@ -53,6 +53,16 @@ class ShareSketchModal extends React.Component {
+

Share This Collab Session

+ + + + + + +

{this.state.copyStatus}

); From 923ea1307ad42de372ef4488e6a4db82ba7c3da1 Mon Sep 17 00:00:00 2001 From: Jonathan Carlson Date: Fri, 9 Apr 2021 15:44:37 -0700 Subject: [PATCH 4/6] makes collabId visible to user in Share modal, currently not a url but an id that can be joined using /collab/create?id endpoint --- .gitignore | 1 + .../TextEditor/components/ShareSketchModal.js | 12 ++++++---- .../TextEditor/components/TextEditor.js | 13 ++++++++-- src/lib/fetch.js | 13 ++++++++++ src/lib/sketch.js | 24 +++++++++++++++++++ 5 files changed, 56 insertions(+), 7 deletions(-) diff --git a/.gitignore b/.gitignore index a75d3016..99f5695c 100644 --- a/.gitignore +++ b/.gitignore @@ -15,6 +15,7 @@ .env.development.local .env.test.local .env.production.local +.eslintcache npm-debug.log* yarn-debug.log* diff --git a/src/components/TextEditor/components/ShareSketchModal.js b/src/components/TextEditor/components/ShareSketchModal.js index 236fcd77..4cc9587d 100644 --- a/src/components/TextEditor/components/ShareSketchModal.js +++ b/src/components/TextEditor/components/ShareSketchModal.js @@ -7,6 +7,7 @@ import { faCopy } from "@fortawesome/free-solid-svg-icons"; import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; import "styles/Modals.scss"; +import { text } from "@fortawesome/fontawesome-svg-core"; /** * ShareSketchModal is a full-screen modal that displays @@ -21,8 +22,9 @@ class ShareSketchModal extends React.Component { copyStatus: 'Hit "Copy to Clipboard"!', }; - initiateCopy = () => { - navigator.clipboard.writeText(this.props.shareUrl).then( + initiateCopy = (textToBeCopied) => { + console.log("textToBeCopied is: ", textToBeCopied); + navigator.clipboard.writeText(textToBeCopied).then( () => { // success this.setState({ copyStatus: "Successfully copied!" }); @@ -47,7 +49,7 @@ class ShareSketchModal extends React.Component { - @@ -55,9 +57,9 @@ class ShareSketchModal extends React.Component {

Share This Collab Session

- + - diff --git a/src/components/TextEditor/components/TextEditor.js b/src/components/TextEditor/components/TextEditor.js index 8e58c478..c2e93f54 100644 --- a/src/components/TextEditor/components/TextEditor.js +++ b/src/components/TextEditor/components/TextEditor.js @@ -43,15 +43,23 @@ class TextEditor extends React.Component { forked: false, redirectToSketch: false, showShareModal: false, + collabId: null, }; } //==============React Lifecycle Functions===================// - componentDidMount() { + componentDidMount = async () => { window.addEventListener("beforeunload", this.onLeave); window.addEventListener("close", this.onLeave); - } + try { + let collabId = await sketch.constructCollabId(this.props.uid); + this.setState({ collabId: collabId }); + console.log("in mount collabId is: ", collabId); + } catch (err) { + console.log(err); + } + }; componentWillUnmount = () => { window.removeEventListener("beforeunload", this.onLeave); @@ -296,6 +304,7 @@ class TextEditor extends React.Component { {this.renderForkModal()} diff --git a/src/lib/fetch.js b/src/lib/fetch.js index 07409fe8..57b7e3d6 100644 --- a/src/lib/fetch.js +++ b/src/lib/fetch.js @@ -145,3 +145,16 @@ export const createCollab = async (data) => { const endpoint = `collab/create`; return makeServerRequest({ uid }, endpoint); }; + +/** + * join the CollabSession with the passed-in id + * @param {string} id //id of CollabSession + */ + +export const joinCollab = async (id) => { + const endpoint = `collab/create?id=${id}`; + let result = await makeServerRequest({}, endpoint, "get"); + let ok = result.ok; + let session = await result.json(); + return { ok, session }; +}; diff --git a/src/lib/sketch.js b/src/lib/sketch.js index 860779bc..621d0eda 100644 --- a/src/lib/sketch.js +++ b/src/lib/sketch.js @@ -1,4 +1,5 @@ import constants from "../constants"; +import * as fetch from "../lib/fetch.js"; /** * constructShareableSketchURL: given a program ID, generate @@ -18,3 +19,26 @@ export const constructShareableSketchURL = (programId, domainRoot = window.locat return `${root}${constants.ROUTER_BASE_NAME}p/${programId}`; }; + +/** + * constructCollabId: given a program ID, TODO: generate + * a collabId that students can join + * @param {String} uid the uid of the user who wants to create a collab session + */ + +export const constructCollabId = async (uid) => { + let data = { + uid: uid, + }; + + let collabId = await fetch + .createCollab(data) + .then((res) => res.text()) + .then((result) => { + return result; + }) + .catch((err) => console.error(err)); + + console.log("collabId is: ", collabId); + return collabId; +}; From 0a06b69e95cd449d7c90b0b2522ea107b2c2cb78 Mon Sep 17 00:00:00 2001 From: Jonathan Carlson Date: Thu, 15 Apr 2021 19:24:18 -0700 Subject: [PATCH 5/6] removes some console logs and fixes constructCollabID description --- src/components/TextEditor/components/TextEditor.js | 1 - src/lib/sketch.js | 7 +++---- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/src/components/TextEditor/components/TextEditor.js b/src/components/TextEditor/components/TextEditor.js index c2e93f54..09d2a019 100644 --- a/src/components/TextEditor/components/TextEditor.js +++ b/src/components/TextEditor/components/TextEditor.js @@ -55,7 +55,6 @@ class TextEditor extends React.Component { try { let collabId = await sketch.constructCollabId(this.props.uid); this.setState({ collabId: collabId }); - console.log("in mount collabId is: ", collabId); } catch (err) { console.log(err); } diff --git a/src/lib/sketch.js b/src/lib/sketch.js index 621d0eda..4b623085 100644 --- a/src/lib/sketch.js +++ b/src/lib/sketch.js @@ -21,8 +21,8 @@ export const constructShareableSketchURL = (programId, domainRoot = window.locat }; /** - * constructCollabId: given a program ID, TODO: generate - * a collabId that students can join + * constructCollabId: given a program ID, + * generate a collabId that students can join * @param {String} uid the uid of the user who wants to create a collab session */ @@ -37,8 +37,7 @@ export const constructCollabId = async (uid) => { .then((result) => { return result; }) - .catch((err) => console.error(err)); + .catch((err) => console.log(err)); - console.log("collabId is: ", collabId); return collabId; }; From ba77126647422e5bdbffc1e585e699091f58fddd Mon Sep 17 00:00:00 2001 From: Jonathan Carlson Date: Sat, 24 Apr 2021 01:26:51 -0700 Subject: [PATCH 6/6] puts create collab button under share and removes joinCollab from src/lib/fetch --- .../TextEditor/components/ShareSketchModal.js | 12 ++++++++---- .../TextEditor/components/TextEditor.js | 18 +++++++++++------- src/lib/fetch.js | 13 ------------- 3 files changed, 19 insertions(+), 24 deletions(-) diff --git a/src/components/TextEditor/components/ShareSketchModal.js b/src/components/TextEditor/components/ShareSketchModal.js index 4cc9587d..b5bc19a4 100644 --- a/src/components/TextEditor/components/ShareSketchModal.js +++ b/src/components/TextEditor/components/ShareSketchModal.js @@ -3,7 +3,7 @@ import ReactModal from "react-modal"; import { Button, Input, InputGroup, InputGroupAddon } from "reactstrap"; -import { faCopy } from "@fortawesome/free-solid-svg-icons"; +import { faCopy, faUser, faUserFriends } from "@fortawesome/free-solid-svg-icons"; import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; import "styles/Modals.scss"; @@ -23,7 +23,6 @@ class ShareSketchModal extends React.Component { }; initiateCopy = (textToBeCopied) => { - console.log("textToBeCopied is: ", textToBeCopied); navigator.clipboard.writeText(textToBeCopied).then( () => { // success @@ -55,9 +54,14 @@ class ShareSketchModal extends React.Component {
-

Share This Collab Session

+

Collab Session

+
+ +
- +