-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Helpcenter Boilerplate Form #21
base: main
Are you sure you want to change the base?
Changes from all commits
c5b22c2
7744a8a
4e8b9a8
fde619e
cb7ba5b
1239a68
6ee8704
5c07bc2
67b9540
f4d0307
50731df
9ba237a
b7c97eb
dd7e5d4
d4df2ea
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
CREATE TABLE comments_table (comment_id integer PRIMARY KEY AUTOINCREMENT, first_name text NOT NULL, last_name text NOT NULL, email text NOT NULL, created_date timestamp default (DATETIME('now')), subject text NOT NULL, comment text NOT NULL) ; | ||
|
||
insert into comments_table (first_name, last_name, email, subject, comment) VALUES ('John', 'Doe', '[email protected]', 'NY', 'hello'); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
import React, { useEffect, useState } from 'react'; | ||
import Header from './Header.jsx'; | ||
import { Link } from 'react-router-dom'; | ||
import axios from 'axios'; | ||
|
||
|
||
const PostButton = ({buttonText}) => { | ||
return ( | ||
<button className='NewComment'>{buttonText}</button> | ||
); | ||
} | ||
|
||
const Comment = ({name,email,date,subject,commentText}) => { | ||
return ( | ||
<div className="comments"> | ||
<div className='labelContainer'> | ||
<div className="name">{name}</div> | ||
<div className="email">{email}</div> | ||
<div className="date">{date}</div> | ||
</div> | ||
<div className="subjectContainer"> | ||
<div className="subject">{subject}</div> | ||
<div className="commentText">{commentText}</div> | ||
</div> | ||
</div> | ||
); | ||
} | ||
|
||
const Forum = () => { | ||
const [comments,setComments] = useState([]) | ||
|
||
|
||
|
||
useEffect(()=>{ | ||
const getComments = () => { | ||
const SERVER_URL = "" | ||
axios | ||
.get(SERVER_URL + 'getComments') | ||
.then((res) => { | ||
setComments(res.data) | ||
console.log(res.data); | ||
}) | ||
} | ||
getComments(); | ||
},[]) | ||
|
||
// const deletePost = async (e) => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. looks like you can maybe delete all this commented out code? |
||
// const SERVER_URL = "" | ||
// e.preventDefault(); | ||
// try { | ||
// await axios.delete(SERVER_URL+ '/comments/<comment_id>'); | ||
// writeStatus("Post succesfully deleted"); | ||
// setTimeout(() => writeStatus(""), 3000); | ||
// } catch (err) { | ||
// writeStatus("Post deletion failed"); | ||
// } | ||
// }; | ||
|
||
// deleteRow = (id, e) => { | ||
// const SERVER_URL = "" | ||
// axios | ||
// .delete(SERVER_URL + '/comments/<comment_id>') | ||
// .then(res => { | ||
// console.log(res); | ||
// console.log(res.data); | ||
|
||
// const posts = this.state.posts.filter(item => item.id !== id); | ||
// this.setState({ posts }); | ||
// }) | ||
// } | ||
|
||
// const handleRemove = () => { | ||
// const SERVER_URL = "" | ||
// axios | ||
// .delete(SERVER_URL + '/comments/<comment_id>', {data: {id}}) | ||
// .then((res) => { | ||
// console.log(res.data); | ||
// }) | ||
// } | ||
|
||
return ( | ||
<> | ||
<Header /> | ||
<div className='webContainer'> | ||
<div className= "Forum"> | ||
<h1 className="ForumHeader">Help Center Forum | ||
<Link to ="/Submit"><PostButton buttonText="Post New Comment"></PostButton></Link> | ||
</h1> | ||
{comments.map( (commentArray) => { | ||
return <Comment name = {commentArray[1]+commentArray[2]} email = {commentArray[3]} date ={commentArray[4]} subject = {commentArray[5]} commentText = {commentArray[6]}> | ||
{/* <button onClick={deletePost}></button> */} | ||
{/* <button onClick={(e) => this.deleteRow(Comment.id, e)}>Delete</button> */} | ||
{/* <button onClick={deleteRow} params={}></button> */} | ||
</Comment> | ||
})} | ||
</div> | ||
</div> | ||
</> | ||
); | ||
} | ||
|
||
export default Forum; | ||
|
||
//we will run this function everytime componenet re-renders, inside depency changes we will rerun | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This looks like it was probably just notes for development (rather than in-line documentation) so you can probably delete all of this through the commented out code at the bottom as well? |
||
|
||
//network request, cannot be sequential, asychronus something need to be | ||
//processed in a que, seperate | ||
//eventloop (javascript), everything asynchrnus is on the loop and runs on the side of the code | ||
//keep checking until data run callback function after succeful execution of network request | ||
//idea of network request side effect | ||
//usestate, program rerender, doesnt need to reload, it knows when probs and state and useeffect and will | ||
//runs when component refreshes | ||
//async allows to write pretty stright forward | ||
//axios .then (promise, res data you will get back), promise syntax | ||
|
||
//create some state | ||
//save data into response | ||
//save data, map data into components, return name is equal to variable, map function | ||
|
||
|
||
{/* <Link to ="/APIInfo"><button className='FAQButtonActual'>?</button></Link> */} | ||
{/* <Link to ="/"><button className='ReturnButtonActual'>Return Home</button></Link> */} | ||
{/* {comments.map( (commentArray) => { | ||
return <Comment name = {commentArray[1]+commentArray[2]} email = {commentArray[3]} date ={commentArray[4]} subject = {commentArray[5]} commentText = {commentArray[6]}></Comment> | ||
})} */} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import React from 'react'; | ||
import Header from './Header.jsx'; | ||
import { Link } from 'react-router-dom'; | ||
|
||
const FAQButton = ({buttonText}) => { | ||
return ( | ||
<button className='FAQButton'>{buttonText}</button> | ||
); | ||
} | ||
|
||
const ForumButton = ({buttonText}) => { | ||
return ( | ||
<button className="ForumButton">{buttonText}</button> | ||
); | ||
} | ||
|
||
const HelpCenter = () => { | ||
return ( | ||
<> | ||
<Header /> | ||
<div className="HelpCenterText"> | ||
<h1 > Shortening links can be confusing. What can we help with? </h1> | ||
</div> | ||
|
||
<div className="Buttonss"> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. are the two |
||
<Link to = "/Forum"><ForumButton buttonText="FORUM"></ForumButton></Link> | ||
<Link to ="/APIInfo"><FAQButton buttonText="FAQ"></FAQButton></Link> | ||
</div> | ||
</> | ||
); | ||
} | ||
|
||
export default HelpCenter; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
import React from 'react'; | ||
import Header from './Header.jsx'; | ||
import axios from 'axios'; | ||
import { Link } from 'react-router-dom'; | ||
|
||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can clean up some of these newlines between the imports and where you define SubmitComment - I'd have two at the most! |
||
|
||
|
||
|
||
|
||
const SubmitComment = () => { | ||
|
||
const { useState, useEffect} = React; | ||
|
||
const [first_name, setFirstName] = useState(''); | ||
const [last_name, setLastName] = useState(''); | ||
const [email, setEmail] = useState(''); | ||
const [subject, SetSubject] = useState(''); | ||
const [comment, SetComment] = useState(''); | ||
|
||
|
||
|
||
const handleSubmit = () => { | ||
const SERVER_URL = "" | ||
axios | ||
.post(SERVER_URL + 'comments', {f_name: first_name, l_name: last_name, email: email, subject: subject, comment: comment}) | ||
.then((res) => { | ||
// setResponse(res.data) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it looks like you're not using the response at all - generally it would be good to add some error handling - to just check that you get a 201 status code in this case, otherwise throw an error to let the user know that their comment didn't get added. Maybe can be skipped for this - what do you think @polarizing ? |
||
}) | ||
} | ||
|
||
const handleReset = () => { | ||
setFirstName(''); | ||
setLastName(''); | ||
setEmail(''); | ||
SetSubject(''); | ||
SetComment(''); | ||
} | ||
|
||
deleteRow = (id, e) => { | ||
const SERVER_URL = "" | ||
axios | ||
.delete(SERVER_URL + '/comments/<comment_id>') | ||
.then(res => { | ||
console.log(res); | ||
console.log(res.data); | ||
|
||
const posts = this.state.posts.filter(item => item.id !== id); | ||
this.setState({ posts }); | ||
}) | ||
} | ||
|
||
|
||
return ( | ||
<> | ||
<Header /> | ||
<div className='webContainer'> | ||
<div className='commentContainer'> | ||
<h1 className='submitHeader'>Submit Comment</h1> | ||
<div className='subjectContainer'> | ||
<label className='subjectLabel'>Subject of Comment</label> | ||
<input value={subject} type="text" name='subject' className='subectTextField' onChange={(event) => SetSubject(event.target.value)} /> | ||
</div> | ||
<br /> | ||
<div className='firstNameContainer'> | ||
<label className='firstNameLabel'>First Name</label> | ||
<input value={first_name} type="text" name='first_name' className= 'firstNameTextField'onChange={(event) => setFirstName(event.target.value)} /> | ||
</div> | ||
<br /> | ||
<div className ='lastNameContainer'> | ||
<label className='lastNameLabel'>Last Name</label> | ||
<input value={last_name} type="text" name='last_name' className= 'lastNameTextField' onChange={(event) => setLastName(event.target.value)} /> | ||
</div> | ||
<br /> | ||
<div className='emailContainer'> | ||
<label className='emailLabel'>Email Address</label> | ||
<input value={email} type="text" name= 'email' className='emailTextField' onChange={(event) => setEmail(event.target.value)} /> | ||
</div> | ||
<br /> | ||
<div className='commentTextContainer'> | ||
<label className='commentLabel'>Your Comment</label> | ||
<input value={comment} type="text" name='comment' className='commentTextField' onChange={(event) => SetComment(event.target.value)} /> | ||
</div> | ||
<div className='buttonContainer'> | ||
<button className="resetButton" onClick={handleReset}>Reset</button> | ||
<button className="btn btn-danger" onClick={(e) => this.deleteRow(post.id, e)}>Delete</button> | ||
<Link to ="/Forum"><button className="submitButton" onClick={handleSubmit}>Submit</button></Link> | ||
</div> | ||
</div> | ||
</div> | ||
</> | ||
); | ||
} | ||
|
||
export default SubmitComment; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now that Ange's PR has been merged with all of these backend routes, you should be able to delete these changes from app.py and just do a rebase on main to get them in their current form! Lemme know if you want support with the rebase, etc :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes please for the rebase help I think maybe my rebasing didn't work properly because it isn't letting me push all of my final commits?