Skip to content

Commit

Permalink
Merge branch 'main' of github.com:sergeychernyshev/GitTerra
Browse files Browse the repository at this point in the history
  • Loading branch information
sergeychernyshev committed Feb 26, 2024
2 parents dbbc3f4 + 0990045 commit 7787efd
Show file tree
Hide file tree
Showing 9 changed files with 53 additions and 41 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"build": "NODE_ENV=production webpack --config webpack.prod.js",
"watch": "NODE_ENV=production webpack --config webpack.prod.js --watch",
"api-server": "node dist/apiServer.js",
"generate": "node dist/generateMap.js -u https://github.com/sergeychernyshev/GitTerra",
"generate": "node dist/mapGeneratorWorker.js -u https://github.com/sergeychernyshev/GitTerra",
"web-dev-server": "webpack serve --config webpack.dev.js"
},
"repository": {
Expand Down
2 changes: 1 addition & 1 deletion src/404.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!DOCTYPE html>
<html>
<html lang="en">
<head>
<title>File not found</title>
<meta content="text/html; charset=utf-8" />
Expand Down
2 changes: 1 addition & 1 deletion src/apiServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ app.post("/api/generateMap", function (req, res) {
return res.status(200).send(`Process already exists but not complete`);
}

const worker = child.spawn("node", ["./dist/generateMap.js"]);
const worker = child.spawn("node", ["./dist/mapGeneratorWorker.js"]);
worker.stdin.write(repo_string);
worker.stdin.end();

Expand Down
14 changes: 13 additions & 1 deletion src/homepage/HomePageMenu.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,19 @@ const HomePageMenu = function () {
}

function startGeneration(repo) {
generateMap(repo, setIsGenerating, setGenerationError);
generateMap({
repo,
onGenerationStart: () => {
setIsGenerating(true);
},
onGenerationSuccess: (url) => {
window.location.href = url;
},
onGenerationError: (message) => {
setGenerationError(message);
setIsGenerating(false);
},
});
}

return isGenerating ? (
Expand Down
13 changes: 7 additions & 6 deletions src/homepage/RepoInputForm.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,13 @@ function RepoInputForm({ callback, initialError }) {
required
placeholder="https://github.com/your/repo"
/>
<div
id="error"
style={{ visibility: valid && !initialError ? "hidden" : "visible" }}
>
{error || initialError}
</div>

{valid && !initialError && <div className="error"></div>}
{!valid && <div className="validation error">{error}</div>}
{valid && initialError && (
<div className="initial error">{initialError}</div>
)}

<input
type="image"
id="generateButton"
Expand Down
33 changes: 18 additions & 15 deletions src/homepage/generateMap.js
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 });
}
24 changes: 10 additions & 14 deletions src/homepage/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ h1 * {
}

body {
background-color: white;
background: url("images/background_and_menus/site_background_image_bg.svg");
background-color: white;
background-size: cover;

/* Jsut got a font stack from CSS-tricks site: https://css-tricks.com/snippets/css/font-stacks/ */
Expand All @@ -32,11 +32,13 @@ body {
#enterGitRepo {
aspect-ratio: auto 322 / 110.25;
width: 100%;
margin-top: 8%;
}

#generateButton {
aspect-ratio: auto 322 / 71.862;
width: 100%;
margin-bottom: 8%;
}

#mainMenu,
Expand Down Expand Up @@ -114,23 +116,17 @@ a#start {
outline: 0 !important;
}

#error {
visibility: hidden;
.error {
text-align: center;
color: rgb(255 204 13);
font-weight: bold;
margin: 0.5em 0;
height: 2em;
}

#error.invalid {
visibility: visible;
min-height: 2em;
}

#enterGitRepo {
margin-top: 8%;
.validation.error {
color: rgb(255 204 13);
}

#generateButton {
margin-bottom: 8%;
}
.initial.error {
color: rgb(255 115 13);
}
2 changes: 1 addition & 1 deletion src/generateMap.js → src/mapGeneratorWorker.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ async function generateMap({
const dirname = "./repos/" + host + "/" + owner + "/" + repo;
const filename = dirname + "/index.html";
mkdirp.sync(dirname);
if (number_of_blocks === MIN_TILES) {
if (repoData.total.files < 1) {
// should be build a special page with message "Your repo seems empty.
//Start to buld your city by commiting code to your repo and come again!"
} else {
Expand Down
2 changes: 1 addition & 1 deletion webpack.server.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ module.exports = {
],
},
entry: {
generateMap: "./src/generateMap",
mapGeneratorWorker: "./src/mapGeneratorWorker",
apiServer: "./src/apiServer",
},
resolve: {
Expand Down

0 comments on commit 7787efd

Please sign in to comment.