feat/revert like (#429)

This commit is contained in:
Nya Candy
2023-04-26 15:01:39 +01:00
committed by GitHub
parent d078d8986d
commit de213d2fa9
6 changed files with 64 additions and 7 deletions
+42 -2
View File
@@ -51,6 +51,8 @@ export const Reactions: React.FC<{
})
const { data: likeCount = 0 } = useGetLikeCounts({ pageId })
const [isUnlikeOpen, setIsUnlikeOpen] = useState(false)
const like = () => {
if (pageId) {
if (likeStatus.isLiked) {
@@ -61,9 +63,18 @@ export const Reactions: React.FC<{
}
}
const unlike = () => {
if (pageId) {
setIsUnlikeOpen(false)
if (likeStatus.isLiked) {
toggleLikePage.mutate({ ...parsePageId(pageId), action: "unlink" })
} // else do nothing
}
}
useEffect(() => {
if (toggleLikePage.isSuccess) {
if (likeRef.current?.getBoundingClientRect()) {
if (likeRef.current?.getBoundingClientRect() && likeStatus.isLiked) {
confetti({
particleCount: 150,
spread: 70,
@@ -347,10 +358,39 @@ export const Reactions: React.FC<{
</UniLink>
</Trans>
</div>
<div className="h-16 border-t flex items-center px-5">
<div className="border-t flex flex-col md:flex-row gap-4 items-center px-5 py-4">
<Button isBlock onClick={() => setIsLikeOpen(false)}>
{t("Got it, thanks!")}
</Button>
<Button
variant="secondary"
isBlock
onClick={() => {
setIsUnlikeOpen(true)
setIsLikeOpen(false)
}}
>
{t("Revert")}
</Button>
</div>
</Modal>
<Modal
open={isUnlikeOpen}
setOpen={setIsUnlikeOpen}
title={t("Confirm to revert")}
>
<div className="p-5">
<Trans i18nKey="like revert">
Do you really want to revert this like action?
</Trans>
</div>
<div className="border-t flex flex-col md:flex-row gap-4 items-center px-5 py-4">
<Button isBlock onClick={() => setIsUnlikeOpen(false)}>
{t("Cancel")}
</Button>
<Button variant="secondary" isBlock onClick={() => unlike()}>
{t("Confirm")}
</Button>
</div>
</Modal>
<Modal
+6 -4
View File
@@ -4,14 +4,16 @@ import { IS_PROD } from "~/lib/constants"
import { DISCORD_LINK } from "~/lib/env"
// HTTPWhiteListPaths: White list of path for plain http request, no HTTPS redirect
const HTTPWhitelistPaths = [
"/api/healthcheck",
]
const HTTPWhitelistPaths = ["/api/healthcheck"]
export default async function middleware(req: NextRequest) {
const { pathname } = req.nextUrl
if (IS_PROD && req.headers.get("x-forwarded-proto") !== "https" && !HTTPWhitelistPaths.includes(req.nextUrl.pathname)) {
if (
IS_PROD &&
req.headers.get("x-forwarded-proto") !== "https" &&
!HTTPWhitelistPaths.includes(req.nextUrl.pathname)
) {
let cfHttps = false
try {
if (