Skip to content
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

Open
wants to merge 15 commits into
base: main
Choose a base branch
from
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
Binary file modified api-explorer.db
Binary file not shown.
38 changes: 37 additions & 1 deletion app.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,40 @@ def dict_factory(cursor, row):
d[col[0]] = row[idx]
return d

@app.route("/getComments", methods = ['GET'])
Copy link
Member

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 :)

Copy link
Contributor Author

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?

def all_comments_queries():
conn = sqlite3.connect(DATABASE)
cursor = conn.cursor()
cursor.execute('''SELECT * FROM comments_table ''')
data = cursor.fetchall()
conn.close()
return json.dumps(data)


@app.route("/comments", methods = ['POST'])
def new_comment_query():

first_name = request.json["f_name"]
last_name = request.json["l_name"]
email = request.json["email"]
subject = request.json["subject"]
comment = request.json["comment"]

conn = sqlite3.connect(DATABASE, isolation_level = None)
cursor = conn.cursor()
cursor.execute('''INSERT INTO comments_table (first_name, last_name, email, subject, comment) VALUES (?,?,?,?,?) ''', (first_name, last_name, email, subject, comment) )
cursor.close()
conn.close()

return "Comment Added"

@app.route("/", methods = ['GET'])
def hello():
hi = "hello world. Winterns are the best."
return render_template('app.html', text=hi)



@app.route('/api', methods=['GET', 'POST', 'PATCH', 'DELETE'])
def quote():

Expand Down Expand Up @@ -74,5 +102,13 @@ def quote():

return (response.json())

@app.route("/comments/<comment_id>/delete", methods = ['DELETE'])
def delete_comment_query(comment_id):

query = ''' DELETE FROM comments_table WHERE comment_id = ?'''
arg = (comment_id)
query_db(query,arg)


return "Delete Comment Successful"

# return jsonify.(statusCode = 204)
3 changes: 3 additions & 0 deletions create_comment_table.sqlite
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');
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
"webpack-cli": "^3.1.2"
},
"dependencies": {
"animate.css": "^4.1.1",
"animate.css-react": "^1.1.0",
"axios": "^0.19.1",
"merge-images": "^2.0.0",
"react": "^16.5.2",
Expand Down
Empty file added sqlite3
Empty file.
125 changes: 125 additions & 0 deletions src/Forum.jsx
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) => {
Copy link
Member

Choose a reason for hiding this comment

The 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
Copy link
Member

Choose a reason for hiding this comment

The 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>
})} */}
3 changes: 2 additions & 1 deletion src/Header.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ const Header = () => {
</button>
<div className="dropdown-contenttwo">
<Link to="/team">Meet The Team</Link>
<Link to="/help-center">Help Center</Link>
<Link to="/HelpCenter">Help Center</Link>
<a href="#">API Explorer</a>
</div>
</div>
<div className="dropdownone">
Expand Down
33 changes: 33 additions & 0 deletions src/HelpCenter.jsx
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">
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are the two ss in Buttons intentional here?

<Link to = "/Forum"><ForumButton buttonText="FORUM"></ForumButton></Link>
<Link to ="/APIInfo"><FAQButton buttonText="FAQ"></FAQButton></Link>
</div>
</>
);
}

export default HelpCenter;
3 changes: 2 additions & 1 deletion src/Home.jsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

import React from 'react';
import './styles/main.scss';
import Form from './Form.jsx';
Expand Down Expand Up @@ -57,4 +58,4 @@ function Home() {

}

export default Home;
export default Home;
95 changes: 95 additions & 0 deletions src/SubmitComment.jsx
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';


Copy link
Member

Choose a reason for hiding this comment

The 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)
Copy link
Member

Choose a reason for hiding this comment

The 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;
2 changes: 2 additions & 0 deletions src/Team.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React, { useState } from 'react';
import './styles/main.scss';
import TeamLandingPage2022 from './wintern-bios/2022/TeamLandingPage2022.jsx';
import TeamLandingPage2021 from './wintern-bios/2021/TeamLandingPage2021.jsx';

import Header from './Header.jsx';
import Footer from './Footer.jsx';

Expand All @@ -16,6 +17,7 @@ function Team() {

<div className="sidebar">
<a onClick={() => setYear(2022)}>2022</a>
<div></div>
<a onClick={() => setYear(2021)}>2021</a>
</div>

Expand Down
Binary file added src/assets/bio-photos/PROFILE.JPEG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/assets/miscellaneous/bella.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/assets/miscellaneous/broady.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/assets/miscellaneous/infinity.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/assets/miscellaneous/jason.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/assets/miscellaneous/olddoggies.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/assets/miscellaneous/quinn.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/assets/miscellaneous/rainbow.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/assets/miscellaneous/sharon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/assets/miscellaneous/stevie.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/assets/miscellaneous/toomuch.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/assets/miscellaneous/winnie.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 12 additions & 0 deletions src/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ import './styles/main.scss';
import Home from './Home.jsx';
import Team from './Team.jsx';
import APIinfo from './APIinfo.jsx';
import HelpCenter from './HelpCenter.jsx';
import Forum from './Forum.jsx';
import Submit from './SubmitComment.jsx'

const App = () => {
return (
Expand All @@ -21,6 +24,15 @@ const App = () => {
<Route path="/team">
<Team />
</Route>
<Route path="/HelpCenter">
<HelpCenter />
</Route>
<Route path="/Forum">
< Forum />
</Route>
<Route path="/Submit">
< Submit />
</Route>
<Route path="/">
<Home />
</Route>
Expand Down
Loading