fix: prevent loading at non-project page

This commit is contained in:
Enix 2018-09-20 10:33:24 +08:00 committed by EnixCoda
parent 2a5e517fab
commit 07163774e7
2 changed files with 14 additions and 3 deletions

View file

@ -6,6 +6,7 @@ import keyHelper from '../../utils/keyHelper'
const init = dispatch => async () => {
try {
if (!URLHelper.isInRepoPage()) return
let nothingWentWrong = true
const metaData = URLHelper.parse()
dispatch(setMetaData, metaData)

View file

@ -33,12 +33,21 @@ const TYPES = {
// known but not related types: issues, pulls, wiki, insight,
// TODO: record more types
}
function isInCodePage(metaData = {}) {
const { userName, repoName, type, branchName } = { ...parseRaw(), ...metaData }
function isInRepoPage(metaData) {
const { userName, repoName } = metaData || parseRaw()
return Boolean(
userName &&
!RESERVED_NAME.find(_ => _ === userName) &&
repoName &&
repoName
)
}
function isInCodePage(metaData = {}) {
const mergedRepo = { ...parseRaw(), ...metaData }
const { type, branchName } = mergedRepo
return Boolean(
isInRepoPage(mergedRepo) &&
(!type || type === TYPES.TREE || type === TYPES.BLOB) &&
type !== TYPES.COMMIT &&
(branchName || (!type && !branchName))
@ -52,6 +61,7 @@ function getCurrentPath(decode = false) {
export default {
getCurrentPath,
isInRepoPage,
isInCodePage,
parse,
}