diff --git a/frontend/src/screens/Results.tsx b/frontend/src/screens/Results.tsx index 5c630c9..2a12742 100644 --- a/frontend/src/screens/Results.tsx +++ b/frontend/src/screens/Results.tsx @@ -61,6 +61,8 @@ const Results: React.FC = () => { Downvotes Original Author Download + Upvote + Downvote @@ -74,6 +76,8 @@ const Results: React.FC = () => { {file.downvotes.length} {file.original_author.username} + + ))} @@ -130,4 +134,47 @@ function DownloadButton({ file }: { file: File }) { } ); +} + +function UpvoteButton({ file, onUpdate }: { file: File, onUpdate: () => void }) { + const [upvoted, setUpvoted] = useState(false); + + const handleUpvote = async () => { + try { + await fetch(`http://localhost:8000/api/files/${file.id}/upvote/`, { + method: 'POST', + headers: getAuthHeaders(), + }); + setUpvoted(true); + window.location.reload(); + onUpdate(); + } catch (error) { + console.error('Error:', error); + } + }; + return ( + + ); +} + +function DownvoteButton({ file, onUpdate }: { file: File, onUpdate: () => void }) { + const [downvoted, setDownvoted] = useState(false); + + const handleDownvote = async () => { + try { + await fetch(`http://localhost:8000/api/files/${file.id}/downvote/`, { + method: 'POST', + headers: getAuthHeaders(), + }); + setDownvoted(true); + window.location.reload(); + onUpdate(); + } catch (error) { + console.error('Error:', error); + } + }; + + return ( + + ); } \ No newline at end of file