Skip to content

Commit

Permalink
format code
Browse files Browse the repository at this point in the history
  • Loading branch information
manikandanraji committed Jul 7, 2020
1 parent 404f595 commit 6ec5017
Show file tree
Hide file tree
Showing 16 changed files with 751 additions and 748 deletions.
2 changes: 1 addition & 1 deletion src/components/DeletePost.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const DeletePost = ({ postId, closeModal, goToHome }) => {

setFeed(feed.filter((post) => post._id !== postId));
toast.success("Your post has been deleted successfully");
client(`/posts/${postId}`, { method: 'DELETE' })
client(`/posts/${postId}`, { method: "DELETE" });
};

return (
Expand Down
4 changes: 2 additions & 2 deletions src/components/Follow.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ const Follow = ({ nobtn, isFollowing, incFollowers, decFollowers, userId }) => {
if (decFollowers) {
decFollowers();
}
client(`/users/${userId}/unfollow`)
client(`/users/${userId}/unfollow`);
} else {
setFollowingState(true);
if (incFollowers) {
incFollowers();
}
client(`/users/${userId}/follow`)
client(`/users/${userId}/follow`);
}
};

Expand Down
4 changes: 2 additions & 2 deletions src/components/LikePost.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ const LikePost = ({ isLiked, postId, incLikes, decLikes }) => {
if (likedState) {
setLiked(false);
decLikes();
client(`/posts/${postId}/toggleLike`)
client(`/posts/${postId}/toggleLike`);
} else {
setLiked(true);
incLikes();
client(`/posts/${postId}/toggleLike`)
client(`/posts/${postId}/toggleLike`);
}
};

Expand Down
190 changes: 95 additions & 95 deletions src/components/Login.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,104 +7,104 @@ import { UserContext } from "../context/UserContext";
import logo from "../assets/logo.png";

export const FormWrapper = styled.div`
background-color: ${props => props.theme.white};
padding: 1rem;
width: 350px;
border: 1px solid ${props => props.theme.borderColor};
margin: 6rem auto;
text-align: center;
padding: 2rem 0;
img {
margin-bottom: 1.5rem;
}
input {
display: block;
margin: 0 auto;
margin-bottom: 1rem;
padding: 0.5rem 1.2rem;
background: ${props => props.theme.white};
border: 1px solid ${props => props.theme.borderColor};
font-family: "Fira Sans", sans-serif;
font-size: 1rem;
border-radius: 4px;
width: 85%;
}
input[type="submit"] {
background-color: ${props => props.theme.blue};
color: ${props => props.theme.white};
border: 1px solid ${props => props.theme.blue};
cursor: pointer;
}
p {
margin-top: 2rem;
}
span {
color: ${props => props.theme.blue};
cursor: pointer;
}
background-color: ${(props) => props.theme.white};
padding: 1rem;
width: 350px;
border: 1px solid ${(props) => props.theme.borderColor};
margin: 6rem auto;
text-align: center;
padding: 2rem 0;
img {
margin-bottom: 1.5rem;
}
input {
display: block;
margin: 0 auto;
margin-bottom: 1rem;
padding: 0.5rem 1.2rem;
background: ${(props) => props.theme.white};
border: 1px solid ${(props) => props.theme.borderColor};
font-family: "Fira Sans", sans-serif;
font-size: 1rem;
border-radius: 4px;
width: 85%;
}
input[type="submit"] {
background-color: ${(props) => props.theme.blue};
color: ${(props) => props.theme.white};
border: 1px solid ${(props) => props.theme.blue};
cursor: pointer;
}
p {
margin-top: 2rem;
}
span {
color: ${(props) => props.theme.blue};
cursor: pointer;
}
`;

const Login = ({ signup }) => {
const { setUser } = useContext(UserContext);
const email = useInput("");
const password = useInput("");

const handleLogin = async e => {
e.preventDefault();

if (!email.value || !password.value) {
return toast.error("Please fill in both the fields");
}

const body = { email: email.value, password: password.value };

try {
const { token } = await client("/auth/login", { body });
localStorage.setItem("token", token);
} catch (err) {
return toast.error(err.message);
}

const user = await client("/auth/me");
localStorage.setItem("user", JSON.stringify(user.data));
setUser(user.data);
toast.success("Login successful");

email.setValue("");
password.setValue("");
};

return (
<FormWrapper onSubmit={handleLogin}>
<img className="logo" src={logo} alt="logo" />
<form>
<input
type="email"
placeholder="[email protected]"
value={email.value}
onChange={email.onChange}
/>
<input
type="password"
placeholder="mysuperpassword"
value={password.value}
onChange={password.onChange}
/>
<input type="submit" value="Log In" className="login-btn" />
</form>

<div>
<p>
Don't have an account? <span onClick={signup}>Sign up</span>
</p>
</div>
</FormWrapper>
);
const { setUser } = useContext(UserContext);
const email = useInput("");
const password = useInput("");

const handleLogin = async (e) => {
e.preventDefault();

if (!email.value || !password.value) {
return toast.error("Please fill in both the fields");
}

const body = { email: email.value, password: password.value };

try {
const { token } = await client("/auth/login", { body });
localStorage.setItem("token", token);
} catch (err) {
return toast.error(err.message);
}

const user = await client("/auth/me");
localStorage.setItem("user", JSON.stringify(user.data));
setUser(user.data);
toast.success("Login successful");

email.setValue("");
password.setValue("");
};

return (
<FormWrapper onSubmit={handleLogin}>
<img className="logo" src={logo} alt="logo" />
<form>
<input
type="email"
placeholder="[email protected]"
value={email.value}
onChange={email.onChange}
/>
<input
type="password"
placeholder="mysuperpassword"
value={password.value}
onChange={password.onChange}
/>
<input type="submit" value="Log In" className="login-btn" />
</form>

<div>
<p>
Don't have an account? <span onClick={signup}>Sign up</span>
</p>
</div>
</FormWrapper>
);
};

export default Login;
Loading

0 comments on commit 6ec5017

Please sign in to comment.