Skip to content

Commit

Permalink
add heading and image core components; update title and view compos; …
Browse files Browse the repository at this point in the history
…add user name retrieval and rendering in home; add post list compo in home with posts retrieval and redering; b00tc4mp#149
  • Loading branch information
unknown authored and unknown committed Jun 12, 2024
1 parent 4dc5cb3 commit 5fbddd5
Show file tree
Hide file tree
Showing 10 changed files with 130 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
function Heading({ level, className, children }) {
const Tag = `h${level}`

return <Tag className={` ${className ? className : ''}`}>{children}</Tag>

}

export default Heading
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import './Image.css'

function Image({ src, className }) {
return <img className={`Image ${className ? className : ''}`} src={src} />
}

export default Image
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import Heading from './Heading'


function Title({ children }) {
return <h1>{children}</h1>
return <Heading level='1'>{children}</Heading>
}

export default Title
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
display: flex;
flex-direction: column;
align-items: center;
padding: 20rem;
padding: 1rem;
background: linear-gradient(to bottom right, rgb(241, 178, 5), rgb(234, 205, 127));
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import './View.css'

function View({ tag: Tag = 'div', children }) {
return <Tag className="View">{children}</Tag>
function View({ tag: Tag = 'div', className, children }) {
return <Tag className={`View ${className ? className : ''}`}>{children}</Tag>
}

export default View
6 changes: 3 additions & 3 deletions staff/mateo-gomez/socialcode/app/src/main.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import App from './App.jsx'
import './index.css'

ReactDOM.createRoot(document.getElementById('root')).render(
<React.StrictMode>
<App />
</React.StrictMode>,
//<React.StrictMode>
<App />
//</React.StrictMode>,
)
30 changes: 28 additions & 2 deletions staff/mateo-gomez/socialcode/app/src/views/Home.jsx
Original file line number Diff line number Diff line change
@@ -1,25 +1,51 @@

import { useState, useEffect } from 'react'
import Title from '../components/core/Title'
import View from '../components/library/View'
import Header from './components/Header'
import Button from '../components/core/Button'
import logic from '../logic'
import Heading from '../components/core/Heading'
import PostList from './components/PostList'

function Home({ onUserLoggedOut }) {
console.log('Home -> render')

const [name, setName] = useState('')

const handleLogout = () => {
logic.logoutUser()

onUserLoggedOut()
}

useEffect(() => {
try {
logic.getUserName((error, name) => {
if (error) {
console.error(error)

alert(error.message)

return
}

setName(name)
})

} catch (error) {
console.error(error)

alert(error.message)
}
})

return <View>
<Header>
<Heading level="3">{name}</Heading>
<Button onClick={handleLogout}>Logout</Button>
</Header>
<View tag='main'>
<Title>Hello, Home!</Title>
<PostList />
</View>
<footer></footer>

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
.Post {
width: 50rem;
height: auto;
background-color: aliceblue;
border: 1px solid orange;
margin: 2rem;
border-radius: 4%;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
.PostList {
position: center;
bottom: 0;
width: 100%;
left: 0;
box-sizing: border-box;
background-color: rgba(255, 191, 0, 0.792);
}
61 changes: 61 additions & 0 deletions staff/mateo-gomez/socialcode/app/src/views/components/PostList.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import './PostList.css'
import './Post.css'

import Image from "../../components/core/Image"
import Heading from '../../components/core/Heading'
import View from "../../components/library/View"

import logic from '../../logic'
import { useEffect, useState } from 'react'

function PostList() {
console.log('PostList -> render')

const [posts, setPosts] = useState([])

useEffect(() => {
console.log('PostList -> useEffect')

try {
logic.getAllPosts((error, posts) => {
if (error) {
console.error(error)

alert(error.message)

return
}

setPosts(posts)
})

} catch (error) {
console.error(error)

alert(error.message)
}
}, [])

return <View tag="section" className='PostList'>

{posts.map(post => <article className="Post">
<p className="AuthorTitle">{post.author}</p>
<Heading level='2' className="PostTitle">{post.title}</Heading>
<Image className="PostImage" src={post.image} />
<Heading level='4' className="DescriptionTitle">
Description:
</Heading>
<p className="PostDescription">
{post.description}</p>
<time>{post.date}</time>
<button className="Button">Delete</button>
</article>

)}


</View>

}

export default PostList

0 comments on commit 5fbddd5

Please sign in to comment.