import React, { useState } from 'react'; import TextField from '@mui/material/TextField'; import Button from '@mui/material/Button'; import Stack from '@mui/material/Stack'; import Box from '@mui/material/Box'; export const GitHubRepoSearch = () => { const [repoUrl, setRepoUrl] = useState(''); const handleSearch = () => { if(!repoUrl || repoUrl.length < 1 ) { return window.alert("Please enter a valid Github URL!") } const matchedRepo = repoUrl.match(/https:\/\/github\.com\/(.*)/)[1] // Construct the search URL const searchUrl = `https://github.com/search?q=repo:${matchedRepo} fetch(&type=code`; // Redirect the user to a new search results page window.open(searchUrl, "_blank"); }; return ( setRepoUrl(e.target.value)} size="small" sx={{width: "450px"}} /> ); }