-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c25c96a
commit 0754285
Showing
15 changed files
with
890 additions
and
304 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,62 @@ | ||
import React, { useState } from "react" | ||
import "../styles/navbar.css" | ||
import { Navbar as BsNavbar, Nav, Form, Button } from "react-bootstrap" | ||
import { NavLink, useNavigate } from "react-router-dom" | ||
import React, { useState } from "react"; | ||
import "../styles/navbar.css"; | ||
import { Navbar as BsNavbar, Nav, Form, Button } from "react-bootstrap"; | ||
import { NavLink, useNavigate } from "react-router-dom"; | ||
|
||
function Navbar({ handleShow }) { | ||
const navigate = useNavigate() | ||
const navigate = useNavigate(); | ||
|
||
const [query, setQuery] = useState("") | ||
const [query, setQuery] = useState(""); | ||
|
||
const handleSubmit = (e) => { | ||
e.preventDefault() | ||
let type = window.location.href.split("/")[3] | ||
if (type != "memes" && type != "anime") type = "main" | ||
navigate(`${type !== "main" ? `/${type}` : ""}/search?q=${query}`) | ||
} | ||
e.preventDefault(); | ||
let type = window.location.href.split("/")[3]; | ||
if (type != "memes" && type != "anime") type = "main"; | ||
navigate(`${type !== "main" ? `/${type}` : ""}/search?q=${query}`); | ||
}; | ||
|
||
return ( | ||
<BsNavbar bg="light" sticky="top" expand="lg"> | ||
<BsNavbar.Brand as={NavLink} to="/">Menfess</BsNavbar.Brand> | ||
<BsNavbar.Toggle aria-controls="basic-navbar-nav" /> | ||
<BsNavbar | ||
bg="secondary" | ||
variant="secondary" | ||
className="text-light" | ||
sticky="top" | ||
expand="lg"> | ||
<BsNavbar.Brand as={NavLink} to="/" className="m-2 text-light"> | ||
Menfess | ||
</BsNavbar.Brand> | ||
<BsNavbar.Toggle | ||
aria-controls="basic-navbar-nav" | ||
className="m-2 text-light" | ||
/> | ||
<BsNavbar.Collapse id="basic-navbar-nav"> | ||
<Nav className="mr-auto"> | ||
<Nav.Link as={NavLink} to="/">Home</Nav.Link> | ||
<Nav.Link as={NavLink} to="/memes">Memes</Nav.Link> | ||
<Nav.Link as={NavLink} to="/anime">Anime</Nav.Link> | ||
<Nav.Link className="m-2 text-light" as={NavLink} to="/"> | ||
Home | ||
</Nav.Link> | ||
<Nav.Link className="m-2 text-light" as={NavLink} to="/memes"> | ||
Memes | ||
</Nav.Link> | ||
<Nav.Link className="m-2 text-light" as={NavLink} to="/anime"> | ||
Anime | ||
</Nav.Link> | ||
</Nav> | ||
<Form inline="true" onSubmit={handleSubmit}> | ||
<Form.Control required type="text" onChange={(e) => setQuery(e.target.value)} value={query} placeholder="Search" className="mr-sm-2" /> | ||
<Button variant="outline-success" type="submit">Search</Button> | ||
<Form inline="true" onSubmit={handleSubmit} className="m-1 text-light"> | ||
<Form.Control | ||
required | ||
type="text" | ||
onChange={(e) => setQuery(e.target.value)} | ||
value={query} | ||
placeholder="Search" | ||
className="mr-sm-2 text-light" | ||
/> | ||
</Form> | ||
<Button onClick={handleShow}>New Post</Button> | ||
<Button className="m-2 text-light" onClick={handleShow}> | ||
New Post | ||
</Button> | ||
</BsNavbar.Collapse> | ||
</BsNavbar> | ||
) | ||
); | ||
} | ||
|
||
export default Navbar | ||
export default Navbar; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,53 +1,89 @@ | ||
import React from "react" | ||
import { Link } from "react-router-dom" | ||
import { Button, Card, Col, Row } from "react-bootstrap" | ||
import axios from "axios" | ||
import React, { useCallback } from "react"; | ||
import { Link } from "react-router-dom"; | ||
import { Button, Card, Col, Row } from "react-bootstrap"; | ||
import axios from "axios"; | ||
|
||
function formatLikeCount(count) { | ||
if (count >= 1000000) { | ||
return (count / 1000000).toFixed(1) + "M"; | ||
} else if (count >= 1000) { | ||
return (count / 1000).toFixed(1) + "K"; | ||
} else { | ||
return count; | ||
} | ||
} | ||
|
||
function Post({ post, type }) { | ||
const handleShare = () => { | ||
const copyText = `${process.env.REACT_APP_BASE_URL}${type != "main" ? `${type}/` : ""}post/${post.noteId}` | ||
const handleShare = useCallback(() => { | ||
const copyText = `${process.env.REACT_APP_BASE_URL}${ | ||
type !== "main" ? `${type}/` : "" | ||
}post/${post.noteId}`; | ||
const shareData = { | ||
title: "Menfess!!", | ||
text: `Sebuah Post dari ${post.noteName}`, | ||
url: copyText, | ||
} | ||
}; | ||
|
||
if (navigator.canShare(shareData)) navigator.share(shareData) | ||
else { | ||
navigator.clipboard.writeText(copyText) | ||
alert("Udah di copy nih, silahkan share ke temen kamu ya:3 (itupun kalo klean punya temen)") | ||
if (navigator.canShare && navigator.canShare(shareData)) { | ||
navigator.share(shareData); | ||
} else { | ||
navigator.clipboard.writeText(copyText); | ||
alert( | ||
"Udah di copy nih, silahkan share ke temen kamu ya:3 (itupun kalo klean punya temen)" | ||
); | ||
} | ||
} | ||
}, [post, type]); | ||
|
||
return ( | ||
<Card> | ||
<Card.Body> | ||
<Card.Title>{post.noteName}</Card.Title> | ||
<Card.Text>{post.noteContent}</Card.Text> | ||
</Card.Body> | ||
<Card.Img | ||
variant="bottom" | ||
src={`${process.env.REACT_APP_IMAGEKIT_URL_ENDPOINT}image${type != "main" ? type : ""}-${post.noteId}.jpg`} | ||
onError={(e) => e.target.remove()} | ||
/> | ||
<Card.Footer> | ||
<Row> | ||
<Col> | ||
<Button onClick={() => axios.post(`/api/${type}/like/${post.noteId}`)}> | ||
{`${post.like} `}Like | ||
</Button> | ||
</Col> | ||
<Col> | ||
<Button as={Link} to={`/${type != "main" ? `${type}/` : ""}post/${post.noteId}`}> | ||
{`${post.comment.length} `}Comment | ||
</Button> | ||
</Col> | ||
<Col> | ||
<Button onClick={handleShare}>Share</Button> | ||
</Col> | ||
</Row> | ||
</Card.Footer> | ||
</Card> | ||
) | ||
<div className="d-flex justify-content-center align-items-center"> | ||
<Card | ||
className="mb-3 m-2 text-center bg-secondary text-white p-1" // Set background color to gray and text color to white | ||
style={{ width: "500px", objectFit: "contain" }}> | ||
<Card.Body> | ||
<Card.Title>{post.noteName}</Card.Title> | ||
<Card.Text>{post.noteContent}</Card.Text> | ||
</Card.Body> | ||
<Card.Img | ||
variant="bottom" | ||
src={`https://ik.imagekit.io/menfessdoma/image${ | ||
type !== "main" ? type : "" | ||
}-${post.noteId}.jpg`} | ||
onError={(e) => e.target.remove()} | ||
alt={`Image for post ${post.noteName}`} | ||
className="img-fluid" | ||
style={{ | ||
maxHeight: "500px", | ||
maxWidth: "500px", | ||
objectFit: "contain", | ||
}} | ||
/> | ||
<Card.Footer> | ||
<Row className="justify-content-around align-items-center"> | ||
<Col xs="auto" sm="auto"> | ||
<Button | ||
variant="primary" | ||
onClick={() => axios.post(`/api/${type}/like/${post.noteId}`)}> | ||
♥ {`${formatLikeCount(post.like)} `} | ||
</Button> | ||
</Col> | ||
<Col xs="auto" sm="auto"> | ||
<Button | ||
variant="success" | ||
as={Link} | ||
to={`/${type !== "main" ? `${type}/` : ""}post/${post.noteId}`}> | ||
Komen | ||
</Button> | ||
</Col> | ||
<Col xs="auto" sm="auto"> | ||
<Button variant="info" onClick={handleShare}> | ||
Bagi | ||
</Button> | ||
</Col> | ||
</Row> | ||
</Card.Footer> | ||
</Card> | ||
</div> | ||
); | ||
} | ||
|
||
export default Post | ||
export default Post; |
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
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
Oops, something went wrong.