feat: add leaderboard router, gamification backfill, and shared content creation helpers

Introduce a new `/leaderboard` endpoint ranking top 50 members by total stars, wire it into the app router and documentation. Implement `_backfill_gamification()` in `database.py` to compute XP/levels for existing accounts from prior posts, comments, votes, and follows. Extract `is_owner()`, `create_content_item()`, and `detail_context()` into `content.py` to centralize content creation, reward awarding, mention notifications, and attachment linking. Update comment creation/deletion in `comments.py` to use `award_rewards()` with `XP_COMMENT` and the new `is_owner()` helper. Add shared template partials documentation for vote bars, star buttons, post headers, and topic selectors to `AGENTS.md`.
This commit is contained in:
2026-05-30 18:16:39 +00:00
parent ab4861562b
commit a136287d36
57 changed files with 1310 additions and 674 deletions
+174 -6
View File
@@ -17,7 +17,9 @@
border: 1px solid var(--border);
}
.feed-nav-btn {
.feed-nav-btn,
.projects-tab,
.profile-tab {
padding: 0.5rem 1rem;
border-radius: var(--radius);
font-size: 0.8125rem;
@@ -178,15 +180,24 @@
color: var(--text-secondary);
}
.post-action-btn.voted,
.post-action-btn.vote-up {
.post-action-btn.vote-up:hover {
color: var(--accent);
}
.post-action-btn.vote-down {
.post-action-btn.vote-down:hover {
color: var(--danger);
}
.post-action-btn.vote-up.voted {
color: var(--accent);
font-weight: 700;
}
.post-action-btn.vote-down.voted {
color: var(--danger);
font-weight: 700;
}
.post-votes {
display: inline-flex;
align-items: center;
@@ -287,6 +298,14 @@
display: flex;
align-items: center;
gap: 0.375rem;
min-width: 0;
}
.top-author-name {
color: var(--text-secondary);
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.stat-row .value {
@@ -302,8 +321,8 @@
width: 56px;
height: 56px;
border-radius: 50%;
background: #e53935;
color: #fff;
background: var(--danger);
color: var(--white);
font-size: 1.5rem;
display: flex;
align-items: center;
@@ -355,6 +374,12 @@
.feed-right {
display: none;
}
.leaderboard-page {
grid-template-columns: 1fr;
}
.leaderboard-page > aside {
display: none;
}
}
@media (max-width: 768px) {
@@ -428,3 +453,146 @@
width: 100%;
}
}
.leaderboard-page {
display: grid;
grid-template-columns: 280px 1fr 280px;
gap: 1.5rem;
align-items: start;
}
.leaderboard-page > aside {
position: sticky;
top: calc(var(--nav-height) + 1rem);
}
.leaderboard-main {
min-width: 0;
}
.featured-news {
background: var(--bg-card);
border: 1px solid var(--border);
border-radius: var(--radius-lg);
padding: 1.25rem;
}
.featured-news h3 {
font-size: 0.75rem;
font-weight: 700;
text-transform: uppercase;
letter-spacing: 0.1em;
color: var(--text-muted);
margin-bottom: 0.75rem;
}
.featured-news-item {
display: flex;
flex-direction: column;
gap: 0.125rem;
padding: 0.5rem 0;
}
.featured-news-item:not(:last-child) {
border-bottom: 1px solid var(--border);
}
.featured-news-title {
font-size: 0.8125rem;
font-weight: 600;
color: var(--text-primary);
line-height: 1.4;
}
.featured-news-meta {
font-size: 0.6875rem;
color: var(--text-muted);
}
.leaderboard-header {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 0.25rem;
}
.leaderboard-header h1 {
font-size: 1.5rem;
font-weight: 700;
}
.leaderboard-you {
font-size: 0.8125rem;
font-weight: 600;
color: var(--accent);
background: var(--accent-light);
padding: 0.25rem 0.625rem;
border-radius: 999px;
}
.leaderboard-intro {
font-size: 0.8125rem;
color: var(--text-muted);
margin-bottom: 1rem;
}
.leaderboard-list {
list-style: none;
margin: 0;
padding: 0;
}
.leaderboard-row {
display: flex;
align-items: center;
gap: 0.75rem;
padding: 0.75rem 1rem;
background: var(--bg-card);
border: 1px solid var(--border);
border-radius: var(--radius);
margin-bottom: 0.5rem;
}
.leaderboard-row-self {
border-color: var(--accent);
background: var(--accent-light);
}
.leaderboard-rank {
font-weight: 700;
font-size: 0.9375rem;
color: var(--text-muted);
min-width: 2.5rem;
}
.leaderboard-name {
flex: 1;
min-width: 0;
font-weight: 600;
color: var(--text-primary);
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.leaderboard-level {
font-size: 0.75rem;
color: var(--text-muted);
}
.leaderboard-stars {
font-weight: 700;
color: var(--text-primary);
}
.leaderboard-star-icon {
color: var(--accent);
}
.leaderboard-empty {
list-style: none;
padding: 2rem 1rem;
text-align: center;
color: var(--text-muted);
font-size: 0.875rem;
}