Skip to content

Commit

Permalink
feat(example): comment component for photoshoot
Browse files Browse the repository at this point in the history
(forgot to add in prev pr)
  • Loading branch information
dylandbl committed Jul 20, 2022
1 parent 5fe4931 commit 7d70487
Showing 1 changed file with 94 additions and 0 deletions.
94 changes: 94 additions & 0 deletions example/src/components/showcaseComponents/photoShoot/Comment.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
import { useState } from "react";
import QuickReactions from "react-quick-reactions";
import { commentEmojis } from "../../../utils/sampleData";
import { SmileSvg } from "../../svgs/SmileSvg";
import {
CommentWrapper,
CommentHeader,
UsernameSpan,
TimeStamp,
CommentBody,
CommentFooter,
PhotoShootEmojiButton,
ReactionsArray,
CountSpan,
} from "./PhotoShootStyles";

interface CommentProps {
timestamp: string;
timeDisplayValue: string;
username: string;
content: string;
reactionArray: {
content: string;
count: number;
thisUserContributed: boolean;
}[];
}
export const CustomComment = ({
timestamp,
timeDisplayValue,
username,
content,
reactionArray,
}: CommentProps) => {
const [visible, setVisible] = useState(false);
const [reactionArrayState, setReactionArrayState] = useState(reactionArray);

const handleClickReaction = (emojiElement?: Element) => {
setVisible(false);
const reactionArrayStateCopy = reactionArrayState;

const index = reactionArrayStateCopy.findIndex(
(item) => item.content === emojiElement?.textContent
);

reactionArrayStateCopy[index].count += 1;
reactionArrayStateCopy[index].thisUserContributed = true;
setReactionArrayState(reactionArrayStateCopy);
};

return (
<CommentWrapper>
<CommentHeader>
<UsernameSpan>{username}</UsernameSpan>
<TimeStamp title={timestamp}>{timeDisplayValue}</TimeStamp>
</CommentHeader>
<CommentBody>{content}</CommentBody>
<CommentFooter>
<QuickReactions
isVisible={visible}
onClose={() => setVisible(false)}
reactionsArray={commentEmojis}
onClickReaction={(item) => handleClickReaction(item)}
trigger={
<PhotoShootEmojiButton onClick={() => setVisible(true)}>
<SmileSvg />
</PhotoShootEmojiButton>
}
/>
<ReactionsArray>
{reactionArrayState.map(
(item) =>
item.count > 0 && (
<PhotoShootEmojiButton
className="emoji-button"
thisUserContributed={item.thisUserContributed}
>
{item.content}
{item.count > 1 ? (
<CountSpan thisUserContributed={item.thisUserContributed}>
x
{item.count > 1000
? Math.floor(item.count / 1000).toString() + "k"
: item.count}
</CountSpan>
) : null}
</PhotoShootEmojiButton>
)
)}
</ReactionsArray>
</CommentFooter>
</CommentWrapper>
);
};

0 comments on commit 7d70487

Please sign in to comment.