mirror of
https://github.com/EnixCoda/Gitako.git
synced 2026-03-11 08:54:44 +00:00
refactor(URLHelper): remove function 'detectShouldShow'
This commit is contained in:
parent
856762cf84
commit
46a11fde39
2 changed files with 18 additions and 15 deletions
|
|
@ -41,7 +41,7 @@ export default class GitakoSideBar extends preact.Component {
|
|||
const branchName = metaDataFromUrl.branchName || metaDataFromAPI['default_branch']
|
||||
const metaData = { ...metaDataFromUrl, branchName, api: metaDataFromAPI }
|
||||
this.setState({ metaData })
|
||||
this.setShouldShow(URLHelper.detectShouldShow(metaData))
|
||||
this.setShouldShow(URLHelper.isInCodePage(metaData))
|
||||
const treeData = await GitHubHelper.getTreeData({ ...metaData, accessToken })
|
||||
this.setState({ treeData, loading: false })
|
||||
|
||||
|
|
@ -69,8 +69,9 @@ export default class GitakoSideBar extends preact.Component {
|
|||
}
|
||||
|
||||
onPJAXEnd = () => {
|
||||
const { metaData } = this.state
|
||||
this.setState({ loading: false })
|
||||
this.setShouldShow(URLHelper.detectShouldShow())
|
||||
this.setShouldShow(URLHelper.isInCodePage(metaData))
|
||||
this.decorateGitHubPageContent()
|
||||
DOMHelper.scrollToRepoContent()
|
||||
DOMHelper.focusSearchInput()
|
||||
|
|
|
|||
|
|
@ -1,8 +1,7 @@
|
|||
function parse() {
|
||||
function parseRaw() {
|
||||
const { pathname } = window.location
|
||||
const [
|
||||
,
|
||||
// ignore content before the first '/'
|
||||
let [
|
||||
/* ignore content before the first '/' */,
|
||||
userName,
|
||||
repoName,
|
||||
type,
|
||||
|
|
@ -15,25 +14,28 @@ function parse() {
|
|||
branchName,
|
||||
}
|
||||
}
|
||||
function parse() {
|
||||
const parsedData = parseRaw()
|
||||
if (!isInCodePage(parsedData)) {
|
||||
delete parsedData.type
|
||||
delete parsedData.branchName
|
||||
}
|
||||
return parsedData
|
||||
}
|
||||
|
||||
const RESERVED_NAME = ['blog']
|
||||
function isInCodePage() {
|
||||
const { userName, repoName, type, branchName } = parse()
|
||||
return !!(
|
||||
function isInCodePage(metaData = {}) {
|
||||
const { userName, repoName, type, branchName } = {...parseRaw(), ...metaData}
|
||||
return (
|
||||
userName &&
|
||||
!RESERVED_NAME.find(_ => _ === userName) &&
|
||||
repoName &&
|
||||
(!type || type === 'tree' || type === 'blob') &&
|
||||
((type && branchName) || !(type || branchName))
|
||||
(branchName || !type && !branchName)
|
||||
)
|
||||
}
|
||||
|
||||
function detectShouldShow(metaData) {
|
||||
return isInCodePage() && (!metaData || metaData.repoName)
|
||||
}
|
||||
|
||||
export default {
|
||||
detectShouldShow,
|
||||
isInCodePage,
|
||||
parse,
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue