-
-
Notifications
You must be signed in to change notification settings - Fork 69
feat: add upvote functionality for learning paths #193
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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!'); | ||
|
Comment on lines
+20
to
+21
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The duplicate guard checks only the incoming Useful? React with 👍 / 👎. |
||
| return; | ||
| } | ||
| try { | ||
| await upvote({ variables: { pathId, userId } }); | ||
| message.success('Upvoted successfully!'); | ||
| } catch (err) { | ||
| message.error('Failed to upvote'); | ||
| } | ||
| }; | ||
|
|
||
| return ( | ||
| <Button icon={<LikeOutlined />} onClick={handleUpvote}> | ||
| {votedBy.length} Upvotes | ||
| </Button> | ||
| ); | ||
| }; | ||
|
|
||
| export default UpvoteButton; | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This mutation uses
update_learning_path_by_pkwith_appendonvoted_by, but the rest of this codebase consistently targetsLearning_Pathsplus a separatevotesrelation (for example,src/components/EditPath/editPath.jsmutatesupdate_Learning_Pathsandsrc/pages/search.jsreadsvotes/votes_aggregate), so this operation does not match the existing schema shape and upvote requests will fail at runtime when invoked.Useful? React with 👍 / 👎.