Feed Component
Allowing the user to view a post in the feed
Last updated
const photoURL = model.data['photoURL']const highscore: number = parseInt(model.data['highscore'])let urls = model.data['urls'] ? JSON.parse(model.data['urls']) : [];export const ImageFeedComponent = ({ model }: FeedComponentProps) => {
let photoURL = model.data['photoURL']
return (
<div style={{ display: 'block', width: '100%' }}>
<img src={photoURL} style={{ width: '100%', height: 'auto' }} />
</div>
);
}const handleVote = async (optionKey: string) => {
if (hasVoted) return; // Prevent multiple votes
const updatedVotes = { ...votes, [optionKey]: votes[optionKey] + 1 };
setVotes(updatedVotes); // Optimistic update
setTotalVotes(totalVotes + 1);
setSelectedOption(optionKey);
setHasVoted(true);
try {
// Prepare the updated data for the backend
const updatedData = { ...model.data };
updatedData[`${optionKey}Votes`] = updatedVotes[optionKey].toString();
// Call the update function to save the new vote counts
if (update) {
await update(updatedData);
}
} catch (error) {
console.error('Failed to update votes:', error);
}
};"data": {
"question": "a or b",
"option1": "a",
"option1Votes": “0”,
"option2": "b",
"option2Votes": "0"
},"data": {
"question": "a or b",
"option1": "a",
"option1Votes": “1”,
"option2": "b",
"option2Votes": "0"
},