Skip to content

Commit 48d47d3

Browse files
committed
Merge branch 'main' into muslime-main
2 parents f115259 + 71966aa commit 48d47d3

File tree

5 files changed

+146
-55
lines changed

5 files changed

+146
-55
lines changed

src/app/api/search/route.ts

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
import { NextRequest, NextResponse } from 'next/server'
2+
import { githubAPIClient } from '@/lib/api/github-api-client'
3+
4+
export async function GET(request: NextRequest) {
5+
try {
6+
const { searchParams } = new URL(request.url)
7+
const query = searchParams.get('q')
8+
const type = searchParams.get('type') || 'repos'
9+
const limit = parseInt(searchParams.get('limit') || '20')
10+
11+
if (!query) {
12+
return NextResponse.json(
13+
{ error: 'Query parameter "q" is required' },
14+
{ status: 400 }
15+
)
16+
}
17+
18+
let results
19+
if (type === 'users') {
20+
results = await githubAPIClient.searchUsers(query, 'all', limit)
21+
} else {
22+
results = await githubAPIClient.searchRepositories(query, 'stars', limit)
23+
}
24+
25+
return NextResponse.json({
26+
query,
27+
type,
28+
results,
29+
total: results.length
30+
})
31+
} catch (error) {
32+
console.error('Search API error:', error)
33+
return NextResponse.json(
34+
{ error: 'Internal server error' },
35+
{ status: 500 }
36+
)
37+
}
38+
}
39+
40+
export async function POST(request: NextRequest) {
41+
try {
42+
const body = await request.json()
43+
const { query, type = 'repos', limit = 20 } = body
44+
45+
if (!query) {
46+
return NextResponse.json(
47+
{ error: 'Query is required in request body' },
48+
{ status: 400 }
49+
)
50+
}
51+
52+
let results
53+
if (type === 'users') {
54+
results = await githubAPIClient.searchUsers(query, 'all', limit)
55+
} else {
56+
results = await githubAPIClient.searchRepositories(query, 'stars', limit)
57+
}
58+
59+
return NextResponse.json({
60+
query,
61+
type,
62+
results,
63+
total: results.length
64+
})
65+
} catch (error) {
66+
console.error('Search API error:', error)
67+
return NextResponse.json(
68+
{ error: 'Internal server error' },
69+
{ status: 500 }
70+
)
71+
}
72+
}

src/app/search/page.tsx

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,44 @@ export default function SearchPage() {
108108
);
109109
const [loadingAnalytics, setLoadingAnalytics] = useState<boolean>(false);
110110

111+
const loadUserAnalytics = useCallback(async () => {
112+
if (!userParam) return;
113+
114+
setLoadingAnalytics(true);
115+
try {
116+
const analytics = await githubAPIClient.getUserAnalytics(userParam);
117+
if (analytics) {
118+
// Convert GitHubUserDetailed to the expected profile format
119+
const convertedAnalytics: UserAnalytics = {
120+
profile: analytics.profile ? {
121+
avatar_url: analytics.profile.avatar_url,
122+
login: analytics.profile.login,
123+
type: analytics.profile.type,
124+
bio: analytics.profile.bio,
125+
public_repos: analytics.profile.public_repos,
126+
followers: analytics.profile.followers,
127+
following: analytics.profile.following,
128+
location: analytics.profile.location,
129+
company: analytics.profile.company,
130+
html_url: analytics.profile.html_url
131+
} : undefined,
132+
overview: analytics.overview,
133+
languages: analytics.languages,
134+
behavior: analytics.behavior
135+
};
136+
setUserAnalytics(convertedAnalytics);
137+
} else {
138+
setUserAnalytics(null);
139+
}
140+
} catch (error) {
141+
console.error("Analytics error:", error);
142+
// Fallback to null if API fails
143+
setUserAnalytics(null);
144+
} finally {
145+
setLoadingAnalytics(false);
146+
}
147+
}, [userParam]);
148+
111149
const throttle = useCallback(
112150
<T extends (...args: unknown[]) => void>(
113151
func: T,

src/components/quick-wins/hooks/useQuickWins.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ export function useQuickWins() {
5050
])
5151
}
5252
isInitialized.current = true
53-
}, [loadFromCache, isQuickWinsCacheExpired, goodIssues.length, easyFixes.length, fetchGoodIssues, fetchEasyFixes])
53+
}, [loadFromCache, isQuickWinsCacheExpired, fetchGoodIssues, fetchEasyFixes])
5454

5555
useEffect(() => {
5656
if (goodIssues.length > 0) {

0 commit comments

Comments
 (0)