Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

style: format code with Prettier and StandardJS #505

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 28 additions & 28 deletions src/components/hooks/useInViewport/index.jsx
Original file line number Diff line number Diff line change
@@ -1,35 +1,35 @@
import { useEffect, useRef, useState } from 'react';
import { useEffect, useRef, useState } from 'react'

Check failure on line 1 in src/components/hooks/useInViewport/index.jsx

View workflow job for this annotation

GitHub Actions / Qodana for JS

ESLint

ESLint: Install the 'eslint' package

const useInViewport = () => {
const inViewRef = useRef(null);
const [inViewport, setInViewport] = useState(false);
const inViewRef = useRef(null)
const [inViewport, setInViewport] = useState(false)

useEffect(() => {
const observer = new IntersectionObserver((entries) => {
entries.forEach((entry) => {
if (entry.isIntersecting) {
setInViewport(true);
} else {
setInViewport(false);
}
});
});

if (inViewRef.current) {
observer.observe(inViewRef.current);
useEffect(() => {
const observer = new IntersectionObserver((entries) => {
entries.forEach((entry) => {
if (entry.isIntersecting) {
setInViewport(true)
} else {
setInViewport(false)
}
})
})

if (inViewRef.current) {
observer.observe(inViewRef.current)
}

return () => {
if (inViewRef.current) {
observer.unobserve(inViewRef.current);
}
};
}, []);
return () => {
if (inViewRef.current) {
observer.unobserve(inViewRef.current)
}
}
}, [])

return {
inViewRef,
inViewport
};
};
return {
inViewRef,
inViewport
}
}

export default useInViewport;
export default useInViewport
93 changes: 46 additions & 47 deletions src/components/hooks/useScrollIntoView/index.jsx
Original file line number Diff line number Diff line change
@@ -1,60 +1,59 @@
import { useEffect, useRef, useState } from 'react';
import { useEffect, useRef, useState } from 'react'

Check failure on line 1 in src/components/hooks/useScrollIntoView/index.jsx

View workflow job for this annotation

GitHub Actions / Qodana for JS

ESLint

ESLint: Install the 'eslint' package

const useScrollIntoView = ({ offset = 0 }) => {
const targetRef = useRef < T > null
const [isScrolled, setIsScrolled] = useState(false)

const useScrollIntoView = ({offset = 0}) => {
const targetRef = useRef<T>(null);
const [isScrolled, setIsScrolled] = useState(false);
const scrollIntoView = () => {
if (targetRef.current) {
const rect = targetRef.current.getBoundingClientRect()
const scrollTop = window.pageYOffset || document.documentElement.scrollTop

Check notice on line 10 in src/components/hooks/useScrollIntoView/index.jsx

View workflow job for this annotation

GitHub Actions / Qodana for JS

Deprecated symbol used

Deprecated symbol used, consult docs for better alternative
const scrollLeft = window.pageXOffset || document.documentElement.scrollLeft

Check notice on line 11 in src/components/hooks/useScrollIntoView/index.jsx

View workflow job for this annotation

GitHub Actions / Qodana for JS

Deprecated symbol used

Deprecated symbol used, consult docs for better alternative
const elementTop = rect.top + scrollTop
const elementLeft = rect.left + scrollLeft

const scrollIntoView = () => {
if (targetRef.current) {
const rect = targetRef.current.getBoundingClientRect();
const scrollTop = window.pageYOffset || document.documentElement.scrollTop;
const scrollLeft = window.pageXOffset || document.documentElement.scrollLeft;
const elementTop = rect.top + scrollTop;
const elementLeft = rect.left + scrollLeft;
const windowHeight = window.innerHeight
const windowWidth = window.innerWidth

const windowHeight = window.innerHeight;
const windowWidth = window.innerWidth;
// 根据偏移量调整滚动位置
const adjustedTop = elementTop - offset
const adjustedLeft = elementLeft - offset

// 根据偏移量调整滚动位置
const adjustedTop = elementTop - offset;
const adjustedLeft = elementLeft - offset;
// 判断是否需要滚动
const shouldScrollY = adjustedTop < 0 || adjustedTop > windowHeight
const shouldScrollX = adjustedLeft < 0 || adjustedLeft > windowWidth

// 判断是否需要滚动
const shouldScrollY = adjustedTop < 0 || adjustedTop > windowHeight;
const shouldScrollX = adjustedLeft < 0 || adjustedLeft > windowWidth;
if (shouldScrollY) {
window.scrollTo({
top: shouldScrollY ? adjustedTop : scrollTop,
behavior: 'smooth'
})
}

if (shouldScrollY) {
window.scrollTo({
top: shouldScrollY? adjustedTop : scrollTop,
behavior: 'smooth'
});
}
if (shouldScrollX) {
window.scrollTo({
left: shouldScrollX ? adjustedLeft : scrollLeft,
behavior: 'smooth'
})
}

if (shouldScrollX) {
window.scrollTo({
left: shouldScrollX? adjustedLeft : scrollLeft,
behavior: 'smooth'
});
}
setIsScrolled(true)
}
}

setIsScrolled(true);
}
};
useEffect(() => {
if (isScrolled) {
setIsScrolled(false)
}
}, [isScrolled])

useEffect(() => {
if (isScrolled) {
setIsScrolled(false);
}
}, [isScrolled]);
return {
scrollIntoView,
targetRef
}
}

return {
scrollIntoView,
targetRef
};
};

