Skip to content

Commit

Permalink
updated post components
Browse files Browse the repository at this point in the history
  • Loading branch information
yemiwebby committed Dec 30, 2019
1 parent e493f97 commit 3b2e474
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 18 deletions.
2 changes: 1 addition & 1 deletion blog-frontend/src/components/Home.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Link, useHistory } from 'react-router-dom';
import { useAuth0 } from '../contexts/auth0-context';


function Home() {
function Home():JSX.Element {
let history = useHistory()
const { isAuthenticated, getIdTokenClaims, user } = useAuth0();

Expand Down
12 changes: 6 additions & 6 deletions blog-frontend/src/components/post/Create.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ function Create(): JSX.Element {
const [submitSuccess, setSubmitSuccess] = useState<boolean>(false);
const [loading, setLoading] = useState<boolean>(false);

useEffect(() => {
if (user) {
setAuthor(user.name)
}
}, [user])

const handleFormSubmission = async (e: React.FormEvent<HTMLFormElement>): Promise<void> => {
e.preventDefault();
setLoading(true);
Expand Down Expand Up @@ -64,12 +70,6 @@ function Create(): JSX.Element {
setFormValues({ [e.currentTarget.name]: e.currentTarget.value })
}

useEffect(() => {
if (user) {
setAuthor(user.name)
}
}, [user])

return (
<div>
<div className={"col-md-12 form-wrapper"}>
Expand Down
18 changes: 9 additions & 9 deletions blog-frontend/src/components/post/Edit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,15 @@ function Edit(): JSX.Element {
const [submitSuccess, setSubmitSuccess] = useState<boolean>(false)
const [loading, setLoading] = useState(false);

useEffect(() => {
const fetchData = async (): Promise<void> => {
const response = await fetch(`${process.env.REACT_APP_SERVER_BASE_URL}/blog/post/${postId}`);
const json = await response.json();
setPost(json)
}
fetchData();
}, [postId]);

const handleFormSubmission = async (e: React.FormEvent<HTMLFormElement>): Promise<void> => {
e.preventDefault();
setLoading(true);
Expand Down Expand Up @@ -58,15 +67,6 @@ function Edit(): JSX.Element {
setFormValues({ [e.currentTarget.id]: e.currentTarget.value })
}

useEffect(() => {
const fetchData = async (): Promise<void> => {
const response = await fetch(`${process.env.REACT_APP_SERVER_BASE_URL}/blog/post/${postId}`);
const json = await response.json();
setPost(json)
}
fetchData();
}, [postId]);

return (
<div className={'page-wrapper'}>
{post &&
Expand Down
4 changes: 2 additions & 2 deletions blog-frontend/src/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ code {
}


/* .App {
.App {
text-align: center;
}

Expand Down Expand Up @@ -44,7 +44,7 @@ code {
@keyframes App-logo-spin {
from { transform: rotate(0deg); }
to { transform: rotate(360deg); }
} */
}



Expand Down

0 comments on commit 3b2e474

Please sign in to comment.