Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
SabaHakimi committed Dec 8, 2023
1 parent 1cbcb11 commit 29be8b2
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 6 deletions.
2 changes: 1 addition & 1 deletion packages/studywell-frontend/src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ function App() {
return (
<BrowserRouter>
<Routes>
<Route path="/work/*" element={<WorkScreen />} />
<Route path="/work/:userId" element={<WorkScreen />} />
<Route path="/" element={<LogIn />} />
<Route path="/create" element={<CreateAccount />} />
</Routes>
Expand Down
3 changes: 2 additions & 1 deletion packages/studywell-frontend/src/pages/LogIn.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ function LogIn() {
})
.then((data) => {
if (data !== null && data.user.password === password.value) {
navigate("/work");
const userId = data.user.id;
navigate(`/work/${userId}`);
} else {
setPassword(true);
}
Expand Down
9 changes: 6 additions & 3 deletions packages/studywell-frontend/src/pages/WorkScreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@ import TotalTask from "../components/taskbar/TotalTask";
import Navbar from "../components/navbar/NavBar";
import { Route, Routes } from "react-router-dom";
import React, { useState, useEffect } from "react";
import { useParams } from 'react-router-dom';
import TotalToDo from "../components/toDo/TotalToDo";

function WorkScreen() {
const [dataFromTask, updateToDoList] = useState("");
const [breakCount, setBreakCount] = useState(1);
const [tasks, setTasks] = useState([]);
const {userId} = useParams();

const updateToDo = (task) => {
console.log(task);
Expand Down Expand Up @@ -47,9 +49,9 @@ function WorkScreen() {
});
}

function postUser(task) {
function postUser(task, userId) {
console.log(task);
const promise = fetch("https://studywell.azurewebsites.net/tasks", {
const promise = fetch("https://studywell.azurewebsites.net/tasks/${userId}", {

Check warning on line 54 in packages/studywell-frontend/src/pages/WorkScreen.js

View workflow job for this annotation

GitHub Actions / build

Unexpected template string expression
method: "POST",
headers: {
"Content-Type": "application/json",
Expand All @@ -63,7 +65,7 @@ function WorkScreen() {
// eslint-disable-next-line
function updateList(task) {
console.log("Adding task:", task);
postUser(task)
postUser(task, userId)
.then((res) => {
console.log("Response from server:", res);
return res.status === 200 ? res.json() : undefined;
Expand Down Expand Up @@ -106,6 +108,7 @@ function WorkScreen() {
updateList={updateList}
removeTask={removeTask}
tasks={tasks}
userId={userId}
/>
</div>
<Routes>
Expand Down
3 changes: 2 additions & 1 deletion studywell-backend/backend.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,11 @@ app.get("/tasks", (req, res) => {
});
});

app.post("/tasks", (req, res) => {
app.post("/tasks/:userId", (req, res) => {
const taskToAdd = req.body;
console.log(taskToAdd);
taskToAdd.id = generateID();
taskToAdd.user_id = req.params.userId;
taskModel
.addTasks(taskToAdd)
.then(() => {
Expand Down

0 comments on commit 29be8b2

Please sign in to comment.