-
Notifications
You must be signed in to change notification settings - Fork 128
feat(frontend): add Groups with leaderboard, roles, and invite system #249
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
Open
junhoyeo
wants to merge
12
commits into
main
Choose a base branch
from
junhoyeo/groups
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 5 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
5d03821
chore: regenerate bun.lock after workspace cleanup
junhoyeo ec06364
feat(frontend): add Groups with leaderboard, roles, and invite system
junhoyeo d7ee26a
feat(api): add user groups and group leaderboard endpoints
junhoyeo 2eb1391
feat(frontend): integrate groups into profile page and leaderboard
junhoyeo 9397dc0
fix(db): register 0005_add_groups migration in drizzle journal
junhoyeo 4f405a5
fix(db): add relationName to disambiguate multi-target user relations
junhoyeo d5ce1f3
fix(groups): correct slug generation and leaderboard pagination logic
junhoyeo 04de0a0
fix(api): add missing authorization checks and TOCTOU guards
junhoyeo c6b6eb2
fix(api): correct SQL aggregation, pagination, and auth fallback
junhoyeo 3fe5949
fix(frontend): fix client-side routing, race conditions, and state bu…
junhoyeo b820451
fix(frontend): fix race condition and client-side routing in leaderbo…
junhoyeo 8494ab2
fix(groups): auth fallback, query consolidation, and cleanup
junhoyeo 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
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
270 changes: 270 additions & 0 deletions
270
packages/frontend/src/app/(main)/groups/GroupsClient.tsx
This file contains hidden or 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,270 @@ | ||
| "use client"; | ||
|
|
||
| import { useState, useEffect, useCallback } from "react"; | ||
| import { useRouter } from "nextjs-toploader/app"; | ||
| import styled from "styled-components"; | ||
| import { TabBar } from "@/components/TabBar"; | ||
| import { LeaderboardSkeleton } from "@/components/Skeleton"; | ||
|
|
||
| const Section = styled.div` | ||
| margin-bottom: 40px; | ||
| `; | ||
|
|
||
| const HeaderRow = styled.div` | ||
| display: flex; | ||
| align-items: center; | ||
| justify-content: space-between; | ||
| margin-bottom: 8px; | ||
| gap: 16px; | ||
|
|
||
| @media (max-width: 480px) { | ||
| flex-direction: column; | ||
| align-items: flex-start; | ||
| } | ||
| `; | ||
|
|
||
| const Title = styled.h1` | ||
| font-size: 30px; | ||
| font-weight: bold; | ||
| color: var(--color-fg-default); | ||
| `; | ||
|
|
||
| const Description = styled.p` | ||
| margin-bottom: 24px; | ||
| color: var(--color-fg-muted); | ||
| `; | ||
|
|
||
| const CreateButton = styled.a` | ||
| display: inline-flex; | ||
| align-items: center; | ||
| gap: 8px; | ||
| padding: 8px 16px; | ||
| background-color: #0073ff; | ||
| color: #fff; | ||
| border: none; | ||
| border-radius: 8px; | ||
| font-size: 14px; | ||
| font-weight: 500; | ||
| cursor: pointer; | ||
| text-decoration: none; | ||
| transition: background-color 0.15s; | ||
| white-space: nowrap; | ||
|
|
||
| &:hover { | ||
| background-color: #005fcc; | ||
| } | ||
| `; | ||
|
|
||
| const TabSection = styled.div` | ||
| margin-bottom: 24px; | ||
| `; | ||
|
|
||
| const GroupGrid = styled.div` | ||
| display: grid; | ||
| grid-template-columns: 1fr; | ||
| gap: 12px; | ||
|
|
||
| @media (min-width: 640px) { | ||
| grid-template-columns: repeat(2, 1fr); | ||
| } | ||
|
|
||
| @media (min-width: 1024px) { | ||
| grid-template-columns: repeat(3, 1fr); | ||
| } | ||
| `; | ||
|
|
||
| const GroupCard = styled.div` | ||
| padding: 20px; | ||
| border-radius: 12px; | ||
| border: 1px solid var(--color-border-default); | ||
| background-color: var(--color-bg-default); | ||
| cursor: pointer; | ||
| transition: all 0.2s; | ||
|
|
||
| &:hover { | ||
| border-color: #0073ff; | ||
| background-color: rgba(0, 115, 255, 0.03); | ||
| } | ||
| `; | ||
|
|
||
| const GroupName = styled.h3` | ||
| font-size: 16px; | ||
| font-weight: 600; | ||
| color: var(--color-fg-default); | ||
| margin-bottom: 4px; | ||
| overflow: hidden; | ||
| text-overflow: ellipsis; | ||
| white-space: nowrap; | ||
| `; | ||
|
|
||
| const GroupDescription = styled.p` | ||
| font-size: 14px; | ||
| color: var(--color-fg-muted); | ||
| margin-bottom: 12px; | ||
| overflow: hidden; | ||
| text-overflow: ellipsis; | ||
| white-space: nowrap; | ||
| `; | ||
|
|
||
| const GroupMeta = styled.div` | ||
| display: flex; | ||
| align-items: center; | ||
| gap: 12px; | ||
| font-size: 12px; | ||
| color: var(--color-fg-subtle); | ||
| `; | ||
|
|
||
| const Badge = styled.span<{ $variant?: "public" | "private" | "role" }>` | ||
| display: inline-flex; | ||
| align-items: center; | ||
| padding: 2px 8px; | ||
| border-radius: 12px; | ||
| font-size: 11px; | ||
| font-weight: 500; | ||
|
|
||
| ${({ $variant }) => | ||
| $variant === "public" | ||
| ? `background: rgba(63, 185, 80, 0.1); color: #3FB950;` | ||
| : $variant === "private" | ||
| ? `background: rgba(248, 81, 73, 0.1); color: #F85149;` | ||
| : `background: rgba(0, 115, 255, 0.1); color: #0073FF;`} | ||
| `; | ||
|
|
||
| const EmptyState = styled.div` | ||
| padding: 48px; | ||
| text-align: center; | ||
| border-radius: 16px; | ||
| border: 1px solid var(--color-border-default); | ||
| background-color: var(--color-bg-default); | ||
| `; | ||
|
|
||
| const EmptyMessage = styled.p` | ||
| margin-bottom: 8px; | ||
| color: var(--color-fg-muted); | ||
| font-size: 16px; | ||
| `; | ||
|
|
||
| const EmptyHint = styled.p` | ||
| font-size: 14px; | ||
| color: var(--color-fg-subtle); | ||
| `; | ||
|
|
||
| type Tab = "my" | "discover"; | ||
|
|
||
| interface GroupItem { | ||
| id: string; | ||
| name: string; | ||
| slug: string; | ||
| description: string | null; | ||
| isPublic: boolean; | ||
| memberCount?: number; | ||
| role?: string; | ||
| } | ||
|
|
||
| interface GroupsResponse { | ||
| groups: GroupItem[]; | ||
| pagination: { | ||
| page: number; | ||
| total: number; | ||
| totalPages: number; | ||
| hasNext: boolean; | ||
| }; | ||
| } | ||
|
|
||
| interface GroupsClientProps { | ||
| currentUser: { id: string; username: string } | null; | ||
| } | ||
|
|
||
| export default function GroupsClient({ currentUser }: GroupsClientProps) { | ||
| const router = useRouter(); | ||
| const [tab, setTab] = useState<Tab>(currentUser ? "my" : "discover"); | ||
| const [data, setData] = useState<GroupsResponse | null>(null); | ||
| const [isLoading, setIsLoading] = useState(true); | ||
|
|
||
| const fetchGroups = useCallback( | ||
cubic-dev-ai[bot] marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| async (activeTab: Tab) => { | ||
| setIsLoading(true); | ||
| try { | ||
| const url = | ||
| activeTab === "my" | ||
| ? "/api/groups?my=true&limit=50" | ||
| : "/api/groups?limit=50"; | ||
| const res = await fetch(url); | ||
| if (res.ok) { | ||
| const result = await res.json(); | ||
| setData(result); | ||
| } | ||
| } finally { | ||
| setIsLoading(false); | ||
| } | ||
| }, | ||
| [] | ||
| ); | ||
|
|
||
| useEffect(() => { | ||
| fetchGroups(tab); | ||
| }, [tab, fetchGroups]); | ||
|
|
||
| const tabs = currentUser | ||
| ? [ | ||
| { id: "my" as Tab, label: "My Groups" }, | ||
| { id: "discover" as Tab, label: "Discover" }, | ||
| ] | ||
| : [{ id: "discover" as Tab, label: "Public Groups" }]; | ||
|
|
||
| return ( | ||
| <> | ||
| <Section> | ||
| <HeaderRow> | ||
| <Title>Groups</Title> | ||
| {currentUser && ( | ||
| <CreateButton href="/groups/new">+ Create Group</CreateButton> | ||
| )} | ||
| </HeaderRow> | ||
| <Description> | ||
| Create or join groups to compete on team leaderboards | ||
| </Description> | ||
| </Section> | ||
|
|
||
| <TabSection> | ||
| <TabBar tabs={tabs} activeTab={tab} onTabChange={(t) => setTab(t)} /> | ||
| </TabSection> | ||
|
|
||
| {isLoading ? ( | ||
| <LeaderboardSkeleton /> | ||
| ) : !data?.groups.length ? ( | ||
| <EmptyState> | ||
| <EmptyMessage> | ||
| {tab === "my" ? "You haven't joined any groups yet" : "No public groups found"} | ||
| </EmptyMessage> | ||
| <EmptyHint> | ||
| {tab === "my" | ||
| ? "Create a group or ask someone to invite you" | ||
| : "Be the first to create a public group!"} | ||
| </EmptyHint> | ||
| </EmptyState> | ||
| ) : ( | ||
| <GroupGrid> | ||
| {data.groups.map((group) => ( | ||
| <GroupCard | ||
| key={group.id} | ||
| onClick={() => router.push(`/groups/${group.slug}`)} | ||
| > | ||
| <GroupName>{group.name}</GroupName> | ||
| <GroupDescription> | ||
| {group.description || "No description"} | ||
| </GroupDescription> | ||
| <GroupMeta> | ||
| <span>{group.memberCount ?? "–"} members</span> | ||
| <Badge $variant={group.isPublic ? "public" : "private"}> | ||
| {group.isPublic ? "Public" : "Private"} | ||
| </Badge> | ||
| {group.role && <Badge $variant="role">{group.role}</Badge>} | ||
| </GroupMeta> | ||
| </GroupCard> | ||
| ))} | ||
| </GroupGrid> | ||
| )} | ||
| </> | ||
| ); | ||
| } | ||
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.
Uh oh!
There was an error while loading. Please reload this page.