diff --git a/app/javascript/components/Reactions/Reactions.jsx b/app/javascript/components/Reactions/Reactions.jsx new file mode 100644 index 00000000000..f31a744b5d1 --- /dev/null +++ b/app/javascript/components/Reactions/Reactions.jsx @@ -0,0 +1,117 @@ +import React, { useState, useCallback } from 'react' + +const Reactions = ({ + // url, + reactionable, + currentUser, + // reactionableId, + availableEmojis +}) => { + const [dropdown, setDropdown] = useState(false) + const displayedEmojis = reactionable.reaction_count.filter((el) => el.count !== 0); + + const createReaction = async (_kind) => {} + + const destroyReaction = async (_kind) => {} + + const footerReaction = (kind) => { + isReacted(kind) ? destroyReaction(kind) : createReaction(kind) + } + + const dropdownToggle = useCallback(() => { + setDropdown((dropdown) => !dropdown) + }, []) + + const dropdownReaction = useCallback((kind) => { + footerReaction(kind); + dropdownToggle() + }, []) + + const isReacted = (kind) => { + const id = reactionable.reaction_count.findIndex((element) => element.kind === kind); + const reaction = reactionable.reaction_count[id].login_names.filter( + (el) => el === currentUser.login_name + ); + return reaction.length !== 0 + } + + return ( +