mirror of
https://github.com/EnixCoda/Gitako.git
synced 2026-03-11 08:54:44 +00:00
refactor: remove warnings
This commit is contained in:
parent
9f4e2b51e0
commit
79c1c82b65
8 changed files with 98 additions and 115 deletions
|
|
@ -19,25 +19,19 @@ class RawFileExplorer extends React.Component<Props & ConnectorState> {
|
|||
visibleNodes: null,
|
||||
}
|
||||
|
||||
componentWillMount() {
|
||||
componentDidMount() {
|
||||
const { init, setUpTree, treeData, metaData, compressSingletonFolder, accessToken } = this.props
|
||||
init()
|
||||
setUpTree({ treeData, metaData, compressSingletonFolder, accessToken })
|
||||
}
|
||||
|
||||
componentDidMount() {
|
||||
const { execAfterRender } = this.props
|
||||
execAfterRender()
|
||||
}
|
||||
|
||||
componentWillReceiveProps(nextProps: Props & ConnectorState) {
|
||||
if (nextProps.treeData !== this.props.treeData) {
|
||||
const { setUpTree, treeData, metaData, compressSingletonFolder, accessToken } = nextProps
|
||||
componentDidUpdate(prevProps: Props & ConnectorState) {
|
||||
if (this.props.treeData !== prevProps.treeData) {
|
||||
const { setUpTree, treeData, metaData, compressSingletonFolder, accessToken } = this.props
|
||||
setUpTree({ treeData, metaData, compressSingletonFolder, accessToken })
|
||||
}
|
||||
}
|
||||
|
||||
componentDidUpdate() {
|
||||
const { execAfterRender } = this.props
|
||||
execAfterRender()
|
||||
}
|
||||
|
|
@ -114,7 +108,7 @@ class RawFileExplorer extends React.Component<Props & ConnectorState> {
|
|||
)
|
||||
})
|
||||
|
||||
private renderActions: Node['props']['renderActions'] = node => {
|
||||
private renderActions: React.ComponentProps<typeof Node>['renderActions'] = node => {
|
||||
const { searchKey, goTo } = this.props
|
||||
return (
|
||||
searchKey && (
|
||||
|
|
|
|||
|
|
@ -24,42 +24,42 @@ type Props = {
|
|||
renderActions?(node: TreeNode): React.ReactNode
|
||||
style?: React.CSSProperties
|
||||
}
|
||||
export class Node extends React.PureComponent<Props> {
|
||||
onClick: React.MouseEventHandler = event => {
|
||||
if (
|
||||
(os === OperatingSystems.macOS && event.metaKey) ||
|
||||
(os === OperatingSystems.Windows && event.ctrlKey)
|
||||
) {
|
||||
// Open in new tab
|
||||
return
|
||||
}
|
||||
event.preventDefault()
|
||||
const { node, onClick } = this.props
|
||||
onClick(node)
|
||||
}
|
||||
export function Node({ node, depth, expanded, focused, renderActions, style, onClick }: Props) {
|
||||
const onClickNode: React.MouseEventHandler = React.useCallback(
|
||||
event => {
|
||||
if (
|
||||
(os === OperatingSystems.macOS && event.metaKey) ||
|
||||
(os === OperatingSystems.Windows && event.ctrlKey)
|
||||
) {
|
||||
// The default behavior, open in new tab
|
||||
return
|
||||
}
|
||||
event.preventDefault()
|
||||
|
||||
render() {
|
||||
const { node, depth, expanded, focused, renderActions, style } = this.props
|
||||
const { name, path } = node
|
||||
return (
|
||||
<div
|
||||
className={cx(`node-item-row`, { focused, disabled: node.accessDenied })}
|
||||
style={style}
|
||||
title={path}
|
||||
>
|
||||
<a href={node.url} onClick={this.onClick}>
|
||||
<div
|
||||
className={cx('node-item', { expanded })}
|
||||
style={{ paddingLeft: `${10 + 20 * depth}px` }}
|
||||
>
|
||||
<div className={'node-item-label'}>
|
||||
<Icon type={getIconType(node)} />
|
||||
<span className={'node-item-name'}>{name}</span>
|
||||
</div>
|
||||
{renderActions && <div>{renderActions(node)}</div>}
|
||||
onClick(node)
|
||||
},
|
||||
[node, onClick],
|
||||
)
|
||||
|
||||
const { name, path } = node
|
||||
return (
|
||||
<div
|
||||
className={cx(`node-item-row`, { focused, disabled: node.accessDenied })}
|
||||
style={style}
|
||||
title={path}
|
||||
>
|
||||
<a href={node.url} onClick={onClickNode}>
|
||||
<div
|
||||
className={cx('node-item', { expanded })}
|
||||
style={{ paddingLeft: `${10 + 20 * depth}px` }}
|
||||
>
|
||||
<div className={'node-item-label'}>
|
||||
<Icon type={getIconType(node)} />
|
||||
<span className={'node-item-name'}>{name}</span>
|
||||
</div>
|
||||
</a>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
{renderActions && <div>{renderActions(node)}</div>}
|
||||
</div>
|
||||
</a>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,10 +5,8 @@ type Props = {
|
|||
into: Element | null
|
||||
}
|
||||
|
||||
export class Portal extends React.PureComponent<Props> {
|
||||
render() {
|
||||
const { into, children } = this.props
|
||||
if (!(into instanceof Element)) return null
|
||||
return ReactDOM.createPortal(children, into)
|
||||
}
|
||||
export function Portal(props: React.PropsWithChildren<Props>) {
|
||||
const { into, children } = props
|
||||
if (!(into instanceof Element)) return null
|
||||
return ReactDOM.createPortal(children, into)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,51 +8,46 @@ type Props = {
|
|||
style?: React.CSSProperties
|
||||
}
|
||||
|
||||
export class HorizontalResizeHandler extends React.PureComponent<Props> {
|
||||
pointerDown = false
|
||||
startX = 0
|
||||
baseSize = this.props.size
|
||||
export function HorizontalResizeHandler({ onResize, size, style }: Props) {
|
||||
const pointerDown = React.useRef(false)
|
||||
const startX = React.useRef(0)
|
||||
const baseSize = React.useRef(size)
|
||||
const latestPropSize = React.useRef(size)
|
||||
|
||||
componentWillReceiveProps(nextProps: Props) {
|
||||
if (!this.pointerDown) {
|
||||
// update baseSize when not resizing
|
||||
this.baseSize = nextProps.size
|
||||
React.useEffect(() => {
|
||||
latestPropSize.current = size
|
||||
}, [size])
|
||||
|
||||
const onPointerDown = React.useCallback(({ clientX }: React.MouseEvent) => {
|
||||
startX.current = clientX
|
||||
pointerDown.current = true
|
||||
baseSize.current = latestPropSize.current
|
||||
}, [])
|
||||
|
||||
React.useEffect(() => {
|
||||
const onPointerMove = ({ clientX }: MouseEvent) => {
|
||||
if (!pointerDown.current) return
|
||||
const shift = clientX - startX.current
|
||||
onResize(baseSize.current + shift)
|
||||
}
|
||||
}
|
||||
window.addEventListener('mousemove', onPointerMove)
|
||||
return () => window.removeEventListener('mousemove', onPointerMove)
|
||||
}, [onResize])
|
||||
|
||||
subscribeEvents = () => {
|
||||
window.addEventListener('mousemove', this.onPointerMove)
|
||||
window.addEventListener('mouseup', this.onPointerUp)
|
||||
}
|
||||
React.useEffect(() => {
|
||||
const onPointerUp = () => {
|
||||
if (pointerDown.current) {
|
||||
pointerDown.current = false
|
||||
baseSize.current = latestPropSize.current
|
||||
}
|
||||
}
|
||||
window.addEventListener('mouseup', onPointerUp)
|
||||
return () => window.removeEventListener('mouseup', onPointerUp)
|
||||
}, [])
|
||||
|
||||
unsubscribeEvents = () => {
|
||||
window.removeEventListener('mousemove', this.onPointerMove)
|
||||
window.removeEventListener('mouseup', this.onPointerUp)
|
||||
}
|
||||
|
||||
onPointerDown = ({ clientX }: React.MouseEvent) => {
|
||||
this.startX = clientX
|
||||
this.pointerDown = true
|
||||
this.subscribeEvents()
|
||||
}
|
||||
|
||||
onPointerMove = ({ clientX }: MouseEvent) => {
|
||||
if (!this.pointerDown) return
|
||||
this.props.onResize(clientX - this.startX + this.baseSize)
|
||||
}
|
||||
|
||||
onPointerUp = () => {
|
||||
this.pointerDown = false
|
||||
this.baseSize = this.props.size
|
||||
this.unsubscribeEvents()
|
||||
}
|
||||
|
||||
render() {
|
||||
const { style } = this.props
|
||||
return (
|
||||
<div className={'gitako-resize-handler'} onMouseDown={this.onPointerDown} style={style}>
|
||||
<Icon type={'grabber'} className={'grabber-icon'} />
|
||||
</div>
|
||||
)
|
||||
}
|
||||
return (
|
||||
<div className={'gitako-resize-handler'} onMouseDown={onPointerDown} style={style}>
|
||||
<Icon type={'grabber'} className={'grabber-icon'} />
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -104,9 +104,9 @@ export class SettingsBar extends React.PureComponent<Props, State> {
|
|||
if (!this.props.accessToken) this.trySetUpAccessTokenWithCode()
|
||||
}
|
||||
|
||||
componentWillReceiveProps({ toggleShowSideBarShortcut }: Props) {
|
||||
componentDidUpdate({ toggleShowSideBarShortcut }: Props) {
|
||||
if (toggleShowSideBarShortcut !== this.props.toggleShowSideBarShortcut) {
|
||||
this.setState({ toggleShowSideBarShortcut })
|
||||
this.setState({ toggleShowSideBarShortcut: this.props.toggleShowSideBarShortcut })
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -24,13 +24,9 @@ class RawGitako extends React.PureComponent<Props & ConnectorState> {
|
|||
disabled: false,
|
||||
}
|
||||
|
||||
componentWillMount() {
|
||||
const { init } = this.props
|
||||
init()
|
||||
}
|
||||
|
||||
componentDidMount() {
|
||||
const { useListeners } = this.props
|
||||
const { init, useListeners } = this.props
|
||||
init()
|
||||
useListeners(true)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -19,6 +19,16 @@ export function SizeObserver({ type = 'div', children, ...rest }: Props) {
|
|||
height: undefined,
|
||||
})
|
||||
|
||||
const safeSetSize = React.useCallback(function safeSetSize(rect: DOMRectReadOnly) {
|
||||
// requestAnimationFrame fixes "ResizeObserver loop limit exceeded" error
|
||||
requestAnimationFrame(() =>
|
||||
setSize({
|
||||
width: rect.width,
|
||||
height: rect.height,
|
||||
}),
|
||||
)
|
||||
}, [])
|
||||
|
||||
React.useLayoutEffect(() => {
|
||||
if (features.resize) {
|
||||
const observer = new window.ResizeObserver(entries => {
|
||||
|
|
@ -43,14 +53,4 @@ export function SizeObserver({ type = 'div', children, ...rest }: Props) {
|
|||
const props: any = { ...rest, ref } // :)
|
||||
|
||||
return React.createElement(type, props, children(size))
|
||||
|
||||
function safeSetSize(rect: DOMRectReadOnly) {
|
||||
// requestAnimationFrame fixes "ResizeObserver loop limit exceeded" error
|
||||
requestAnimationFrame(() =>
|
||||
setSize({
|
||||
width: rect.width,
|
||||
height: rect.height,
|
||||
}),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -102,7 +102,7 @@ export function insertLogoMountPoint() {
|
|||
|
||||
function createLogoMountPoint() {
|
||||
const logoMountElement = document.createElement('div')
|
||||
logoMountElement.setAttribute('class', 'gitako-logo-mount-point')
|
||||
logoMountElement.classList.add('gitako-logo-mount-point')
|
||||
document.body.appendChild(logoMountElement)
|
||||
return logoMountElement
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue