Skip to content

Commit

Permalink
chore: minor tweaks to allow upvoting better
Browse files Browse the repository at this point in the history
  • Loading branch information
RobertBrunhage committed Dec 5, 2024
1 parent 6aa7be9 commit da834eb
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 13 deletions.
6 changes: 5 additions & 1 deletion .github/workflows/update-votes.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ jobs:
repository(owner: $owner, name: $repo) {
discussions(first: 50, after: $cursor) {
nodes {
id
title
reactions(content: THUMBS_UP) {
totalCount
Expand Down Expand Up @@ -79,7 +80,10 @@ jobs:
for (const discussion of allDiscussions) {
if (discussion.title.startsWith('Vote: ')) {
const appName = discussion.title.replace('Vote: ', '').split(' by ')[0];
votes[appName] = discussion.reactions.totalCount;
votes[appName] = {
id: discussion.id,
votes: discussion.reactions.totalCount
};
}
}
Expand Down
5 changes: 4 additions & 1 deletion src/data/votes.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
{
"Today": 1
"Today": {
"id": "1",
"votes": 1
}
}
24 changes: 14 additions & 10 deletions src/pages/index.astro
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ const votes: VoteData = getVotes();
// Sort apps by vote count (descending)
const sortedApps = allApps.sort((a, b) => {
const votesA = votes[a.data.name] || 0;
const votesB = votes[b.data.name] || 0;
const votesA = votes[a.data.name]?.votes || 0;
const votesB = votes[b.data.name]?.votes || 0;
return votesB - votesA;
});
Expand Down Expand Up @@ -81,7 +81,18 @@ const sortedApps = allApps.sort((a, b) => {
</div>

<!-- App Info -->
<h2 class="text-xl font-bold mb-2 text-center">{app.data.name}</h2>
<div class="flex flex-col items-center gap-3 mb-4">
<h2 class="text-xl font-bold text-center">{app.data.name}</h2>
<a
href={`https://github.com/hungrimind/flutter-of-the-year/discussions/${votes[app.data.name]?.id}`}
target="_blank"
rel="noopener noreferrer"
class="flex items-center space-x-2 bg-white/10 hover:bg-white/20 px-3 py-1.5 rounded-full transition-colors"
>
<span class="text-blue-300">👍</span>
<span class="text-sm font-medium">{votes[app.data.name]?.votes || 0}</span>
</a>
</div>
<p class="text-blue-200 text-sm mb-2 text-center">by {app.data.author}</p>
<p class="text-gray-300 text-sm mb-6 text-center">{app.data.description}</p>

Expand All @@ -98,13 +109,6 @@ const sortedApps = allApps.sort((a, b) => {
</a>
))}
</div>
<div class="flex justify-between items-start mb-2">
<h3 class="text-xl font-bold">{app.data.name}</h3>
<div class="flex items-center space-x-1 bg-white/10 px-2 py-1 rounded-full">
<span class="text-blue-300">👍</span>
<span class="text-sm font-medium">{votes[app.data.name] || 0}</span>
</div>
</div>
</div>
</div>
))}
Expand Down
5 changes: 4 additions & 1 deletion src/utils/votes.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
export interface VoteData {
[appName: string]: number;
[appName: string]: {
id: string;
votes: number;
};
}

export function getVotes(): VoteData {
Expand Down

0 comments on commit da834eb

Please sign in to comment.