forked from b00tc4mp/isdi-bootcamp-202405
-
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 new function at the app, in react method fav y follow at header c…
…omponent b00tc4mp#79
- Loading branch information
Fabián Romero
authored and
Fabián Romero
committed
Jul 5, 2024
1 parent
785f6ba
commit d00825e
Showing
11 changed files
with
333 additions
and
95 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
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
60 changes: 0 additions & 60 deletions
60
staff/fabian-romero/react/ponies/app/view/home/component/FavPostList.jsx
This file was deleted.
Oops, something went wrong.
118 changes: 118 additions & 0 deletions
118
staff/fabian-romero/react/ponies/app/view/home/component/FavsPostList.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,118 @@ | ||
import logic from '../../../logic/index.mjs' | ||
|
||
const { Component } = React | ||
|
||
import Post from './Post.jsx' | ||
|
||
class FavsPostList extends Component { | ||
constructor() { | ||
console.debug('FavsPostList -> constructor') | ||
|
||
super() | ||
|
||
try { | ||
const posts = logic.getAllFavPosts() | ||
|
||
this.state = { posts } | ||
} catch (error) { | ||
console.error(error) | ||
|
||
alert(error.message) | ||
} | ||
} | ||
|
||
componentWillReceiveProps(newProps) { | ||
console.debug('FavsPostList -> componentWillReceiveProps', newProps, this.props) | ||
|
||
if (newProps.refreshStamp !== this.props.refreshStamp) | ||
try { | ||
const posts = logic.getAllFavPosts() | ||
|
||
this.setState({ posts }) | ||
} catch (error) { | ||
console.error(error) | ||
|
||
alert(error.message) | ||
} | ||
} | ||
|
||
handlePostDeleted() { | ||
try { | ||
const posts = logic.getAllFavPosts() | ||
|
||
this.setState({ posts }) | ||
} catch (error) { | ||
console.error(error) | ||
|
||
alert(error.message) | ||
} | ||
} | ||
|
||
handlePostEdited() { | ||
try { | ||
const posts = logic.getAllFavPosts() | ||
|
||
this.setState({ posts }) | ||
} catch (error) { | ||
console.error(error) | ||
|
||
alert(error.message) | ||
} | ||
} | ||
|
||
handlePostLiked() { | ||
try { | ||
const posts = logic.getAllFavPosts() | ||
|
||
this.setState({ posts }) | ||
} catch (error) { | ||
console.error(error) | ||
|
||
alert(error.message) | ||
} | ||
} | ||
|
||
handlePostFavorited() { | ||
try { | ||
const posts = logic.getAllFavPosts() | ||
|
||
this.setState({ posts }) | ||
} catch (error) { | ||
console.error(error) | ||
|
||
alert(error.message) | ||
} | ||
} | ||
|
||
handleFollowedUser() { | ||
try { | ||
const posts = logic.getAllFavPosts() | ||
|
||
this.setState({ posts }) | ||
} catch (error) { | ||
console.error(error) | ||
|
||
alert(error.message) | ||
} | ||
} | ||
|
||
render() { | ||
console.debug('FavsPostList -> render') | ||
|
||
return <section className="post-list"> | ||
{this.state.posts.map(post => <Post | ||
key={post.id} | ||
post={post} | ||
onPostDeleted={this.handlePostDeleted.bind(this)} | ||
onPostEdited={this.handlePostEdited.bind(this)} | ||
onPostLiked={this.handlePostLiked.bind(this)} | ||
onPostFavToggled={this.handlePostFavorited.bind(this)} | ||
onFollowedUser={this.handleFollowedUser.bind(this)} | ||
/>)} | ||
</section> | ||
} | ||
} | ||
|
||
export default FavsPostList | ||
|
||
// esta logica es la misma que PostList pero ahora en Fav.. llamando a la logica anterior del JS get all FAV post! en vez del get all post... |
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
124 changes: 124 additions & 0 deletions
124
staff/fabian-romero/react/ponies/app/view/home/component/PoniesPostList.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,124 @@ | ||
import logic from '../../../logic/index.mjs' | ||
|
||
const { Component } = React | ||
|
||
import Post from './Post.jsx' | ||
|
||
class PoniesPostList extends Component { | ||
constructor() { | ||
console.debug('PoniesPostList -> contructor') | ||
|
||
super() | ||
|
||
try { | ||
const posts = logic.getAllPoniesPosts() // caambiar por la logica que trae solo los ffollower ya no seria get all post si no el get all fav post que ahora los ponies es followCORRIEGIR | ||
|
||
this.state = { posts } // inicializar los post lo llamamos, se contruye y luego en render lo pinta y me devulve todo el DOM | ||
} catch (error) { | ||
console.error(error) | ||
|
||
alert(error.message) | ||
} | ||
} | ||
|
||
componentWillReceiveProps(newProps) { | ||
console.debug('PoniesPostList -> componentWillReceiveProps', newProps, this.props) // esto es una funcuon que tengo que saber que hace ciclo de vida del componente | ||
// react lo llama cuando detecta que cambia un prop | ||
//se puede implementar a demanda y me dice que voy a recibir nuevos props (newProps) | ||
// new props | ||
|
||
if (newProps.refreshStamp !== this.props.refreshStamp) | ||
try { | ||
const posts = logic.getAllPoniesPosts() | ||
|
||
this.setState({ posts }) | ||
} catch (error) { | ||
console.error(error) | ||
|
||
alert(error.message) | ||
} | ||
} | ||
|
||
handlePostDeleted() {// aqui llamo a la logica de deleted dentro del post list abajo | ||
try { | ||
const posts = logic.getAllPoniesPosts() | ||
|
||
this.setState({ posts }) | ||
} catch (error) { | ||
console.error(error) | ||
|
||
alert(error.message) | ||
} | ||
} | ||
|
||
handlePostEdited() { // aqui llamo a la logica de edited dentro del post list abajo | ||
try { | ||
const posts = logic.getAllPoniesPosts() | ||
|
||
this.setState({ posts }) | ||
} catch (error) { | ||
console.error(error) | ||
|
||
alert(error.message) | ||
} | ||
} | ||
|
||
handlePostLikeToggled() { | ||
|
||
try { | ||
const posts = logic.getAllPoniesPosts() | ||
|
||
this.setState({ posts }) | ||
} catch (error) { | ||
console.error(error) | ||
|
||
alert(error.message) | ||
} | ||
} | ||
|
||
handlePostFavToggled() { | ||
|
||
try { | ||
const posts = logic.getAllPoniesPosts() | ||
|
||
this.setState({ posts }) | ||
} catch (error) { | ||
console.error(error) | ||
|
||
alert(error.message) | ||
} | ||
} | ||
|
||
handleUserFollowToggled() { // este es el mismo nombre que tengo en el renders | ||
|
||
try { | ||
const posts = logic.getAllPoniesPosts() // esta logica es la misma de arriba | ||
|
||
this.setState({ posts }) | ||
} catch (error) { | ||
console.error(error) | ||
|
||
alert(error.message) | ||
} | ||
} | ||
|
||
|
||
|
||
render() { | ||
console.debug('PoniesPostList -> render') | ||
|
||
return <section className="post-list"> | ||
{this.state.posts.map(post => <Post | ||
key={post.id} | ||
post={post} | ||
onPostDeleted={this.handlePostDeleted.bind(this)} | ||
onPostEdited={this.handlePostEdited.bind(this)} | ||
onPostLikeToggled={this.handlePostLikeToggled.bind(this)} | ||
onPostFavToggled={this.handlePostFavToggled.bind(this)} | ||
onUserFollowToggled={this.handleUserFollowToggled.bind(this)} | ||
/>)} | ||
</section> | ||
} | ||
} | ||
|
||
export default PoniesPostList |
Oops, something went wrong.