Skip to content

Commit

Permalink
[feat]: add emoji picker
Browse files Browse the repository at this point in the history
  • Loading branch information
SiddharthaMishra-dev committed Mar 8, 2024
1 parent 5236457 commit 432db4e
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 10 deletions.
2 changes: 1 addition & 1 deletion components/CommentButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const CommentButton = ({ blog, handleComment }: CommentButtonProps) => {

return (
<>
<div className="flex items-center justify-center hover:text-blue-500 transition cursor-pointer">
<div className="flex items-center justify-center hover:text-blue-500 transition cursor-pointer text-gray-400">
<FaRegComment onClick={onOpen} />
<span className="ml-2">{blogsLength.length > 0 ? blogsLength.length : ""}</span>
</div>
Expand Down
10 changes: 7 additions & 3 deletions components/LikeButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ const LikeButton = ({ blog, handleLike }: LikeButtonProps) => {
if (!isLiked) {
setIsLiked(true);
setOptimisticLike(1);

handleLike(blog);
}
};
Expand All @@ -38,13 +39,16 @@ const LikeButton = ({ blog, handleLike }: LikeButtonProps) => {
const Icon = isLiked ? AiFillHeart : AiOutlineHeart;

return (
<div className="group flex items-center hover:text-red-600 transition cursor-pointer">
<div className="group flex items-center hover:text-red-500 transition cursor-pointer text-gray-400">
<Icon
onClick={likeFn}
size={20}
color={isLiked ? "red" : "white"}
// color={isLiked ? "red" : "white"}
className={`hover:text-red-500 ${isLiked ? "text-red-500" : ""}`}
/>
<span className="ml-2">{blog?.likes.length + optimisticLike}</span>
<span className="ml-2 text-sm">
{blog?.likes.length + optimisticLike !== 0 ? blog?.likes.length + optimisticLike : null}
</span>
</div>
);
};
Expand Down
36 changes: 33 additions & 3 deletions components/PostModal.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"use client";

import React from "react";
import React, { useRef } from "react";
import { useState } from "react";
import { useSession } from "next-auth/react";
import {
Expand All @@ -16,6 +16,8 @@ import {
import { CircularProgress } from "@nextui-org/progress";
import toast from "react-hot-toast";
import { PostBlog } from "@/actions/actions";
import { Smile } from "lucide-react";
import EmojiPicker from "emoji-picker-react";

const InitialState = {
title: "",
Expand All @@ -32,9 +34,13 @@ interface PostModalProps {
}

export default function PostModal({ isOpen, onOpenChange, setfunction }: PostModalProps) {
const [isEmojiOpen, setIsEmojiOpen] = useState(false);
const [formData, setFormData] = useState(InitialState);
const [posting, setPosting] = useState(false);
const { data: session } = useSession();

const contentRef = useRef<HTMLTextAreaElement>(null);

const handleChange = (e: any) => {
const { name, value } = e.target;
setFormData((prevValue) => ({ ...prevValue, [name]: value }));
Expand All @@ -55,6 +61,13 @@ export default function PostModal({ isOpen, onOpenChange, setfunction }: PostMod
}
};

const handleEmojiClick = (emoji: string) => {
setFormData((prevFormData) => ({
...prevFormData,
content: prevFormData.content + emoji,
}));
};

const resetForm = () => {
setFormData(InitialState);
};
Expand All @@ -75,7 +88,7 @@ export default function PostModal({ isOpen, onOpenChange, setfunction }: PostMod
Jot down your thought
</h2>
</ModalHeader>
<ModalBody>
<ModalBody className="relative">
<div className="w-full flex flex-col justify-center items-center gap-y-4">
<div className="p-1 flex flex-col w-full gap-y-2 ">
<Input
Expand All @@ -99,6 +112,7 @@ export default function PostModal({ isOpen, onOpenChange, setfunction }: PostMod
</div>
<div className="p-1 flex flex-col w-full gap-y-2">
<Textarea
ref={contentRef}
size="lg"
minRows={10}
name="content"
Expand All @@ -110,7 +124,23 @@ export default function PostModal({ isOpen, onOpenChange, setfunction }: PostMod
</div>
</div>
</ModalBody>
<ModalFooter>
<div className={`${isEmojiOpen ? "block" : "hidden"} absolute bottom-20 left-10`}>
<EmojiPicker
open={true}
onEmojiClick={({ emoji }) => handleEmojiClick(emoji)}
/>
</div>
<ModalFooter className="items-center">
<div className="me-auto w-full box-border ">
<Smile
className="h-15 w-15 "
onClick={() => {
setIsEmojiOpen((prev) => {
return !prev;
});
}}
/>
</div>
<Button
color="danger"
variant="light"
Expand Down
6 changes: 3 additions & 3 deletions lib/utils.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { type ClassValue, clsx } from "clsx"
import { twMerge } from "tailwind-merge"
import { type ClassValue, clsx } from "clsx";
import { twMerge } from "tailwind-merge";

export function cn(...inputs: ClassValue[]) {
return twMerge(clsx(inputs))
return twMerge(clsx(inputs));
}
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"autoprefixer": "10.4.14",
"class-variance-authority": "^0.7.0",
"clsx": "^2.1.0",
"emoji-picker-react": "^4.8.0",
"eslint": "8.46.0",
"eslint-config-next": "13.4.13",
"framer-motion": "^10.15.2",
Expand Down
17 changes: 17 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 432db4e

Please sign in to comment.