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 9ef1f06d..b5bc19a4 100644 --- a/src/components/TextEditor/components/ShareSketchModal.js +++ b/src/components/TextEditor/components/ShareSketchModal.js @@ -3,10 +3,11 @@ 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"; +import { text } from "@fortawesome/fontawesome-svg-core"; /** * ShareSketchModal is a full-screen modal that displays @@ -21,8 +22,8 @@ class ShareSketchModal extends React.Component { copyStatus: 'Hit "Copy to Clipboard"!', }; - initiateCopy = () => { - navigator.clipboard.writeText(this.props.shareUrl).then( + initiateCopy = (textToBeCopied) => { + navigator.clipboard.writeText(textToBeCopied).then( () => { // success this.setState({ copyStatus: "Successfully copied!" }); @@ -47,7 +48,22 @@ class ShareSketchModal extends React.Component { - + + +
+

Collab Session

+
+ +
+ + + + diff --git a/src/components/TextEditor/components/TextEditor.js b/src/components/TextEditor/components/TextEditor.js index 8e58c478..16d44015 100644 --- a/src/components/TextEditor/components/TextEditor.js +++ b/src/components/TextEditor/components/TextEditor.js @@ -43,15 +43,16 @@ class TextEditor extends React.Component { forked: false, redirectToSketch: false, showShareModal: false, + collabId: null, }; } //==============React Lifecycle Functions===================// - componentDidMount() { + componentDidMount = () => { window.addEventListener("beforeunload", this.onLeave); window.addEventListener("close", this.onLeave); - } + }; componentWillUnmount = () => { window.removeEventListener("beforeunload", this.onLeave); @@ -115,6 +116,15 @@ class TextEditor extends React.Component { this.setState({ currentLine: line }); }; + createCollabSession = async () => { + try { + let collabId = await sketch.constructCollabId(this.props.uid); + this.setState({ collabId: collabId }); + } catch (err) { + console.log(err); + } + }; + renderForkModal = () => { return (
{ 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"); }; /** @@ -131,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); +}; diff --git a/src/lib/sketch.js b/src/lib/sketch.js index 860779bc..4b623085 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,25 @@ export const constructShareableSketchURL = (programId, domainRoot = window.locat return `${root}${constants.ROUTER_BASE_NAME}p/${programId}`; }; + +/** + * 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 + */ + +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.log(err)); + + return collabId; +};