Commit 0a8302b1 authored by Kamal Thennakoon's avatar Kamal Thennakoon

introduce medium scrapper

parent ebc21901
......@@ -52,12 +52,13 @@ export async function getAllPortfolios() {
return err
}
}
export async function createPortfolio(gitUsername, stofUsername) {
export async function createPortfolio(gitUsername, stofUsername, mediumUsername) {
const url = `/user/create`
try {
const response = await portfolioPublicFetch.post(url, {
git_username: gitUsername,
stof_username: stofUsername
stof_username: stofUsername,
medium_username: mediumUsername,
})
const data = response.data
......
......@@ -16,31 +16,41 @@ import {
export default function PortfolioGenerateDialog(props) {
const router = useRouter()
const [username, setUsername] = useState('')
const [stofUsername, setStofUsername] = useState('')
const [mediumUsername, setMediumUsername] = useState('')
const handleChange = (e) => {
console.log(e.target.value)
setUsername(e.target.value.toLowerCase())
}
const handleStofChange = (e) => {
console.log(e.target.value)
setStofUsername(e.target.value.toLowerCase())
}
const handleMediumChange = (e) => {
console.log(e.target.value)
setMediumUsername(e.target.value.toLowerCase())
}
const navigateToPortfolio = (username) => {
console.log('username::', username)
router.push(`/portfolio/${username}`)
}
const createUserPortfolio = async (username) => {
const portfolio = await createPortfolio(username)
const createUserPortfolio = async (git_username,stof_username,medium_username) => {
const portfolio = await createPortfolio(git_username,stof_username,medium_username)
return portfolio && portfolio.valid ? true : false
}
const portfolioGeneration = async (username) => {
const portfolioGeneration = async (git_username,stof_username,medium_username) => {
try {
const profileValidity = await checkGithubProfile(username)
const profileValidity = await checkGithubProfile(git_username)
if (profileValidity) {
const portfolioValidity = await checkPortfolio(username)
const portfolioValidity = await checkPortfolioAvailability(git_username)
if (portfolioValidity) {
navigateToPortfolio(username)
navigateToPortfolio(git_username)
} else {
const portfolio = await createUserPortfolio(username)
const portfolio = await createUserPortfolio(git_username,stof_username,medium_username)
if (portfolio) {
navigateToPortfolio(username)
navigateToPortfolio(git_username)
} else {
console.log('something went wrong, show it using toast')
}
......@@ -54,7 +64,7 @@ export default function PortfolioGenerateDialog(props) {
}
// check user portfolio availabilty from the backend
const checkPortfolio = async (username) => {
const checkPortfolioAvailability = async (username) => {
const response = await checkPortfolioExists(username)
return response && response.valid ? true : false
......@@ -73,7 +83,7 @@ export default function PortfolioGenerateDialog(props) {
onClose={props.handleClose}
aria-labelledby="form-dialog-title"
>
<DialogTitle id="form-dialog-title">Subscribe</DialogTitle>
<DialogTitle id="form-dialog-title">Generate Portfolio</DialogTitle>
<DialogContent>
<DialogContentText>
Please enter user's github username to generate the dynamic
......@@ -89,12 +99,32 @@ export default function PortfolioGenerateDialog(props) {
type="text"
fullWidth
/>
<TextField
value={stofUsername}
onChange={handleStofChange}
autoFocus
margin="dense"
id="stof_username"
label="Stackoverflow Username"
type="text"
fullWidth
/>
<TextField
value={mediumUsername}
onChange={handleMediumChange}
autoFocus
margin="dense"
id="medium_username"
label="medium Username"
type="text"
fullWidth
/>
</DialogContent>
<DialogActions>
<Button onClick={props.handleClose} color="primary">
Cancel
</Button>
<Button onClick={() => portfolioGeneration(username)} color="primary">
<Button onClick={() => portfolioGeneration(username,stofUsername,mediumUsername)} color="primary">
Generate
</Button>
</DialogActions>
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment