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 date logic and comments to unsocial b00tc4mp#177
- Loading branch information
1 parent
f93527c
commit 5f956f1
Showing
36 changed files
with
201 additions
and
98 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
Empty file.
23 changes: 23 additions & 0 deletions
23
staff/juanp-arias/unsocial/src/components/function/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 |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { Button, Form, Label } from '../library' | ||
|
||
export default () => | ||
<section> | ||
<ul> | ||
<li> | ||
<h4>juanpablo</h4> | ||
<p>Lovely!</p> | ||
<time>1 day ago</time> | ||
</li> | ||
<li> | ||
<h4>pepito</h4> | ||
<p>Nice pic!</p> | ||
<time>2 days ago</time> | ||
</li> | ||
</ul> | ||
<Form> | ||
<Label htmlFor="text">New comment</Label> | ||
<textarea id="text"></textarea> | ||
|
||
<Button type="submit">Send</Button> | ||
</Form> | ||
</section> |
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
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
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
52 changes: 39 additions & 13 deletions
52
staff/juanp-arias/unsocial/src/components/function/PostItem.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,25 +1,51 @@ | ||
import './PostItem.css' | ||
import { Button } from '../library' | ||
|
||
import logic from '../../logic' | ||
import dateAgo from '../../utilities/dateAgo' | ||
import Comments from './Comments' | ||
|
||
import './PostItem.css' | ||
import { Component } from 'react' | ||
|
||
export default class extends Component { | ||
constructor(props) { | ||
super(props) | ||
this.state = { view: null } | ||
} | ||
|
||
render() { | ||
|
||
const { item: { id, author, image, text, date, liked, likes }, onLikeClicked, onDeleted } = this.props | ||
return <article className="PostItem"> | ||
<h4>{author.username}</h4> | ||
|
||
<img src={image} /> | ||
|
||
<p>{text}</p> | ||
|
||
<time>{dateAgo(date)}ago</time> | ||
|
||
function PostItem({ item: { id, author, image, text, date, liked, likes }, onLikeClicked }) { | ||
return <article className="PostItem"> | ||
<h4>{author.username}</h4> | ||
<Button onClick={() => { | ||
logic.toggleLikePosts(id) | ||
|
||
<img src={image} /> | ||
onLikeClicked() | ||
}}>{`${liked ? '❤️' : '🤍'} ${likes.length} likes`}</Button> | ||
|
||
<p>{text}</p> | ||
{author.id === logic.getUserId() && | ||
<Button onClick={() => { | ||
if (confirm('Delete post?')) { | ||
logic.deletePost(id) | ||
|
||
<time>{date}</time> | ||
onDeleted() | ||
} | ||
}}>Delete</Button>} | ||
|
||
<Button onClick={() => { | ||
logic.toggleLikePosts(id) | ||
<Button onClick={() => { | ||
this.setState({ view: this.state.view ? null : 'comments' }) | ||
}}>Comment</Button> | ||
|
||
onLikeClicked() | ||
}}>{`${liked ? '❤️' : '🤍'} ${likes.length} likes`}</Button> | ||
</article> | ||
{this.state.view === 'comments' && <Comments />} | ||
</article> | ||
} | ||
} | ||
|
||
export default PostItem |
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
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
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,3 @@ | ||
.Button { | ||
border-radius: 0.5rem; | ||
} |
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,6 +1,5 @@ | ||
import './Button.css' | ||
|
||
function Button({ type, children, onClick }) { | ||
return <button type={type} className="Button" onClick={onClick}>{children}</button> | ||
} | ||
export default Button | ||
export default ({ type, children, onClick }) => | ||
<button type={type} className="Button" onClick={onClick}>{children}</button> | ||
|
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,6 +1,5 @@ | ||
import './Field.css' | ||
|
||
function Field({ children }) { | ||
return <div className="Field">{children}</div> | ||
} | ||
export default Field | ||
export default ({ children }) => | ||
<div className="Field">{children}</div> | ||
|
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,7 +1,6 @@ | ||
import './Form.css' | ||
|
||
function Form({ children, onSubmit }) { | ||
return <form className="Form" onSubmit={onSubmit}>{children}</form> | ||
} | ||
export default ({ children, onSubmit }) => | ||
<form className="Form" onSubmit={onSubmit}>{children}</form> | ||
|
||
|
||
export default Form |
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,5 @@ | ||
.Input { | ||
border-radius: 0.2rem; | ||
width: 13rem; | ||
background-color: white; | ||
} |
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,6 +1,5 @@ | ||
import './Input.css' | ||
|
||
function Input({ type, id }){ | ||
return <input type = {type} id= {id} className= "Input" /> | ||
} | ||
export default Input | ||
export default ({ type, id, placeholder }) => | ||
<input type={type} id={id} placeholder={placeholder} className="Input" /> | ||
|
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,7 +1,7 @@ | ||
import './Label.css' | ||
|
||
function Label({ htmlFor, children }) { | ||
return <label hmtlFor={htmlFor} className="Label">{children}</label> | ||
} | ||
export default({ htmlFor, children }) => | ||
<label hmtlFor={htmlFor} className="Label">{children}</label> | ||
|
||
export default Label | ||
|
||
|
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,3 @@ | ||
.emoji{ | ||
margin-right: 4.4rem; | ||
} |
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
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,3 +1,2 @@ | ||
const uuid = () => (Date.now() + Math.random()).toString(36).replace('.', '') | ||
export default () => (Date.now() + Math.random()).toString(36).replace('.', '') | ||
|
||
export default uuid |
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
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,13 @@ | ||
export default postId => { | ||
const posts = JSON.parse(localStorage.posts) | ||
|
||
const index = posts.findIndex(({ id }) => id === postId) | ||
|
||
|
||
if (index < 0) throw new Error('post not found') | ||
|
||
posts.splice(index, 1) | ||
|
||
localStorage.posts = JSON.stringify(posts) | ||
} | ||
//función deletePost para eliminar los posts que queremos, le estamos dando funcionalidad a el botón delete |
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
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 @@ | ||
export default () => sessionStorage.userId |
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,10 +1,10 @@ | ||
const getUserName = () => { | ||
export default () => { | ||
const users = JSON.parse(localStorage.users) | ||
const user = users.find(user => user.id === sessionStorage.userId) | ||
|
||
if (!user) throw new Error('user not found') | ||
|
||
return user.name | ||
} | ||
export default getUserName | ||
|
||
|
Oops, something went wrong.