From c9efaab966779175d0a604ed79b6da1de5b29d54 Mon Sep 17 00:00:00 2001 From: Pangea 3 Date: Sun, 8 Mar 2026 18:28:08 +0000 Subject: [PATCH] fix: feat: add upvote functionality for learning paths (fixes #20) --- src/components/UpvoteButton.js | 39 ++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 src/components/UpvoteButton.js diff --git a/src/components/UpvoteButton.js b/src/components/UpvoteButton.js new file mode 100644 index 0000000..3d720bc --- /dev/null +++ b/src/components/UpvoteButton.js @@ -0,0 +1,39 @@ +import React from 'react'; +import { Button, message } from 'antd'; +import { LikeOutlined } from '@ant-design/icons'; +import { useMutation } from '@apollo/react-hooks'; +import gql from 'graphql-tag'; + +const UPVOTE_PATH = gql` + mutation UpvotePath($pathId: Int!, $userId: String!) { + update_learning_path_by_pk(pk_columns: {id: $pathId}, _append: {voted_by: [ $userId ]}) { + id + voted_by + } + } +`; + +const UpvoteButton = ({ pathId, userId, votedBy = [] }) => { + const [upvote] = useMutation(UPVOTE_PATH); + + const handleUpvote = async () => { + if (votedBy.includes(userId)) { + message.info('You have already upvoted this path!'); + return; + } + try { + await upvote({ variables: { pathId, userId } }); + message.success('Upvoted successfully!'); + } catch (err) { + message.error('Failed to upvote'); + } + }; + + return ( + + ); +}; + +export default UpvoteButton; \ No newline at end of file