From 07163774e71827aebb7199f038ab8f715d6fc656 Mon Sep 17 00:00:00 2001 From: Enix Date: Thu, 20 Sep 2018 10:33:24 +0800 Subject: [PATCH] fix: prevent loading at non-project page --- src/driver/core/SideBar.js | 1 + src/utils/URLHelper.js | 16 +++++++++++++--- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/driver/core/SideBar.js b/src/driver/core/SideBar.js index 12d7b82..489698c 100644 --- a/src/driver/core/SideBar.js +++ b/src/driver/core/SideBar.js @@ -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) diff --git a/src/utils/URLHelper.js b/src/utils/URLHelper.js index 07bdfde..4fc890a 100644 --- a/src/utils/URLHelper.js +++ b/src/utils/URLHelper.js @@ -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, }