Skip to content

Commit

Permalink
Merge pull request #501 from Jlu18/doc
Browse files Browse the repository at this point in the history
Added documentation for missing functions and some clean up
  • Loading branch information
kdvalin authored Feb 3, 2022
2 parents f87b4e0 + 5d9a029 commit ef10929
Show file tree
Hide file tree
Showing 69 changed files with 1,628 additions and 991 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ on: [push, pull_request]
jobs:
ci-checks:
runs-on: ubuntu-latest
env:
NODE_OPTIONS: '--max_old_space_size=4096'
container:
image: node:12.18

Expand Down
11 changes: 9 additions & 2 deletions src/actions/authActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import * as types from "../constants/ActionTypes";
*
* @param {obj} user User data from the firebase auth obj
*
* @returns reducer action obj with type: LOGIN and user obj
* @returns {object} reducer action obj with type: LOGIN and user obj
*/
export function login(user) {
return { type: types.LOGIN, user };
Expand All @@ -14,12 +14,19 @@ export function login(user) {
/**
* Sends a signal to the reducer to logout the current user
*
* @returns reducer action obj with type: LOGOUT
* @returns {object} reducer action obj with type: LOGOUT
*/
export function logout() {
return { type: types.LOGOUT };
}

/**
* Sends a signal to the reducer to refresh the token
*
* @param {object} token
*
* @returns {object} reducer action object with type: REFRESH_TOKEN and token obj
*/
export function refreshToken(token) {
return { type: types.REFRESH_TOKEN, token };
}
Expand Down
52 changes: 44 additions & 8 deletions src/actions/collectionActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,19 @@ import * as types from "../constants/ActionTypes";

export const collectRef = "/apiv1/collections";

export function asyncCollections(id) {

/**
* Fetch the list of the user collection asynchronously
* Use when user login or added a new collection
*
* @param {*} uid A JWT token to authenticate with the backend
*/
export function asyncCollections(uid) {
// fetch user's collections
return (dispatch) => {
if (id) {
if (uid) {
let userCollections = [];
fetch(collectRef, {headers: {"x-access-token": id}}).then((data) => {
fetch(collectRef, {headers: {"x-access-token": uid}}).then((data) => {
data.json().then((data) => {
data.forEach((doc) => {
userCollections.push(doc);
Expand All @@ -19,10 +26,23 @@ export function asyncCollections(id) {
};
}

/**
* Sends a signal to the reducer to sync the user collections
*
* @param {object} payload List of user collections
*
* @returns {object} reducer action obj with type SYNC_COLLECTIONS with payload
*/
export function syncCollections(payload) {
return { type: types.SYNC_CLASSES, payload: payload };
return { type: types.SYNC_COLLECTIONS, payload: payload };
}

/**
* Fetch the specific collection specify by user
*
* @param {string} collectionID Collection id
* @param {*} uid A JWT token to authenticate with the backend
*/
export function asyncCollection(collectionID, uid) {
// fetch projects in collection
return (dispatch) => {
Expand Down Expand Up @@ -62,13 +82,27 @@ export function asyncCollection(collectionID, uid) {
};
}

/**
* Sends a signal to the reducer to load the retrieved collection
*
* @param {object} payload Data of retrieved collection
*
* @returns {object} reducer action obj with type: SYNC_COLLECTION and payload
*/
export function syncCollection(payload) {
return { type: types.SYNC_CLASS, payload: payload };
return { type: types.SYNC_COLLECTION, payload: payload };
}

export function deleteCollection(id, name = null, uid) {
/**
* Sends a signal to the reducer to delete the specific collection of user
*
* @param {string} collectionID Collection ID
* @param {string} name Name of the collection if exists
* @param {*} uid A JWT token to authenticate with the backend
*/
export function deleteCollection(collectionID, name = null, uid) {
return (dispatch) => {
name = (name ? name : id);
name = (name ? name : collectionID);
if (window.confirm(`Are you sure you want to delete collection "${name}"?`)) {

// Delete Document
Expand All @@ -77,12 +111,14 @@ export function deleteCollection(id, name = null, uid) {
console.error(`Error deleting collection ${name}: ${resp.statusText}`);
return;
}
dispatch({ type: types.DELETE_CLASS, id: id });
dispatch({ type: types.DELETE_COLLECTION, id: collectionID });
});
}
};
}

/**
* Creates a new collection
*
* @param {string} name The name of the collection to be created
* @param {*} uid A JWT token to authenticate with the backend
Expand Down
78 changes: 54 additions & 24 deletions src/actions/courseActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import * as sceneActions from "./sceneActions";

const courseRef = "/apiv1/courses/";
const header = { headers: { "content-type": "application/json" } };
let noLessons = {
const noLessons = {
name: "",
id: -1,
prompt: "There are no lessons in this course",
Expand All @@ -19,9 +19,12 @@ const problem = {
code: ""
};

/**
/*
* Course Actions
*/
/**
* Fetch all the courses available
*/
export function fetchCourses() {
return (dispatch) => {
fetch(courseRef, header)
Expand All @@ -42,10 +45,22 @@ export function fetchCourses() {
};
}

/**
* Sends a signal to the reducer to synchronize the courses
*
* @param {*} payload List of courses retrieved
*
* @returns reducer action object with type: SYNC_COURSE and payload
*/
export function syncCourses(payload) {
return { type: types.SYNC_COURSES, payload: payload };
}

/**
* Fetch specific course
*
* @param {string} courseId id of the course getting
*/
export function fetchCourse(courseId) {
return (dispatch) => {
fetch(courseRef + courseId, header)
Expand Down Expand Up @@ -84,16 +99,23 @@ export function fetchCourse(courseId) {
};
}

/**
* Sends signal to the reducer to load the course retrieved
*
* @param {*} course Data of course retrieved
* @returns {object} reducer action obj with type: LOAD_COURSE and payload
*/
export function loadCourse(course) {
return {
type: types.LOAD_COURSE,
payload: course
};
return { type: types.LOAD_COURSE, payload: course };
}

/**
/*
* Lesson Actions
*/
/**
* Fetch the lesson that is supplied by the parameter.
* @param {*} json Lesson data
*/
export function fetchLesson(json) {
return (dispatch) => {
dispatch(loadLesson(json));
Expand All @@ -106,10 +128,21 @@ export function fetchLesson(json) {
}

/**
* Frontend disables option if out of bounds
* Sends signal to the reducer to load a new lesson supplied by parameter
*
* @param {object} lesson Lesson data
* @returns reducer action obj with type: LOAD_LESSON and payload: lesson
*/
export function loadLesson(lesson) {
return { type: types.LOAD_LESSON, payload: lesson };
}

/**
* Increment the lesson index and load the next lesson.
* Frontend disables option if out of bounds
*
* @param {*} currentIndex !!!DESCRIPTION NEEDED!!!
* @param {*} next !!!DESCRIPTION NEEDED!!!
* @param {number} currentIndex current index of the course
* @param {object} next Object of lesson to be load next
*/
export function nextLesson(currentIndex, next) {
return (dispatch) => {
Expand All @@ -119,10 +152,11 @@ export function nextLesson(currentIndex, next) {
}

/**
* Frontend disables option if out of bounds
* Decrement the lesson index and load the previous lesson.
* Frontend disables option if out of bounds
*
* @param {*} currentIndex !!!DESCRIPTION NEEDED!!!
* @param {*} prev !!!DESCRIPTION NEEDED!!!
* @param {number} currentIndex current index of the course
* @param {object} prev Object of lesson to be load previous
*/
export function previousLesson(currentIndex, prev) {
return (dispatch) => {
Expand All @@ -131,18 +165,14 @@ export function previousLesson(currentIndex, prev) {
};
}

/**
* Sends signal to the reducer to update the current index of the Course
*
* @param {number} newIndex New index to be set
* @returns {object} reducer action obj with type: SET_INDEX and payload: newIndex
*/
export function setCurrentIndex(newIndex) {
return {
type: types.SET_INDEX,
payload: newIndex
};
}

export function loadLesson(lesson) {
return {
type: types.LOAD_LESSON,
payload: lesson
};
return { type: types.SET_INDEX, payload: newIndex };
}

export default {
Expand Down
15 changes: 7 additions & 8 deletions src/actions/editorActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ const sceneRef = "/apiv1/scenes";
* Sends a signal to the reducer to render the scene
*
* @param {string} text Text from the Ace Editor component
*
* @param {*} uid A JWT token to authenticate with the backend
*
* @returns reducer action obj with action type and text
*/
export function render(text, uid) {
Expand All @@ -19,6 +20,7 @@ export function render(text, uid) {
* Sends a signal to the reducer to refresh with the given text
*
* @param {string} text Text from the Ace Editor component
* @param {*} uid A JWT token to authenticate with the backend
*
* @returns reducer action obj with action type and text
*/
Expand All @@ -36,8 +38,11 @@ export function recover() {
}

/**
* This does an async fetch to Firebase to grab the scene, then
* This does an async fetch to backend to grab the scene, then
* dispatches the necessary functions to update the state.
*
* @param {string} id scene id
* @param {*} uid A JWT token to authenticate with the backend
*/
export function fetchScene(id, uid = "anon") {
return (dispatch) => { // Return a func that dispatches events after async
Expand Down Expand Up @@ -89,20 +94,14 @@ export function fetchScene(id, uid = "anon") {
*
* @returns reducer action obj with action type
*/

export function updateSavedText(savedText){
return {type: types.EDITOR_UPDATE_SAVEDTEXT, savedText};
}

export function addPassword(payload) {
return { type: types.ADD_PW, payload };
}

export default {
render,
refresh,
recover,
fetchScene,
addPassword,
updateSavedText,
};
36 changes: 33 additions & 3 deletions src/actions/projectActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,16 @@ import * as types from "../constants/ActionTypes";
const sceneRef = "/apiv1/scenes";
const previewRef = "/apiv1/preview/id";

export function asyncUserProj(id) {
/**
* Retrieved the list of user scenes
*
* @param {*} uid A JWT token to authenticate with the backend
*/
export function asyncUserProj(uid) {
// fetch user's project
return (dispatch) => {
if (id) {
fetch(`${sceneRef}/`, {headers: {"x-access-token": id}}).then((response) =>{
if (uid) {
fetch(`${sceneRef}/`, {headers: {"x-access-token": uid}}).then((response) =>{
if(response.status === 200){
response.json().then((json) =>{
json.forEach(element => {
Expand All @@ -21,10 +26,21 @@ export function asyncUserProj(id) {
};
}


/**
* Sends signal to the reducer to sync the user project
*
* @param {*} payload list of user projects
*
* @returns reducer action obj with type: SYNC_USER_PROJ wiht payload
*/
export function syncUserProj(payload) {
return { type: types.SYNC_USER_PROJ, payload: payload };
}

/**
* Fetch a eample scenes from the backend
*/
export const asyncExampleProj = () => {
// fetch example projects
return (dispatch) => {
Expand All @@ -41,10 +57,24 @@ export const asyncExampleProj = () => {
};
};


/**
* Sends signal to the reducer to sync the example project
* @param {*} payload List of the example project
*
* @returns reducer action obj with type: SYNC_EXAMP_PROJ with payload
*/
export function syncExampleProj(payload) {
return { type: types.SYNC_EXAMP_PROJ, payload: payload };
}

/**
* Delete the specify user project
*
* @param {*} uid A JWT token to authenticate with the backend
* @param {string} id Scene id to be deleted
* @param {string} name Name of the scene
*/
export function deleteProj(uid, id, name) {
return (dispatch) => {
if (window.confirm(`Are you sure you want to delete ${name}?`)) {
Expand Down
Loading

0 comments on commit ef10929

Please sign in to comment.