mirror of
https://github.com/EnixCoda/Gitako.git
synced 2026-03-11 08:54:44 +00:00
refactor: handle hash links natively
This commit is contained in:
parent
9050313ad1
commit
328a04f9bb
3 changed files with 16 additions and 6 deletions
|
|
@ -175,7 +175,7 @@ function ListView({
|
|||
width: number
|
||||
focusedNode: TreeNode | null
|
||||
searchKey: string
|
||||
onNodeClick(node: TreeNode): void
|
||||
onNodeClick(event: React.MouseEvent<HTMLElement, MouseEvent>, node: TreeNode): void
|
||||
renderActions?(node: TreeNode): React.ReactNode
|
||||
visibleNodes: VisibleNodes
|
||||
} & Pick<Props, 'metaData'> &
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ function getIconType(node: TreeNode) {
|
|||
|
||||
type Props = {
|
||||
node: TreeNode
|
||||
onClick(node: TreeNode): void
|
||||
onClick(event: React.MouseEvent<HTMLElement, MouseEvent>, node: TreeNode): void
|
||||
depth: number
|
||||
expanded: boolean
|
||||
focused: boolean
|
||||
|
|
@ -49,9 +49,8 @@ export function Node({
|
|||
// The default behavior, open in new tab
|
||||
return
|
||||
}
|
||||
event.preventDefault()
|
||||
|
||||
onClick(node)
|
||||
onClick(event, node)
|
||||
}}
|
||||
className={cx(`node-item`, { focused, disabled: node.accessDenied, expanded })}
|
||||
style={{ ...style, paddingLeft: `${10 + 20 * depth}px` }}
|
||||
|
|
|
|||
|
|
@ -230,18 +230,29 @@ export const focusNode: BoundMethodCreator<[TreeNode | null, boolean]> = dispatc
|
|||
dispatch.call(updateVisibleNodes)
|
||||
}
|
||||
|
||||
export const onNodeClick: BoundMethodCreator<[TreeNode]> = dispatch => node => {
|
||||
export const onNodeClick: BoundMethodCreator<[
|
||||
React.MouseEvent<HTMLElement, MouseEvent>,
|
||||
TreeNode,
|
||||
]> = dispatch => (event, node) => {
|
||||
let preventDefault = true
|
||||
if (node.type === 'tree') {
|
||||
dispatch.call(toggleNodeExpansion, node, true)
|
||||
} else if (node.type === 'blob') {
|
||||
const [, { loadWithPJAX }] = dispatch.get()
|
||||
dispatch.call(focusNode, node, true)
|
||||
if (node.url) loadWithPJAX(node.url)
|
||||
if (node.url) {
|
||||
if (node.url.startsWith('#')) {
|
||||
preventDefault = false
|
||||
} else {
|
||||
loadWithPJAX(node.url)
|
||||
}
|
||||
}
|
||||
} else if (node.type === 'commit') {
|
||||
if (node.url) {
|
||||
window.open(node.url, '_blank')
|
||||
}
|
||||
}
|
||||
if (preventDefault) event.preventDefault()
|
||||
}
|
||||
|
||||
export const expandTo: BoundMethodCreator<[string[]]> = dispatch => currentPath => {
|
||||
|
|
|
|||
Loading…
Reference in a new issue