-
Notifications
You must be signed in to change notification settings - Fork 223
Project submission for post and comments #215
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
Open
colormethanh
wants to merge
18
commits into
projectshft:master
Choose a base branch
from
colormethanh:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
dfc57ba
initial setup
colormethanh 6a3bde6
added post and create post element
colormethanh c0c771f
Finished adding and testing logic
colormethanh e6ef3c5
Fixed vertical line to be responsive
colormethanh 571c0aa
added populatePost func and create post/comment element func
colormethanh e7bc257
Added create new post and like/dislike post function
colormethanh d8292ef
added comment and comment reply func
colormethanh 5c15df7
added post delete and comment delete
colormethanh 456de4a
added confirmation modal to post delete
colormethanh 561847f
updated README.md
colormethanh 1f0e28c
added some comments
colormethanh 41cbb66
changed import statement to be correct in main.js
colormethanh 64e5868
changed modal font color
colormethanh ee57171
removed uuidv4
colormethanh d3b1465
Merge branch 'master' of https://github.com/colormethanh/project-reddit
colormethanh 6357c82
fixed toggle form comment button
colormethanh 714118d
fixed misplaced semi-colon
colormethanh 93ab7aa
updated ReadMe
colormethanh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| { | ||
| "cSpell.words": ["Btns", "postid", "uniqueid", "uuidv"], | ||
| "liveServer.settings.port": 5501 | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| Copyright (c) 2008-2019 Pivotal Labs | ||
| Copyright (c) 2008-2023 The Jasmine developers | ||
|
|
||
| Permission is hereby granted, free of charge, to any person obtaining | ||
| a copy of this software and associated documentation files (the | ||
| "Software"), to deal in the Software without restriction, including | ||
| without limitation the rights to use, copy, modify, merge, publish, | ||
| distribute, sublicense, and/or sell copies of the Software, and to | ||
| permit persons to whom the Software is furnished to do so, subject to | ||
| the following conditions: | ||
|
|
||
| The above copyright notice and this permission notice shall be | ||
| included in all copies or substantial portions of the Software. | ||
|
|
||
| THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
| EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
| MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||
| NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE | ||
| LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION | ||
| OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION | ||
| WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,143 @@ | ||
|
|
||
| export class SocialMedia { | ||
| #posts; | ||
| constructor() { | ||
| this.#posts = []; | ||
| } | ||
|
|
||
| setPost(postArray) { | ||
|
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. I would call this update posts |
||
| this.#posts = postArray; | ||
| } | ||
|
|
||
| createPost(author, text) { return new Post(author, text) }; | ||
|
|
||
| addPost(author, text){ | ||
| const newPost = this.createPost(author, text); | ||
| this.#posts.push(newPost) | ||
| return newPost; | ||
| }; | ||
|
|
||
| getPosts(){ return this.#posts }; | ||
|
|
||
| getPost(id){ | ||
| const post = this.#posts.find((post) => { | ||
| return post.getId() === id; | ||
| }) | ||
| return post; | ||
| }; | ||
|
|
||
| deletePost(id) { | ||
| const postToDelete = this.getPost(id); | ||
| const newPostArray = []; | ||
| this.#posts.forEach((post) => { | ||
| if (post !== postToDelete ) return newPostArray.push(post); | ||
| }); | ||
| this.setPost(newPostArray); | ||
| }; | ||
|
|
||
| } | ||
|
|
||
| export class Post { | ||
| #author; | ||
| #text; | ||
| #comments; | ||
| #id; | ||
| #likes; | ||
| constructor(author, text) { | ||
| this.#author = author; | ||
| this.#text = text; | ||
| this.#comments = []; | ||
| this.#likes = 0; | ||
| this.#id = new Date().getTime() + Math.random(); | ||
| } | ||
|
|
||
| getId() {return this.#id}; | ||
|
|
||
| getPost() {return `${this.#author}\n${this.#text}`}; | ||
|
|
||
| getText() {return this.#text}; | ||
|
|
||
| getAuthor() {return this.#author}; | ||
|
|
||
| getComments() {return this.#comments}; | ||
|
|
||
| getComment(id){ | ||
| const comment = this.#comments.find((comment) => { | ||
| return comment.getId() === id; | ||
| }) | ||
| return comment; | ||
| }; | ||
|
|
||
| setComments(commentsArray) { | ||
| this.#comments = commentsArray; | ||
| } | ||
|
|
||
| getLikeCt() {return this.#likes}; | ||
|
|
||
| deleteComment(id) { | ||
| const commentToDelete = this.getComment(id); | ||
| const newCommentArray = []; | ||
| this.#comments.forEach((comment) => { | ||
| if (comment !== commentToDelete ) return newCommentArray.push(comment); | ||
| }); | ||
| this.setComments(newCommentArray); | ||
| } | ||
|
|
||
| likePost(type) { | ||
| let success = false; | ||
| switch (type) { | ||
| case "like": | ||
| this.#likes += 1; | ||
| success = true; | ||
| break; | ||
| case "dislike": | ||
| this.#likes -= 1; | ||
| success = true; | ||
| break; | ||
| } | ||
| if (success)console.log("Successfully liked comment"); | ||
| return this; | ||
| }; | ||
|
|
||
| createComment(author, text) { | ||
| return new Comment(author, text, this); | ||
| }; | ||
|
|
||
| addComment(author, text){ | ||
|
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. function name doesnt match what it is actually doing. Its adding but also getting, maybe worth separating the logic |
||
| const comment = this.createComment(author, text); | ||
| this.#comments.push(comment); | ||
| return comment; | ||
| }; | ||
|
|
||
| }; | ||
|
|
||
| export class Comment extends Post { | ||
| #author; | ||
| #text; | ||
| #parentPost; | ||
| #likes; | ||
| constructor(author, text, parentPost) { | ||
| super(author, text); | ||
| this.#author = author; | ||
| this.#text = text; | ||
| this.#likes = 0; | ||
| this.#parentPost = parentPost; | ||
| } | ||
|
|
||
| getParent() {return this.#parentPost}; | ||
|
|
||
| createCommentReply(otherCommentAuthor, reply) { | ||
| const replyPrefix = `<strong>@${this.#author}</strong> `; | ||
|
|
||
| const replyText = replyPrefix + reply; | ||
| const newComment = this.#parentPost.addComment(otherCommentAuthor, replyText); | ||
|
|
||
| return newComment; | ||
| }; | ||
| } | ||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| <!doctype html> | ||
| <html> | ||
| <head> | ||
| <meta charset="utf-8" /> | ||
| <title>Jasmine Spec Runner v5.1.2</title> | ||
|
|
||
| <link | ||
| rel="shortcut icon" | ||
| type="image/png" | ||
| href="lib/jasmine-5.1.2/jasmine_favicon.png" | ||
| /> | ||
| <link rel="stylesheet" href="lib/jasmine-5.1.2/jasmine.css" /> | ||
|
|
||
| <script src="lib/jasmine-5.1.2/jasmine.js"></script> | ||
| <script src="lib/jasmine-5.1.2/jasmine-html.js"></script> | ||
| <script src="lib/jasmine-5.1.2/boot0.js"></script> | ||
| <!-- optional: include a file here that configures the Jasmine env --> | ||
| <script src="lib/jasmine-5.1.2/boot1.js"></script> | ||
|
|
||
| <script src="./src/jquery-3.7.1.min.js"></script> | ||
|
|
||
| <!-- include source files here... --> | ||
| <script type="module" src="main.js"></script> | ||
|
|
||
| <!-- include spec files here... --> | ||
| <script type="module" src="spec/ReRedditSpec.js"></script> | ||
| </head> | ||
|
|
||
| <body></body> | ||
| </html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,113 @@ | ||
| <!doctype html> | ||
| <html lang="en"> | ||
| <head> | ||
| <meta charset="UTF-8" /> | ||
| <meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
| <script | ||
| src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js" | ||
| integrity="sha384-YvpcrYf0tY3lHB60NNkmXc5s9fDVZLESaAA55NDzOxhy9GkcIdslK1eN7N6jIeHz" | ||
| crossorigin="anonymous" | ||
| ></script> | ||
| <link | ||
| href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" | ||
| rel="stylesheet" | ||
| integrity="sha384-QWTKZyjpPEjISv5WaRU9OFeRpok6YctnYmDr5pNlyT2bRjXh0JMhjY6hW+ALEwIH" | ||
| crossorigin="anonymous" | ||
| /> | ||
| <link | ||
| rel="stylesheet" | ||
| href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.3/font/bootstrap-icons.min.css" | ||
| /> | ||
| <script src="./src/jquery-3.7.1.min.js"></script> | ||
| <link rel="stylesheet" href="style.css" /> | ||
| <title>Project Reddit</title> | ||
| </head> | ||
| <body> | ||
| <div class="container" id="content-container"> | ||
| <header> | ||
| <div class="row text-center mt-3"> | ||
| <h1>ReReddit</h1> | ||
| </div> | ||
| </header> | ||
|
|
||
| <article> | ||
| <h1>Posts</h1> | ||
| <!-- Post elements section --> | ||
| <section class="row mb-4 p-4" id="posts"> | ||
| <div class="column" id="posts-inner"></div> | ||
| </section> | ||
| <!--Create a new Post form section --> | ||
| <section class="row" id="post-form"> | ||
| <div class="col-12 post-form-header"> | ||
| <h2>Create a post</h2> | ||
| </div> | ||
| <div class="col-12"> | ||
| <form class="form" id="create-post-form"> | ||
| <div class="form-group mb-2"> | ||
| <input | ||
| type="text" | ||
| class="form-control" | ||
| placeholder="Name" | ||
| id="post-name-input" | ||
| /> | ||
| </div> | ||
| <div class="form-group mb-2"> | ||
| <input | ||
| type="text" | ||
| class="form-control" | ||
| placeholder="Post text" | ||
| id="post-text-inpunt" | ||
| /> | ||
| </div> | ||
| <button | ||
| type="submit" | ||
| id="post-submit" | ||
| class="btn btn-primary" | ||
| aria-label="post submit button" | ||
| > | ||
| Post | ||
| </button> | ||
| </form> | ||
| </div> | ||
| </section> | ||
| <!-- Post delete confirmation modal --> | ||
| <div | ||
| class="modal fade" | ||
| id="confirmationModal" | ||
| tabindex="-1" | ||
| role="dialog" | ||
| aria-labelledby="deleteConfirmation" | ||
| aria-hidden="true" | ||
| > | ||
| <div class="modal-dialog" role="document"> | ||
| <div class="modal-content"> | ||
| <div class="modal-header"> | ||
| <h2 class="modal-title">Are you sure?</h2> | ||
| </div> | ||
| <div class="modal-body"></div> | ||
| <div class="modal-footer"> | ||
| <button | ||
| type="button" | ||
| class="btn btn-secondary" | ||
| data-bs-dismiss="modal" | ||
| id="modal-close" | ||
| > | ||
| Close | ||
| </button> | ||
| <button | ||
| type="button" | ||
| class="btn btn-danger" | ||
| id="confirm-delete" | ||
| > | ||
| Yes, delete the sucker! | ||
| </button> | ||
| </div> | ||
| </div> | ||
| </div> | ||
| </div> | ||
| </article> | ||
| </div> | ||
| <script type="module" src="MyClasses.js"></script> | ||
| <script type="module" src="main.js"></script> | ||
| </body> | ||
| </html> |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
why the # ?