Skip to content

Commit

Permalink
fix: edit backend routes
Browse files Browse the repository at this point in the history
  • Loading branch information
huythai855 committed Aug 9, 2023
1 parent 235ff17 commit a172513
Show file tree
Hide file tree
Showing 9 changed files with 445 additions and 15 deletions.
399 changes: 399 additions & 0 deletions frontend/package-lock.json

Large diffs are not rendered by default.

9 changes: 6 additions & 3 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@
"@testing-library/user-event": "^13.5.0",
"axios": "^1.4.0",
"bootstrap": "^5.3.1",

"crypto-browserify": "^3.12.0",
"os-browserify": "^0.3.0",
"path-browserify": "^1.0.1",
"react": "^18.2.0",
"react-bootstrap": "^2.8.0",
"react-dom": "^18.2.0",
"react-router": "^6.14.2",
"react-router-dom": "^6.14.2",

"react-scripts": "^5.0.1",
"react-strap": "^0.0.1",

"reactstrap": "^9.2.0",
"web-vitals": "^2.1.4"
},
Expand All @@ -44,5 +44,8 @@
"last 1 firefox version",
"last 1 safari version"
]
},
"devDependencies": {
"dotenv-webpack": "^8.0.1"
}
}
3 changes: 1 addition & 2 deletions frontend/src/AppRouter.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,10 @@ function AppRouter() {
<Route path="/quiz" element={<Quiz/>} />
<Route path="/physic-page" element={<Coursepath/>} />
<Route path="/course-path" element={<Coursepath/>} />
<Route path="/" element={<Login/>} />
<Route path = "/interactive" element={<Interactive/>} />

{/* 404 page if you guy wanna edit :> */}
{/*<Route path='*' element={<Home/>} /> */}
{/*<Route path='*' element={<Page404/>} /> */}
</Routes>
</div>
</Router>
Expand Down
1 change: 1 addition & 0 deletions frontend/src/pages/Course/CourseDetail.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React, { useEffect, useState } from 'react';
import axios from 'axios';
import { Link } from 'react-router-dom';
import { backendUrl } from '../../index.js';
import './CourseDetail.css'

import Owl1 from "../../assets/group-51.png"
Expand Down
12 changes: 10 additions & 2 deletions frontend/src/pages/Home/Home.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import React, { useEffect, useState } from 'react';
import axios from 'axios';
import { Link } from 'react-router-dom';
import backendUrl from '../../index.js';
// import Calendar from 'react-calendar';
// import 'react-calendar/dist/Calendar.css';
import './Home.css'


import Line2 from "../../assets/line-2.png"
import Icon5 from "../../assets/icon-5.png"
import Bell from "../../assets/bell-1.png"
Expand Down Expand Up @@ -47,6 +49,12 @@ function Home() {
const urlSearchParams = new URLSearchParams(window.location.search);
const userId = urlSearchParams.get('user_id');


// const dotenv = require('dotenv');
// dotenv.config();
const backendUrl = process.env.REACT_APP_BACKEND_URL;
const url = (backendUrl !== undefined) ? backendUrl : 'https://sci-play-server.vercel.app/';

const onChange = date => {
setDate(date);
};
Expand All @@ -55,7 +63,7 @@ function Home() {

// console.log(userId);

axios.get(`http://10.10.143.92:3000/api/course?user_id=${userId}`)
axios.get(url + `api/course?user_id=${userId}`)
.then(response => {
setData(response.data);
// console.log(data);
Expand All @@ -64,7 +72,7 @@ function Home() {
// setLessons(data.lessons);
console.log(student);
console.log(courses);

console.log("Axios.get.then logged");

})
.catch(error => {
Expand Down
8 changes: 6 additions & 2 deletions frontend/src/pages/Learn/Interactive/LessonDetails.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,16 @@ const LessonDetails = () => {
const [currentLineIndex, setCurrentLineIndex] = useState(0);
const [displayedText, setDisplayedText] = useState("");

// const dotenv = require('dotenv');
// dotenv.config();
const backendUrl = process.env.REACT_APP_BACKEND_URL;
const url = (backendUrl !== undefined) ? backendUrl : 'https://sci-play-server.vercel.app/';

useEffect(() => {
async function fetchLessonData() {
try {

const response = await axios.get(`
http://localhost:3000/api/lesson?user_id=${userId}&lesson_id=${lessonId}`
const response = await axios.get(url + `api/lesson?user_id=${userId}&lesson_id=${lessonId}`
);
setLessonData(response.data);
// setName(response.data.student.name);
Expand Down
11 changes: 9 additions & 2 deletions frontend/src/pages/Learn/Learn.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,18 +44,25 @@ function Learn() {
const [lessons, setLessons] = useState([]);
const [recommend, setRecommend] = useState([]);
const urlSearchParams = new URLSearchParams(window.location.search);
const userId = urlSearchParams.get('user_id');
const userId = urlSearchParams.get('user_id');
// console.log(userId);

// const dotenv = require('dotenv');
// dotenv.config();
const backendUrl = process.env.REACT_APP_BACKEND_URL;
const url = (backendUrl !== undefined) ? backendUrl : 'https://sci-play-server.vercel.app/';


const onChange = date => {
setDate(date);
};

useEffect(() => {




axios.get(`http://10.10.143.92:3000/api/course?user_id=${userId}`)
axios.get(url + `api/course?user_id=${userId}`)
.then(response => {
setData(response.data);
// console.log(data);
Expand Down
7 changes: 6 additions & 1 deletion frontend/src/pages/Lesson/Quiz/Quiz.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,15 @@ function Quiz () {
const userId = urlSearchParams.get('user_id');
const [lessonData, setLessonData] = useState({});

// const dotenv = require('dotenv');
// dotenv.config();
const backendUrl = process.env.REACT_APP_BACKEND_URL;
const url = (backendUrl !== undefined) ? backendUrl : 'https://sci-play-server.vercel.app/';

useEffect(() => {
async function fetchData() {
try {
const res = await axios.get(`http://localhost:3000/api/lesson?lesson_id=${lessonId}&user_id=${userId}`);
const res = await axios.get(url + `api/lesson?lesson_id=${lessonId}&user_id=${userId}`);
// console.log("LessonId: ", lessonId);
// console.log("UserId: ", userId);

Expand Down
10 changes: 7 additions & 3 deletions frontend/src/pages/Login/Login.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,21 @@ function Login({ history }) {
if(data !== {"status": "unreceived"}) {

if(data.error === true) {
window.location.href = "http://localhost:3001/login?error=true";
window.location.href = "https://sciplay.vercel.app/login?error=true";
}
else {
if(data.error === false) {
window.location.href = `http://localhost:3001/homepage?user_id=${data.student_id}`;
window.location.href = `https://sciplay.vercel.app/homepage?user_id=${data.student_id}`;
}
}

}
}, [data]);

// const dotenv = require('dotenv');
// dotenv.config();
const backendUrl = process.env.REACT_APP_BACKEND_URL;
const url = (backendUrl !== undefined) ? backendUrl : 'https://sci-play-server.vercel.app/';


const handleEmailChange = (event) => {
Expand All @@ -62,7 +66,7 @@ function Login({ history }) {

await event.preventDefault();

axios.get(`http://localhost:3000/api/login?email=${email}&password=${password}`)
axios.get(url + `api/login?email=${email}&password=${password}`)
.then((response) => {
setData(response.data);

Expand Down

0 comments on commit a172513

Please sign in to comment.