-
Notifications
You must be signed in to change notification settings - Fork 1
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
#514 Implement voting on Community note #516
Merged
Merged
Changes from 3 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
956efd4
Feature: New Voting System
keenlim 3597ac1
Merge branch 'feat/checkmate-v2' into feat/checkmate-v2-keen
keenlim 27f08fc
implement voting results
keenlim 294165e
Merge branch 'feat/checkmate-v2' into feat/checkmate-v2-keen
keenlim b376ea6
Links section and minor changes
keenlim 5c126bf
sending of correction note to users
keenlim 906572e
Minor changes
keenlim 2a7ceb0
Minor changes
keenlim 5125300
key corrections implemented
bwsarge 4d3bdb8
CommunityNote Correction Function
keenlim 6664482
updated handling of correction
bwsarge abce963
Merge branch 'feat/checkmate-v2' into feat/checkmate-v2-keen
bwsarge d6405eb
updated handling
bwsarge File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
import React, {useState} from "react"; | ||
import {Card, CardBody, Typography, Button} from "@material-tailwind/react"; | ||
import { UserIcon } from "@heroicons/react/24/solid"; | ||
|
||
interface PropType { | ||
en: string; | ||
cn: string; | ||
links: string[]; | ||
downvoted: boolean; | ||
} | ||
|
||
// Helper function to detect URLs and split the text | ||
const splitTextByUrls = (text: string) => { | ||
// This regex will match URLs | ||
const urlRegex = /(https?:\/\/[^\s]+)/g; | ||
let match; | ||
let lastIndex = 0; | ||
const parts = []; | ||
|
||
// Find al matches and their indices | ||
while ((match = urlRegex.exec(text)) !== null) { | ||
const url = match[0]; | ||
const index = match.index; | ||
|
||
// Push text before URL | ||
if (index > lastIndex) { | ||
parts.push({ text: text.substring(lastIndex, index), isUrl: false}); | ||
} | ||
|
||
// Push URL | ||
parts.push({ text: url, isUrl: true}); | ||
|
||
// Update lastIndex to end of current URL | ||
lastIndex = index + url.length; | ||
} | ||
|
||
// Push remaining text after last URL | ||
if (lastIndex < text.length) { | ||
parts.push({ text: text.substring(lastIndex), isUrl: false}); | ||
} | ||
|
||
return parts; | ||
} | ||
|
||
export default function CommunityCard(prop: PropType){ | ||
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. Can change the "CommunityCard" name to "CommunityNoteCard"? Same for categories etc. I'm always very concerned about getting the nomenclature meaningful so ppl can easily understand the code |
||
const [isExpanded, setIsExpanded] = useState(false); | ||
const lengthBeforeTruncation = 300; | ||
const { en, cn, links, downvoted } = prop; | ||
|
||
const toggleExpansion = () => { | ||
setIsExpanded(!isExpanded); | ||
}; | ||
|
||
let displayText = en ?? ""; | ||
|
||
const shouldTruncate = displayText.length > lengthBeforeTruncation; | ||
const textToShow = | ||
isExpanded || !shouldTruncate | ||
? displayText | ||
: displayText.slice(0, lengthBeforeTruncation) + "..."; | ||
|
||
// Split text by URLs | ||
const textParts = splitTextByUrls(textToShow) | ||
|
||
return ( | ||
<Card className="bg-blue-100 overflow-y-auto overflow-x-hidden max-w-md w-full h-full max-h-full p-3 mb-2"> | ||
<CardBody className="-m-3"> | ||
<Typography className="flex items-center mb-2"> | ||
<UserIcon className="h-6 w-6 text-[#ff8932] mr-2 flex-shrink-0"/> | ||
<p className="font-semibold leading-none">Community Note:</p> | ||
</Typography> | ||
|
||
<Typography className="w-full"> | ||
{textParts.map((part, index) => { | ||
// Split the text part by new lines | ||
const lines = part.text.split("\n"); | ||
return ( | ||
<React.Fragment key={index}> | ||
{lines.map((line, lineIndex) => ( | ||
<React.Fragment key={lineIndex}> | ||
{part.isUrl ? ( | ||
<a | ||
href={line} | ||
target="_blank" | ||
rel="noopener noreferrer" | ||
className="text-blue-500 hover:underline" | ||
> | ||
{line} | ||
</a> | ||
) : ( | ||
<span>{line}</span> | ||
)} | ||
{lineIndex < lines.length - 1 && <br />} | ||
</React.Fragment> | ||
))} | ||
</React.Fragment> | ||
); | ||
})} | ||
</Typography> | ||
{shouldTruncate && ( | ||
<Button | ||
onClick={toggleExpansion} | ||
variant="text" | ||
className="p-0 text-primary-color3" | ||
size="sm" | ||
> | ||
{isExpanded ? "Show Less" : "Read More"} | ||
</Button> | ||
)} | ||
</CardBody> | ||
</Card> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
import { useState } from "react"; | ||
import { TrophyIcon } from "@heroicons/react/20/solid"; | ||
import { CheckBadgeIcon } from "@heroicons/react/24/solid"; | ||
import { XCircleIcon } from "@heroicons/react/24/outline"; | ||
import { Button } from "@material-tailwind/react" | ||
import { ForwardIcon } from "@heroicons/react/24/solid"; | ||
|
||
interface PropType { | ||
messageId: string | null; | ||
voteRequestId: string | null; | ||
currentCommunityCategory: string | null; | ||
onNextStep: (value: number) => void; | ||
onSelectCommunityCategory: (communityCategory: string | null) => void; | ||
} | ||
|
||
const CATEGORIES = [ | ||
{ | ||
name: "great", | ||
icon: <TrophyIcon className = "h-7 w-7" />, | ||
display: "Great", | ||
description: "Good response, can't do any better", | ||
}, | ||
{ | ||
name: "acceptable", | ||
icon: <CheckBadgeIcon className = "h-7 w-7" />, | ||
display: "Acceptable", | ||
description: "Acceptable response, but can be improved" | ||
}, | ||
{ | ||
name: "unacceptable", | ||
icon: <XCircleIcon className="h-7 w-7" />, | ||
display: "Unacceptable", | ||
description: "Unacceptable response" | ||
} | ||
] | ||
|
||
|
||
export default function CommunityCategories(Prop: PropType) { | ||
const currentCategory = Prop.currentCommunityCategory | ||
const messageId = Prop.messageId; | ||
const voteRequestId = Prop.voteRequestId; | ||
const [selectedCategory, setSelectedCategory] = useState<string | null>(currentCategory); | ||
const [communityCategory, setCommunityCategory] = useState<string | null>(currentCategory); | ||
|
||
const handleCommunityCategoryChange = (category: string) => { | ||
switch(category) { | ||
default: | ||
setCommunityCategory(category); | ||
Prop.onSelectCommunityCategory(category); | ||
break; | ||
} | ||
} | ||
|
||
const handleSelection = (categoryName: string) => { | ||
setSelectedCategory(categoryName); | ||
handleCommunityCategoryChange(categoryName); | ||
} | ||
|
||
const handleNextStep = (value: number) => { | ||
Prop.onNextStep(value) | ||
} | ||
|
||
return ( | ||
<div className="grid grid-flow-row gap-y-4 items-center"> | ||
{CATEGORIES.map((cat, index) => ( | ||
<> | ||
<Button | ||
className={`flex flex-row items-center justify-start gap-2 max-w-md space-x-3 text-sm | ||
${ | ||
selectedCategory === cat.name | ||
? "bg-primary-color3" | ||
: "bg-primary-color"}`} | ||
key={index} | ||
onClick={() => handleSelection(cat.name)} | ||
> | ||
{cat.icon} | ||
{cat.display} | ||
</Button> | ||
</> | ||
))} | ||
|
||
{communityCategory ? ( | ||
<Button fullWidth className="flex items-center justify-center gap-3 bg-green-400" size="sm" | ||
onClick = {() => handleNextStep(2)} | ||
> | ||
Move to next step | ||
<ForwardIcon className="h-5 w-5"/> | ||
</Button> | ||
) : null} | ||
</div> | ||
) | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Can we have a section to show the links too? These will be the links identified by the GenAI system. Will help the checkers review the links to make sure the note is congruent with the link