@@ -43,6 +43,8 @@ const MainDashboard: React.FC = () => {
4343 const [ newSkill , setNewSkill ] = useState ( '' ) ;
4444 const [ selectedRole , setSelectedRole ] = useState ( ( ) => localStorage . getItem ( 'selectedRole' ) || '' ) ;
4545 const [ repos , setRepos ] = useState < { id : number ; name : string ; html_url : string } [ ] > ( [ ] ) ;
46+ const [ useOAuth , setUseOAuth ] = useState ( true ) ; // Toggle for GitHub connection method
47+ const [ showAuthOptions , setShowAuthOptions ] = useState ( false ) ; // Toggle for showing auth options
4648
4749 useEffect ( ( ) => {
4850 localStorage . setItem ( 'aboutMe' , aboutMe ) ;
@@ -67,10 +69,35 @@ const MainDashboard: React.FC = () => {
6769 } ;
6870
6971 const handleGitHubConnect = async ( ) => {
72+ if ( ! showAuthOptions ) {
73+ setShowAuthOptions ( true ) ; // Show auth options first
74+ return ;
75+ }
76+
7077 try {
71- initiateGitHubOAuth ( ) ;
78+ if ( useOAuth ) {
79+ initiateGitHubOAuth ( ) ;
80+ } else {
81+ const username = prompt ( 'Enter GitHub username:' ) ;
82+ if ( ! username ) {
83+ alert ( 'GitHub username is required for No Auth connection.' ) ;
84+ return ;
85+ }
86+ const fetchedRepos = await connectToGitHub ( username ) ;
87+ setRepos ( fetchedRepos ) ;
88+
89+ // Fetch languages and add them as skills
90+ const languagesSet = new Set ( skills ) ;
91+ for ( const repo of fetchedRepos ) {
92+ const repoLanguages = await fetchRepoLanguages ( repo . html_url ) ;
93+ Object . keys ( repoLanguages ) . forEach ( ( lang ) => languagesSet . add ( lang ) ) ;
94+ }
95+ setSkills ( Array . from ( languagesSet ) ) ;
96+ }
7297 } catch ( error ) {
73- console . error ( 'Error initiating GitHub OAuth:' , error ) ;
98+ console . error ( 'Error connecting to GitHub:' , error ) ;
99+ } finally {
100+ setShowAuthOptions ( false ) ; // Close auth options after proceeding
74101 }
75102 } ;
76103
@@ -203,14 +230,26 @@ const MainDashboard: React.FC = () => {
203230 >
204231 Connect to LinkedIn
205232 </ Button >
233+ { showAuthOptions && (
234+ < FormControl fullWidth sx = { { mb : 2 } } >
235+ < InputLabel > GitHub Connection Method</ InputLabel >
236+ < Select
237+ value = { useOAuth ? 'oauth' : 'no-auth' }
238+ onChange = { ( e ) => setUseOAuth ( e . target . value === 'oauth' ) }
239+ >
240+ < MenuItem value = "oauth" > OAuth</ MenuItem >
241+ < MenuItem value = "no-auth" > No Auth</ MenuItem >
242+ </ Select >
243+ </ FormControl >
244+ ) }
206245 < Button
207246 variant = "contained"
208247 color = "secondary"
209248 startIcon = { < GitHub /> }
210249 fullWidth
211250 onClick = { handleGitHubConnect }
212251 >
213- Connect to GitHub
252+ { showAuthOptions ? 'Proceed' : ' Connect to GitHub' }
214253 </ Button >
215254 {
216255 repos . length > 0 && < Typography variant = "h6" sx = { { mt : 3 } } >
@@ -226,7 +265,7 @@ const MainDashboard: React.FC = () => {
226265 </ li >
227266 ) ) }
228267 </ ul >
229- </ Paper >
268+ </ Paper >
230269 </ Grid >
231270 </ Grid >
232271 </ Container >
0 commit comments