Skip to content

Commit

Permalink
Merge pull request #80 from Noroff-FED-Campus-Assignments/staging
Browse files Browse the repository at this point in the history
Staging
  • Loading branch information
Cnbergh authored Oct 15, 2023
2 parents bcc88f5 + 502c8dd commit d465d33
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ function App() {
</main>

<footer>
<small>Created with ❤️ by You</small>
<small>Created with ❤️ by Team Mimir</small>
</footer>
</>
);
Expand Down
2 changes: 1 addition & 1 deletion src/components/navbar/posts/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ function OtherPosts() {
{String.fromCodePoint(0x1f44d)} Like {post.likes}
</button>
{/** Button to "post page" -- @author Cnbergh*/}
<Link to={`/post/${post.id}`}>
<Link to={`/posts/${post.id}`}>
<button className="text-sm text-gray-600 border border-gray-300 dark:text-white dark:border-darkGray dark:bg-gray-700 hover:text-emerald-500 hover:border-emerald-500">View Post</button>
</Link>
</div>
Expand Down
2 changes: 1 addition & 1 deletion src/lib/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ export const NAVIGATION = [
{ label: "Profiles", href: "/profiles" },
{ label: "Posts", href: "/posts" },
{ label: "Login", href: "/login" },
{ label: "Single Post", href: "/post/:id" }, //added link to post -- Cnbergh
{ label: "Post", href: "/posts/$postId" }, //added to post -- Cnbergh
];
29 changes: 22 additions & 7 deletions src/pages/Post.jsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,33 @@
import { API_URL } from '../lib/constants';
import { useEffect, useState } from 'react';
import { useParams, Link } from '@tanstack/react-router';
import { Link } from '@tanstack/react-router';
import UserIcon from "../assets/icons/user.svg";

const SinglePostPage = () => {
const { id } = useParams();
const PostPage = () => {
const id = window.location.pathname;
const [post, setPost] = useState(null);
const accessToken = localStorage.getItem("jwt");

useEffect(() => {

const fetchData = async () => {
const response = await fetch(`${API_URL}/social/posts/${id}`);
const data = await response.json();
setPost(data);
const url = `${API_URL}${id}`;

const response = await fetch(url, {
method: "GET",
headers: {
Authorization: `Bearer ${accessToken}`,
},
});

if (response.ok) {
const data = await response.json();
setPost(data);
} else {
console.log("Error:", response.status, response.statusText);
}
};

fetchData();
}, [id]);

Expand Down Expand Up @@ -54,4 +69,4 @@ const SinglePostPage = () => {
);
};

export default SinglePostPage;
export default PostPage;

0 comments on commit d465d33

Please sign in to comment.