-
Notifications
You must be signed in to change notification settings - Fork 110
Enable multi-language repo search and selection #244
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
Merged
Merged
Changes from 5 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
3f0f462
Enable multi-language repo search and selection
offbeatjs bafa1dd
Update src/app/(public)/_components/hero.tsx
offbeatjs 7a276ec
fix: as per req
offbeatjs 4284a5b
Merge branch 'main' of https://github.com/offbeatjs/hacktoberfest-pro…
offbeatjs 6e7bd4b
Update page.tsx
offbeatjs f907abc
send array as url search Params
offbeatjs 89070fe
Update src/app/(public)/repos/page.tsx
offbeatjs 7917ddf
Refactor hero search and add repos loading skeleton
offbeatjs 3cdbbda
Merge branch 'main' of https://github.com/offbeatjs/hacktoberfest-pro…
offbeatjs 6eff959
Format code
max-programming 73b9b9d
Fix styling issues
max-programming ba450f6
Some visual changes in text display
max-programming bad6e9e
Show selected language names in the list
max-programming 12d24b3
Merge remote-tracking branch 'origin/main' into offbeatjs/main
max-programming 02a497c
Enable typedRoutes and update Next.js
max-programming 8106b7c
Fix type error
max-programming 5f1bbd3
fix type error
max-programming 218ae78
Remove default sort
max-programming 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
offbeatjs marked this conversation as resolved.
Show resolved
Hide resolved
|
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
max-programming marked this conversation as resolved.
Show resolved
Hide resolved
|
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
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
max-programming marked this conversation as resolved.
Show resolved
Hide resolved
|
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,135 @@ | ||
| import { env } from '@/env.mjs'; | ||
| import { notFound } from 'next/navigation'; | ||
| import { Header } from '@/app/(public)/_components/header'; | ||
| import { ScrollToTop } from './_components/scroll-to-top'; | ||
| import { RepoCard } from './_components/repo-card'; | ||
| import { Sorter } from './_components/sorter'; | ||
| import { StarsFilter } from './_components/stars-filter'; | ||
| import { Pagination } from './_components/pagination'; | ||
| import { auth } from '@/auth'; | ||
| import { db } from '@/lib/db/connection'; | ||
| import { accountsTable, reportsTable } from '@/lib/db/migrations/schema'; | ||
| import { eq } from 'drizzle-orm'; | ||
| import type { RepoResponse, RepoData, RepoItem, SearchParams } from '@/types'; | ||
|
|
||
| export default async function ReposPage({ searchParams }: { searchParams: Promise<SearchParams> }) { | ||
| const sp = await searchParams; | ||
| const raw = (sp as any).l ?? (sp as any).langs ?? ''; | ||
offbeatjs marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| const langs = (Array.isArray(raw) ? raw : raw.toString().split(',')) | ||
| .map((s: string) => decodeURIComponent(s.trim())) | ||
| .filter(Boolean); | ||
|
|
||
| const reposRes = await getRepos(langs, sp); | ||
| if (!reposRes) notFound(); | ||
|
|
||
| const { repos, page } = reposRes; | ||
|
|
||
| return ( | ||
| <> | ||
| <Header /> | ||
| <ScrollToTop /> | ||
| <div className="w-full overflow-x-hidden"> | ||
| <div className="container mx-auto px-4 pt-32 sm:pt-36 md:pt-40 pb-8"> | ||
| <div className="min-h-screen"> | ||
| <Sorter /> | ||
| <StarsFilter /> | ||
| <div className="grid grid-cols-1 gap-6 px-2 sm:px-4 sm:grid-cols-2 lg:grid-cols-3"> | ||
| {repos.items.map(repo => ( | ||
| <RepoCard key={repo.id} repo={repo} /> | ||
| ))} | ||
| </div> | ||
| </div> | ||
| <Pagination | ||
| page={page} | ||
| totalCount={repos.total_count} | ||
| searchParams={sp} | ||
| /> | ||
| </div> | ||
| </div> | ||
| </> | ||
| ); | ||
| } | ||
|
|
||
| async function getRepos( | ||
| languages: string[], | ||
| searchParams: SearchParams | ||
| ): Promise<RepoResponse | undefined> { | ||
| const session = await auth(); | ||
| const { | ||
| p: page = '1', | ||
| s: sort = 'updated', | ||
max-programming marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| o: order = 'desc', | ||
| q: searchQuery = '', | ||
| startStars = '1', | ||
| endStars = '' | ||
| } = searchParams; | ||
|
|
||
| const starsQuery = | ||
| startStars && endStars | ||
| ? `stars:${startStars}..${endStars}` | ||
| : startStars && !endStars | ||
| ? `stars:>${startStars}` | ||
| : !startStars && endStars | ||
| ? `stars:<${endStars}` | ||
| : ''; | ||
|
|
||
| const combinedLangs = languages.map(l => `language:${l}`).join(' '); | ||
|
|
||
| const apiUrl = new URL('https://api.github.com/search/repositories'); | ||
| apiUrl.searchParams.set('page', page.toString()); | ||
| apiUrl.searchParams.set('per_page', '21'); | ||
| apiUrl.searchParams.set('sort', sort.toString()); | ||
| apiUrl.searchParams.set('order', order.toString()); | ||
| apiUrl.searchParams.set( | ||
| 'q', | ||
| `topic:hacktoberfest ${combinedLangs} ${searchQuery} ${starsQuery}` | ||
| ); | ||
|
|
||
| const headers: HeadersInit = { | ||
| Accept: 'application/vnd.github.mercy-preview+json' | ||
| }; | ||
|
|
||
| const userId = session?.user?.id; | ||
|
|
||
| if (userId) { | ||
| const [account] = await db | ||
| .select() | ||
| .from(accountsTable) | ||
| .where(eq(accountsTable.userId, userId)) | ||
| .limit(1); | ||
|
|
||
| if (account && account.access_token) { | ||
| headers.Authorization = `Bearer ${account.access_token}`; | ||
| } else if (env.AUTH_GITHUB_TOKEN) { | ||
| headers.Authorization = `Bearer ${env.AUTH_GITHUB_TOKEN}`; | ||
| } | ||
| } else if (env.AUTH_GITHUB_TOKEN) { | ||
| headers.Authorization = `Bearer ${env.AUTH_GITHUB_TOKEN}`; | ||
| } | ||
|
|
||
| const res = await fetch(apiUrl, { headers }); | ||
| if (!res.ok) return undefined; | ||
|
|
||
| const repos = (await res.json()) as RepoData; | ||
| const reports = await getReportedRepos(); | ||
|
|
||
| repos.items = repos.items.filter((repo: RepoItem) => { | ||
| return !repo.archived && !reports.find(report => report.repoId === repo.id); | ||
| }); | ||
|
|
||
| return { | ||
| page: +page.toString(), | ||
| languageName: languages.join(', '), | ||
| repos | ||
| }; | ||
| } | ||
|
|
||
| async function getReportedRepos() { | ||
| const reports = await db | ||
| .select() | ||
| .from(reportsTable) | ||
| .where(eq(reportsTable.valid, false)) | ||
| .limit(100); | ||
|
|
||
| return reports; | ||
| } | ||
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.