Created
January 13, 2021 17:44
-
-
Save polluterofminds/df8392083bf00f1fff742939d80d3141 to your computer and use it in GitHub Desktop.
Single Post Page
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
import React, { useState, useEffect } from "react"; | |
import ReactMarkdown from "react-markdown"; | |
import axios from "axios"; | |
import { useRouter } from "next/router"; | |
import Link from "next/link"; | |
import { checkUserSession } from "../actions/auth"; | |
const Post = () => { | |
const [content, setContent] = useState(null); | |
const router = useRouter(); | |
const { id } = router.query; | |
useEffect(() => { | |
loadPost(); | |
}, []); | |
const loadPost = async () => { | |
const loggedIn = await checkUserSession(); | |
if (loggedIn) { | |
loadContent(id); | |
} else { | |
router.push("/"); | |
} | |
} | |
const loadContent = async (id) => { | |
const res = await axios.get(`https://gateway.pinata.cloud/ipfs/${id}`); | |
setContent(res.data); | |
}; | |
return ( | |
<div> | |
<div style={styles.nav}> | |
<Link href="/">{"< Back"}</Link> | |
</div> | |
<div style={styles.main} className="blog-post"> | |
<ReactMarkdown source={content} allowDangerousHtml={true} /> | |
</div> | |
</div> | |
); | |
}; | |
const styles = { | |
nav: { | |
position: "fixed", | |
width: "100%", | |
top: 0, | |
left: 0, | |
display: "flex", | |
flexDirection: "row", | |
justifyContent: "flex-start", | |
paddingLeft: 15, | |
paddingTop: 20 | |
}, | |
main: { | |
marginTop: 60 | |
} | |
}; | |
export default Post; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment