Skip to content
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

Added basic posts page #1

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@ module.exports = {
plugins: ['react-refresh'],
rules: {
'react-refresh/only-export-components': 'warn',
'react/prop-types': 'off'
},
}
3 changes: 3 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Roboto:wght@100;300;400;500;700;900&display=swap" rel="stylesheet">
<title>Vite + React</title>
</head>
<body>
Expand Down
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,11 @@
"preview": "vite preview"
},
"dependencies": {
"axios": "^1.4.0",
"axios-hooks": "^4.0.0",
"react": "^18.2.0",
"react-dom": "^18.2.0"
"react-dom": "^18.2.0",
"swr": "^2.2.0"
},
"devDependencies": {
"@types/react": "^18.0.37",
Expand Down
121 changes: 121 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion public/vite.svg

This file was deleted.

6 changes: 5 additions & 1 deletion src/App.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import Posts, { PostsAxios } from "./components/posts";
import Nav from "./components/navbar";

function App() {
return (
<>
<h1>Hello, World!</h1>
<Nav />
<Posts totalPosts={10} />
</>
)
}
Expand Down
16 changes: 16 additions & 0 deletions src/components/navbar/Nav.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import NavTitle from "./NavTitle";
import NavLinks from "./NavLinks";

import "./nav.css"


export default function Nav() {
return (
<>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unnecessary fragment

<nav className="nav">
<NavTitle title={"React Posts App"}/>
<NavLinks />
</nav>
</>
)
}
7 changes: 7 additions & 0 deletions src/components/navbar/NavLink.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@


export default function NavLink({ title }) {
return (
<div className="nav-link">{title}</div>
)
}
10 changes: 10 additions & 0 deletions src/components/navbar/NavLinks.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import NavLink from "./NavLink";


export default function NavLinks() {
return (
<div className="nav-links-container">
<NavLink title={"Create"}/>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
<NavLink title={"Create"}/>
<NavLink title="Create"/>

</div>
)
}
10 changes: 10 additions & 0 deletions src/components/navbar/NavTitle.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@


export default function NavTitle({ title }) {
return (
<div className="nav-title-container">
<h1 className="nav-title">{title}</h1>
</div>
)
}

3 changes: 3 additions & 0 deletions src/components/navbar/index.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import Nav from "./Nav";

export default Nav;
36 changes: 36 additions & 0 deletions src/components/navbar/nav.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@

.nav {
display: flex;
color: white;
background-color: #0078FB;
padding: 0 20px;
}

.nav-title {
font-size: 22px;
padding: 10px;
}

.nav-links-container {
flex: 1;
display: flex;
justify-content: end;
align-items: center;
}

.nav-link {
padding: 10px;
font-size: 14px;
font-weight: 500;
border-radius: 5px;
color: white;
border: 1px solid white;
margin: 5px;
text-transform: uppercase;
}

.nav-link:hover {
color: #0078FB;
background-color: white;
transition-delay: 0.1s;
}
17 changes: 17 additions & 0 deletions src/components/posts/Post.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@


function Post({ title, body }) {
return (
<div className="post">
<div className="post-title">
{title}
</div>
<div className="post-body">
{body}
</div>
</div>
)
}


export default Post;
22 changes: 22 additions & 0 deletions src/components/posts/Posts.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import Post from "./Post";
import "./posts.css";

import usePosts from "./utils";


function Posts({ totalPosts }) {
const { posts, error, isLoading } = usePosts();

if (isLoading) return <div>...Loading</div>
if (error) return <div>{error}</div>
return (
<div className="posts">
{posts.data.slice(0, totalPosts).map(post =>
<Post key={post.id} title={post.title} body={post.body} />
)}
</div>
)
}


export default Posts;
Loading