feat: expand all folders when in pr

This commit is contained in:
EnixCoda 2020-08-31 21:16:23 +08:00
parent 0515d3cb2d
commit e2aee2cdd6
No known key found for this signature in database
GPG key ID: 0C1A07377913A1DD
3 changed files with 14 additions and 3 deletions

View file

@ -68,11 +68,18 @@ export const setUpTree: BoundMethodCreator<[
})
visibleNodesGenerator.init()
tasksAfterRender.push(DOMHelper.focusSearchInput)
dispatch.set({ state: 'done' })
const targetPath = platform.getCurrentPath(metaData.branchName)
if (targetPath) dispatch.call(goTo, targetPath)
if (platform.shouldExpandAll?.()) {
visibleNodesGenerator.visibleNodes.nodes.forEach(node =>
dispatch.call(toggleNodeExpansion, node, { skipScrollToNode: true, recursive: true }),
)
dispatch.call(updateVisibleNodes)
} else {
const targetPath = platform.getCurrentPath(metaData.branchName)
if (targetPath) dispatch.call(goTo, targetPath)
}
}
export const execAfterRender: BoundMethodCreator = dispatch => () => {

View file

@ -203,6 +203,9 @@ export const GitHub: Platform = {
shouldShow() {
return Boolean(DOMHelper.isInCodePage() || URLHelper.isInPullPage())
},
shouldExpandAll() {
return Boolean(URLHelper.isInPullPage())
},
getCurrentPath(branchName) {
return URLHelper.getCurrentPath(branchName)
},

View file

@ -7,6 +7,7 @@ type Platform = {
): Promise<Pick<MetaData, 'userUrl' | 'repoUrl' | 'defaultBranchName'>>
getTreeData(metaData: MetaData, accessToken?: string): Promise<TreeNode>
shouldShow(): boolean
shouldExpandAll?(): boolean
getCurrentPath(branchName: string): string[] | null
setOAuth(code: string): Promise<string | null>
getOAuthLink(): string