forked from pomber/git-history
-
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.
- Loading branch information
Showing
6 changed files
with
112 additions
and
27 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import React, { useState, useEffect } from "react"; | ||
import { getLanguage, loadLanguage } from "./language-detector"; | ||
|
||
export function Center({ children }) { | ||
return ( | ||
<div | ||
style={{ | ||
display: "flex", | ||
flexDirection: "column", | ||
alignItems: "center", | ||
justifyContent: "center", | ||
height: "100%", | ||
padding: "0 40px" | ||
}} | ||
> | ||
{children} | ||
</div> | ||
); | ||
} | ||
|
||
export function Loading({ repo, path }) { | ||
return ( | ||
<Center> | ||
<p> | ||
Loading <strong>{path}</strong> history {repo ? "from " + repo : ""}... | ||
</p> | ||
</Center> | ||
); | ||
} | ||
|
||
export function useLanguageLoader(path) { | ||
const [loadedLang, setLang] = useState(false); | ||
|
||
useEffect(() => { | ||
const lang = getLanguage(path); | ||
loadLanguage(lang).then(() => setLang(lang)); | ||
}, [path, setLang]); | ||
|
||
return loadedLang; | ||
} |
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,27 +1,29 @@ | ||
import { getLanguage } from "./language-detector"; | ||
import App from "./app"; | ||
import App from "./napp"; | ||
import React from "react"; | ||
import ReactDOM from "react-dom"; | ||
|
||
const [repo, sha, path] = getParams(); | ||
const lang = getLanguage(path); | ||
const root = document.getElementById("root"); | ||
ReactDOM.render(<App />, root); | ||
|
||
ReactDOM.render(<App repo={repo} sha={sha} path={path} lang={lang} />, root); | ||
// const [repo, sha, path] = getParams(); | ||
// const lang = getLanguage(path); | ||
|
||
function getParams() { | ||
const [ | ||
, | ||
owner, | ||
reponame, | ||
action, | ||
sha, | ||
...paths | ||
] = window.location.pathname.split("/"); | ||
// ReactDOM.render(<App repo={repo} sha={sha} path={path} lang={lang} />, root); | ||
|
||
if (action !== "commits" && action !== "blob") { | ||
return []; | ||
} | ||
// function getParams() { | ||
// const [ | ||
// , | ||
// owner, | ||
// reponame, | ||
// action, | ||
// sha, | ||
// ...paths | ||
// ] = window.location.pathname.split("/"); | ||
|
||
return [owner + "/" + reponame, sha, "/" + paths.join("/")]; | ||
} | ||
// if (action !== "commits" && action !== "blob") { | ||
// return []; | ||
// } | ||
|
||
// return [owner + "/" + reponame, sha, "/" + paths.join("/")]; | ||
// } |
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 |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import React from "react"; | ||
import History from "./history"; | ||
import { Loading, useLanguageLoader } from "./app-helpers"; | ||
|
||
const cli = window._CLI; | ||
|
||
export default function App() { | ||
if (cli) { | ||
return <CliApp data={cli} />; | ||
} else { | ||
return null; | ||
// return <GitHubApp />; | ||
} | ||
} | ||
|
||
function CliApp({ data }) { | ||
let { commits, path } = data; | ||
commits = commits.map(commit => ({ ...commit, date: new Date(commit.date) })); | ||
const lang = useLanguageLoader(path); | ||
if (!lang) { | ||
return <Loading path={path} />; | ||
} else { | ||
return <History commits={commits} language={lang} />; | ||
} | ||
} |