Skip to content

Commit

Permalink
updating for speed
Browse files Browse the repository at this point in the history
  • Loading branch information
elhagen13 committed Dec 8, 2023
1 parent 3745521 commit 0c9cdc6
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
}

.title {
color: white;
text-decoration-color: white;
font-family: "Courier New", Courier, monospace;
font-weight: bolder;
Expand Down
38 changes: 38 additions & 0 deletions packages/studywell-frontend/src/pages/CreateAccount.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ function CreateAccount() {
const email = document.getElementById("email");
const username = document.getElementById("username");
const password = document.getElementById("password");
var existence = [0, 0];
setUsernameExistence(false);
setEmailExistence(false);

Expand All @@ -22,6 +23,42 @@ function CreateAccount() {
password: password.value,
};

try {
const usernameRes = await fetchUserByUsername(username.value);
console.log("username", usernameRes.status);
if (usernameRes.status === 200) {
setUsernameExistence(true);
existence[0] = 1;
console.log("username exists?", usernameExistence);
}

const emailRes = await fetchUserByEmail(email.value);
console.log("email", emailRes.status);
if (emailRes.status === 200) {
existence[1] = 1;
setEmailExistence(true);
console.log("email exists?", emailExistence);
}

console.log(emailExistence, usernameExistence);

if (!existence[0] && !existence[1]) {
const res = await createUser(user);
if (res.status === 201) {
const result = res.json();
const userId = result.id;
navigate(`/work/${userId}`);
console.log("navigated");
} else {
console.log("Account creation failed.");
}
} else {
console.log("failed");
}
} catch (error) {
console.error("Error:", error);
}
/*
fetchUserByUsername(username.value)
.then((res) => {
console.log("username", res.status);
Expand Down Expand Up @@ -64,6 +101,7 @@ function CreateAccount() {
});
} else console.log("failed");
});
*/
}

function fetchUserByEmail(email) {
Expand Down
1 change: 1 addition & 0 deletions packages/studywell-frontend/src/pages/LogIn.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ function LogIn() {
.then((data) => {
if (data !== null && data.user.password === password.value) {
const userId = data.user.id;
console.log("true");
navigate(`/work/${userId}`);
} else {
setPassword(true);
Expand Down
7 changes: 5 additions & 2 deletions packages/studywell-frontend/src/pages/WorkScreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,23 @@ import TotalTask from "../components/taskbar/TotalTask";
import Navbar from "../components/navbar/NavBar";
import { Route, Routes } from "react-router-dom";
import React, { useState, useEffect, useCallback } from "react";
import { useParams } from "react-router-dom";
import TotalToDo from "../components/toDo/TotalToDo";
import Popup from "reactjs-popup";

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

const [workTime, setWorkTime] = useState(25);
const [shortBreak, setShortBreak] = useState(5);
const [longBreak, setLongBreak] = useState(15);

const curURL = window.location.href;
const pathSegments = curURL.split("/");
const userId = pathSegments[pathSegments.length - 1];

const updateTimes = (type, value) => {
if (type === "work") {
setWorkTime(value);
Expand Down

0 comments on commit 0c9cdc6

Please sign in to comment.