export default useScrollIntoView;
export default useScrollIntoView

// const { scrollIntoView, targetRef } = useScrollIntoView({
// offset: 60
Expand All @@ -65,4 +64,4 @@
// <div ref={targetRef}>这是要滚动到的目标元素</div>
// <button onClick={scrollIntoView}>滚动到目标元素</button>
// </div>
// );
// );
60 changes: 30 additions & 30 deletions src/components/hooks/useWindowScroll/index.jsx
Original file line number Diff line number Diff line change
@@ -1,37 +1,37 @@
import { useState, useEffect } from 'react';
import { useState, useEffect } from 'react'

Check failure on line 1 in src/components/hooks/useWindowScroll/index.jsx

View workflow job for this annotation

GitHub Actions / Qodana for JS

ESLint

ESLint: Install the 'eslint' package

const useWindowScroll = () => {
// 用于存储窗口滚动位置的状态
const [scroll, setScroll] = useState({
x: window.pageXOffset,
y: window.pageYOffset
});
// 用于存储窗口滚动位置的状态
const [scroll, setScroll] = useState({
x: window.pageXOffset,

Check notice on line 6 in src/components/hooks/useWindowScroll/index.jsx

View workflow job for this annotation

GitHub Actions / Qodana for JS

Deprecated symbol used

Deprecated symbol used, consult docs for better alternative
y: window.pageYOffset

Check notice on line 7 in src/components/hooks/useWindowScroll/index.jsx

View workflow job for this annotation

GitHub Actions / Qodana for JS

Deprecated symbol used

Deprecated symbol used, consult docs for better alternative
})

// 用于更新滚动位置状态的函数
const handleScroll = () => {
setScroll({
x: window.pageXOffset,
y: window.pageYOffset
});
};
// 用于更新滚动位置状态的函数
const handleScroll = () => {
setScroll({
x: window.pageXOffset,

Check notice on line 13 in src/components/hooks/useWindowScroll/index.jsx

View workflow job for this annotation

GitHub Actions / Qodana for JS

Deprecated symbol used

Deprecated symbol used, consult docs for better alternative
y: window.pageYOffset

Check notice on line 14 in src/components/hooks/useWindowScroll/index.jsx

View workflow job for this annotation

GitHub Actions / Qodana for JS

Deprecated symbol used

Deprecated symbol used, consult docs for better alternative
})
}

// 在组件挂载时添加滚动事件监听器,在组件卸载时移除监听器
useEffect(() => {
window.addEventListener('scroll', handleScroll);
// 在组件挂载时添加滚动事件监听器,在组件卸载时移除监听器
useEffect(() => {
window.addEventListener('scroll', handleScroll)

return () => {
window.removeEventListener('scroll', handleScroll);
};
}, []);
return () => {
window.removeEventListener('scroll', handleScroll)
}
}, [])

// 返回滚动位置对象以及设置滚动位置的方法
return {
scroll,
setScroll: (newScroll) => {
window.scrollTo(newScroll.x, newScroll.y);
setScroll(newScroll);
}
};
};
// 返回滚动位置对象以及设置滚动位置的方法
return {
scroll,
setScroll: (newScroll) => {
window.scrollTo(newScroll.x, newScroll.y)
setScroll(newScroll)
}
}
}

export default useWindowScroll;
export default useWindowScroll
6 changes: 2 additions & 4 deletions src/components/stateless/SlideLinear/index.jsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import React from 'react'

Check failure on line 1 in src/components/stateless/SlideLinear/index.jsx

View workflow job for this annotation

GitHub Actions / Qodana for JS

ESLint

ESLint: Install the 'eslint' package
import styles from './index.module.less'
const SlideLinear = ({children}) => {
const SlideLinear = ({ children }) => {
return (
<div className={styles.slider}>
<div className={styles.content}>
{children}
</div>
<div className={styles.content}>{children}</div>
</div>
)
}
Expand Down
Loading
Loading