-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' of github.com:sergeychernyshev/GitTerra
- Loading branch information
Showing
9 changed files
with
53 additions
and
41 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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 |
---|---|---|
@@ -1,50 +1,53 @@ | ||
async function checkJobStatus(postdata, setIsGenerating, setGenerationError) { | ||
async function checkJobStatus({ | ||
postdata, | ||
onGenerationSuccess, | ||
onGenerationError, | ||
}) { | ||
let response = await fetch("/api/mapStatus", { | ||
method: "POST", | ||
body: JSON.stringify(postdata), | ||
headers: { "Content-type": "application/json" }, | ||
}); | ||
|
||
if (!response.ok) { | ||
setIsGenerating(false); | ||
setGenerationError( | ||
onGenerationError( | ||
"We have problems generating your map, please try again later." | ||
); | ||
return; | ||
} | ||
|
||
let job = await response.json(); | ||
if (job.complete) { | ||
window.location.href = job.mapPageURL; | ||
onGenerationSuccess(job.mapPageURL); | ||
} else { | ||
setTimeout(() => { | ||
checkJobStatus(postdata, setIsGenerating, setGenerationError); | ||
checkJobStatus({ postdata, onGenerationSuccess, onGenerationError }); | ||
}, 3000); | ||
} | ||
} | ||
|
||
export default async function generateMap( | ||
export default async function generateMap({ | ||
repo, | ||
setIsGenerating, | ||
setGenerationError | ||
) { | ||
const repoRequest = { repo }; | ||
onGenerationStart, | ||
onGenerationError, | ||
onGenerationSuccess, | ||
}) { | ||
const postdata = { repo }; | ||
|
||
let response = await fetch("/api/generateMap", { | ||
method: "POST", | ||
body: JSON.stringify(repoRequest), | ||
body: JSON.stringify(postdata), | ||
headers: { "Content-type": "application/json" }, | ||
}); | ||
|
||
if (!response.ok) { | ||
setIsGenerating(false); | ||
setGenerationError( | ||
onGenerationError( | ||
"We couldn't start generating your map, please try again later." | ||
); | ||
return; | ||
} | ||
|
||
setIsGenerating(true); | ||
onGenerationStart(); | ||
|
||
checkJobStatus(repoRequest, setIsGenerating, setGenerationError); | ||
checkJobStatus({ postdata, onGenerationSuccess, onGenerationError }); | ||
} |
This file contains 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
This file contains 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
This file contains 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