Skip to content

Commit

Permalink
v1
Browse files Browse the repository at this point in the history
  • Loading branch information
bioodev committed Jan 11, 2023
1 parent 4186a1b commit 202e4c8
Show file tree
Hide file tree
Showing 21 changed files with 1,188 additions and 239 deletions.
11 changes: 11 additions & 0 deletions app/about/page.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
export default function AboutPage() {
return (
<div className="container">
<h1>About</h1>
<p>A simple blog example with Jsonplaceholder API and Nexjs</p>
<a href="https://github.com/bioodev">Designed by Bioodev</a>

</div>
);
}

9 changes: 9 additions & 0 deletions app/components/Footer.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import React from 'react'

const Footer = () => {
return (
<div className='container footer'><a href="https://github.com/bioodev">@bioodev</a></div>
)
}

export default Footer
26 changes: 26 additions & 0 deletions app/components/Navbar.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import React from "react";
import Link from "next/link";
import "./Navbar.module.css"

const Navbar = () => {
const links = [
{ label: "Home", route: "/", icon:"💎" },
{ label: "Posts", route: "/posts", icon:"📄" },
{ label: "About", route: "/about", icon:"💻" },
];
return (
<>
<nav className="container">
<ul className="navlist">
{links.map(({ label, route, icon }) => (
<li key={route}>
<Link href={route}>{icon} {label}</Link>
</li>
))}
</ul>
</nav>
</>
);
};

export default Navbar;
13 changes: 13 additions & 0 deletions app/components/Navbar.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@

.nav{
background-color: black;
display: inline-flex;
}
.nav li{
background-color: black;
display: inline-flex;
}
.nav li a{
background-color: black;
display: inline-flex;
}
9 changes: 9 additions & 0 deletions app/head.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export default function Head() {
return (
<>
<title>srndp</title>
<meta name="viewport" content="width=device-width, initial-scale=1" />
</>
);
}

20 changes: 20 additions & 0 deletions app/layout.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import Navbar from "./components/Navbar";
import Footer from "./components/Footer";
import "../styles/globals.css"
export default function RootLayout({ children }) {

return (
<html lang="es">
<head />
<body>
<header>
<Navbar />
</header>
{children}
<footer>
<Footer />
</footer>
</body>
</html>
);
}
11 changes: 11 additions & 0 deletions app/page.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import Link from "next/link";

export default function HomePage() {
return (
<div className="container">
<h1>🏴 Blog</h1>
<h3>A simple example blog with Nextjs and API</h3>
<Link className="button" href={"/posts"}>Check list of posts</Link>
</div>
);
}
20 changes: 20 additions & 0 deletions app/posts/ListOfPosts.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import Link from "next/link"
const fetchPosts = () => {
return fetch("https://jsonplaceholder.typicode.com/users/1/posts")
.then(res => res.json())
.catch(err => console.log(err))
}

export async function ListOfPosts() {
const posts = await fetchPosts()
return posts.slice(0, 15).map(post => (
<Link className="articles" href={`/posts/${post.id}`} key={post.id}>
<h2>
{post.title}
</h2>
<p>
{post.body}
</p>
</Link>
))
}
24 changes: 24 additions & 0 deletions app/posts/[id]/PostDetail.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import React from "react";

export async function PostDetail({ id }) {
const fetchPost = () => {
return fetch(`https://jsonplaceholder.typicode.com/users/1/posts?id=${id}`)
.then((res) => res.json())
.catch((err) => console.log(err));
};
const post = await fetchPost();
const { title, body } = post[0];
console.log(id);
console.log(post);
console.log(title);
return (
<div className="container">
{title && body && (
<>
<h1>{title}</h1>
<div>{body}</div>
</>
)}
</div>
);
}
11 changes: 11 additions & 0 deletions app/posts/[id]/page.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { PostDetail } from "./PostDetail";

export default function PostsPage({ params }) {
const { id } = params;

return (
<>
<PostDetail id={id} />
</>
);
}
11 changes: 11 additions & 0 deletions app/posts/page.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { ListOfPosts } from "./ListOfPosts";

export default function PostsPage() {
return (
<div className="container postslist">
<h1>Blog posts</h1>
<ListOfPosts />
</div>
);
}

3 changes: 3 additions & 0 deletions next.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
/** @type {import('next').NextConfig} */
const nextConfig = {
experimental: {
appDir: true
},
reactStrictMode: true,
}

Expand Down
Loading

1 comment on commit 202e4c8

@vercel
Copy link

@vercel vercel bot commented on 202e4c8 Jan 11, 2023

Choose a reason for hiding this comment

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

Successfully deployed to the following URLs:

blog-nextjs-api – ./

blog-nextjs-api.vercel.app
blog-nextjs-api-bioodev.vercel.app
blog-nextjs-api-git-main-bioodev.vercel.app

Please sign in to comment.