Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ import { ToastContainer } from 'react-toastify'
import 'react-toastify/dist/ReactToastify.css'
import { withAuth0 } from '@auth0/auth0-react';

import Comments from './pages/Comments'
import Dashboard from './pages/Dashboard'
import NewHeader from './components/NewHeader'
import NewGoalForm from './components/Goals/NewGoalForm'
import Dashboard from './pages/Dashboard'
import Welcome from './components/Welcome'
import ImageGenerator from './components/ImageGenerator'
// import Snake from './pages/Snake'
Expand All @@ -21,6 +22,7 @@ function App({ auth0 }) {
<div className='container'>
<Routes>
<Route path='/' element={<Dashboard auth0={auth0} />} />
<Route path='/comments' element={<Comments auth0={auth0} />} />
{auth0.isAuthenticated && (
<>
<Route path='/goalForm' element={<NewGoalForm auth0={auth0} />} />
Expand Down
6 changes: 2 additions & 4 deletions src/components/Goals/GoalItem.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,16 @@ import { deleteGoal } from '../features/goals/goalSlice'
function GoalItem({ goal }) {
const dispatch = useDispatch()

console.log(goal)

return (
<div className='goal'>
<div>{new Date(goal.createdAt).toLocaleString('en-US')}</div>
<h2>{goal.description}</h2>
<button onClick={() => dispatch(deleteGoal(goal._id))} className='close'>
X
</button>

{goal.isCompleted ? <p> COMPLETED </p> : <p>Not Completed</p>}

</div>
)
}
Expand Down
6 changes: 2 additions & 4 deletions src/components/Goals/Goals.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ function Goals({
};

const handleMarkComplete = async (e, goalId, description, status, isCompleted = false) => {
console.log(e.target)

try {
let data = {
Expand All @@ -64,8 +63,7 @@ function Goals({
status: status,
isCompleted: isCompleted
}
const res = updateData(`/api/goals/${goalId}`, data)
console.log(res)
const res = await updateData(`/api/goals/${goalId}`, data)
e.target.classList.replace('btn-warning', 'btn-success')
} catch (error) {
console.error('Error updating data in DB. Received:', error)
Expand All @@ -85,7 +83,7 @@ function Goals({

<section className='heading'>
{/* DISPLAY GOALS */}
<Row xs={1} md={1} lg={2} xl={3} className='g-4 shadow-md'>
<Row xs={3} md={3} lg={3} xl={3} className='g-4 shadow-md'>
{goalData && goalData.map((goal, idx) => (
<>
<Col key={goal._id} >
Expand Down
2 changes: 0 additions & 2 deletions src/components/Goals/NewGoalForm.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ function NewGoalForm({ auth0, handleGetData }) {
return
}
const token = claim.__raw
console.log(tasks)
await createData(token, POST_GOALS, {
"description": text,
"status": status,
Expand Down Expand Up @@ -63,7 +62,6 @@ function NewGoalForm({ auth0, handleGetData }) {
if (taskInput !== '') {
setTasks([...tasks, taskInput.trim()])
}
console.log(tasks)
setTaskInput('')
e.placeholder = 'Task Added. Press Add Goal to save'
}
Expand Down
3 changes: 2 additions & 1 deletion src/components/SideBar.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React from 'react'
import { Link } from 'react-router-dom';
import ImageGenerator from './ImageGenerator'

function SideBar({ auth0, handleShowGoalModal }) {
Expand All @@ -18,7 +19,7 @@ function SideBar({ auth0, handleShowGoalModal }) {
</a>
</li>
<li>
<a href='#'>Add Comment</a>
<Link to='/comments'>Add Comment</Link>
</li>
<li>
<a href='#'>Play Snake</a>
Expand Down
Empty file removed src/pages/AI.jsx
Empty file.
18 changes: 0 additions & 18 deletions src/pages/About.jsx

This file was deleted.

101 changes: 101 additions & 0 deletions src/pages/Comments.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
import React, { useState, useEffect } from 'react';
import createData from '../utils/createData';
import fetchData from '../utils/fetchData';
import { withAuth0 } from '@auth0/auth0-react';
// import deleteData from '../utils/deleteData'

const API_URL = `${import.meta.env.VITE_SERVER_URL}`;

// Comments.jsx
const Comments = ({ auth0 }) => {
const [comments, setComments] = useState([]);
const [newComment, setNewComment] = useState('');
// Fetch comments initially and when dependencies change

const postComment = async (path, body, userId) => {
const claim = await auth0.getIdTokenClaims()
if (!claim) {
console.log('Token claim is undefined.')
return
}
try {
const token = claim.__raw
const response = await createData(token, path, body, userId)
if (response.status === 200) {
return response.data
}
} catch (error) {
console.log(error)
}
}


useEffect(() => {
const getComments = async () => {
const claim = await auth0.getIdTokenClaims()
if (!claim) {
console.log('Token claim is undefined.')
return
}
try {
const token = claim.__raw
const response = await fetchData(token, `/api/comments`)
return response
} catch (error) {
console.log(error)
}
}

const loadComments = async () => {
const fetchedComments = await getComments();
setComments(fetchedComments);
};
if (auth0.isAuthenticated) {
loadComments();
}
}, []);


// Handle new comment submission
const handleSubmit = async (e) => {
e.preventDefault();
if (!newComment.trim()) return;
const postedComment = await postComment(
`/api/comments`,
{ text: newComment }
)

if (postedComment) {
setComments([...comments, postedComment])
setNewComment('')
}
}
return (
<div>
<h3>Comments</h3>
{auth0.isAuthenticated ? (
<form onSubmit={handleSubmit}>
<textarea
name='text'
value={newComment}
onChange={(e) => setNewComment(e.target.value)}
placeholder="Write a comment..."
></textarea>
<button type="submit">Post Comment</button>
</form>
) : (
<p>Please log in to post comments.</p>
)}
<div>
{comments && comments.map((comment) => (
<div key={comment._id}>
<p>{comment.createdAt}</p>
<p>{comment.user.nickname}</p>
<p>{comment.text}</p>
</div>
))}
</div>
</div>
);
};
export default Comments;
4 changes: 2 additions & 2 deletions src/utils/createData.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ const createData = async (token, path, body) => {
};

try {
const response = await axios.post(`${API_URL}${path}`, body, config);
return response.data;
const response = await axios.post(`${API_URL}${path}`, body, config)
return response
} catch (error) {
console.error('Error fetching data:', error);
throw error;
Expand Down
4 changes: 0 additions & 4 deletions src/utils/updateData.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,6 @@ const handleUpdateData = async (path, goalId, auth0, body) => {
}
const token = claim.__raw
const response = await updateData(token, `${path}/${goalId}`, body)

if (response.status === 200) {
console.log(response.data)
}
} catch (error) {
console.error('Error fetching data from DB. Received:', error)
}
Expand Down