forked from b00tc4mp/isdi-bootcamp-202409
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add comment logic and functionaliity; move validations to validate b0…
- Loading branch information
Showing
37 changed files
with
679 additions
and
391 deletions.
There are no files selected for viewing
This file contains 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
36 changes: 36 additions & 0 deletions
36
staff/angelzrc/unsocial/src/components/functional/AddComment.jsx
This file contains 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,36 @@ | ||
import { Label, Button, Form, Field } from '../library' | ||
|
||
import logic from '../../logic' | ||
|
||
export default ({ postId, onAdded }) => { | ||
console.log('AddComment -> render') | ||
|
||
const handleSubmit = event => { | ||
event.preventDefault() | ||
|
||
const form = event.target | ||
|
||
const { text: { value: text } } = form | ||
|
||
try { | ||
logic.addComment(postId, text) | ||
|
||
form.reset() | ||
|
||
onAdded() | ||
} catch (error) { | ||
alert(error.message) | ||
|
||
console.error(error) | ||
} | ||
} | ||
|
||
return <Form onSubmit={handleSubmit}> | ||
<Field> | ||
<Label htmlFor="text">New comment</Label> | ||
<textarea id="text"></textarea> | ||
</Field> | ||
|
||
<Button type="submit">Send</Button> | ||
</Form> | ||
} |
32 changes: 32 additions & 0 deletions
32
staff/angelzrc/unsocial/src/components/functional/Comment.jsx
This file contains 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,32 @@ | ||
import { Button } from '../library' | ||
|
||
import logic from '../../logic' | ||
|
||
import getElapsedTime from '../../utils/getElapsedTime' | ||
|
||
export default ({ postId, comment: { id, author, text, date }, onRemoved }) => { | ||
console.log('Comment -> render') | ||
|
||
const handleRemove = () => { | ||
if (confirm('Delete comment?')) | ||
try { | ||
logic.removeComment(postId, id) | ||
|
||
onRemoved() | ||
} catch (error) { | ||
alert(error.message) | ||
|
||
console.error(error) | ||
} | ||
} | ||
|
||
return <li> | ||
<h4>{author.username}</h4> | ||
|
||
<p>{text}</p> | ||
|
||
<time>{getElapsedTime(date)}</time> | ||
|
||
{logic.getUserId() === author.id && <Button onClick={handleRemove}>🗑️</Button>} | ||
</li> | ||
} |
107 changes: 75 additions & 32 deletions
107
staff/angelzrc/unsocial/src/components/functional/Comments.jsx
This file contains 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 |
---|---|---|
@@ -1,32 +1,75 @@ | ||
export default () => <section> | ||
<ul> | ||
<li> | ||
<h4>username</h4> | ||
<p>Lorem ipsum dolor, sit amet consectetur adipisicing elit. Numquam in maxime id, expedita quaerat, corporis dolorum earum vero culpa omnis officia ducimus ipsum ipsam sequi praesentium dolores dolor. Ipsam, possimus.</p> | ||
<time>4 days</time> | ||
</li> | ||
|
||
<li> | ||
<h4>username</h4> | ||
<p>Lorem ipsum dolor, sit amet consectetur adipisicing elit. Numquam in maxime id, expedita quaerat, corporis dolorum earum vero culpa omnis officia ducimus ipsum ipsam sequi praesentium dolores dolor. Ipsam, possimus.</p> | ||
<time>4 days</time> | ||
</li> | ||
|
||
<li> | ||
<h4>username</h4> | ||
<p>Lorem ipsum dolor, sit amet consectetur adipisicing elit. Numquam in maxime id, expedita quaerat, corporis dolorum earum vero culpa omnis officia ducimus ipsum ipsam sequi praesentium dolores dolor. Ipsam, possimus.</p> | ||
<time>4 days</time> | ||
</li> | ||
|
||
<form o/* nSubmit= {event =>{ | ||
event.preventDefault() | ||
} | ||
} */> | ||
<label htmlFor="text">New comment</label> | ||
<textarea id="text"></textarea> | ||
|
||
<button type="submit">Send</button> | ||
</form> | ||
</ul> | ||
</section> | ||
import { Component } from 'react' | ||
|
||
import Comment from './Comment' | ||
import AddComment from './AddComment' | ||
|
||
import logic from '../../logic' | ||
|
||
export default class extends Component { | ||
constructor(props) { | ||
console.log('Comments -> constructor') | ||
|
||
super(props) | ||
|
||
let comments | ||
|
||
try { | ||
comments = logic.getComments(props.postId) | ||
} catch (error) { | ||
alert(error.message) | ||
|
||
console.error(error) | ||
} | ||
|
||
this.state = { comments } | ||
} | ||
|
||
onAdded = () => { | ||
try { | ||
const comments = logic.getComments(this.props.postId) | ||
|
||
this.setState({ comments }) | ||
|
||
this.props.onAdded() | ||
} catch (error) { | ||
alert(error.message) | ||
|
||
console.error(error) | ||
} | ||
} | ||
|
||
onRemoved = () => { | ||
try { | ||
const comments = logic.getComments(this.props.postId) | ||
|
||
this.setState({ comments }) | ||
|
||
this.props.onRemoved() | ||
} catch (error) { | ||
alert(error.message) | ||
|
||
console.error(error) | ||
} | ||
} | ||
|
||
render() { | ||
console.log('Comments -> render') | ||
|
||
return <section> | ||
<ul> | ||
{this.state.comments.map(comment => | ||
<Comment | ||
postId={this.props.postId} | ||
comment={comment} | ||
onRemoved={this.onRemoved} | ||
/>) | ||
} | ||
</ul> | ||
|
||
<AddComment | ||
postId={this.props.postId} | ||
onAdded={this.onAdded} | ||
/> | ||
</section> | ||
} | ||
} |
40 changes: 0 additions & 40 deletions
40
staff/angelzrc/unsocial/src/components/functional/CreatePost.jsx
This file was deleted.
Oops, something went wrong.
This file contains 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
File renamed without changes.
Oops, something went wrong.