Skip to content

Commit

Permalink
fix: 修复首页刷新跳动问题
Browse files Browse the repository at this point in the history
  • Loading branch information
konodioda727 committed Dec 25, 2024
1 parent c628aac commit 259c0b1
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 42 deletions.
58 changes: 24 additions & 34 deletions src/common/components/Comment/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,43 +61,33 @@ const CommentHeader: React.FC<CommentProps> = memo((props) => {

return (
<>
{!course_info ? (
<>
<View className="italic text-gray-400">加载中 ...</View>
</>
) : (
<>
<View className="classTitle" onClick={handleClickToClass}>
{course_info?.name
? `${course_info?.name} (${course_info?.teacher}) `
: '加载中 ...'}
</View>
</>
<View className="comment">
<>
<View className="classTitle" onClick={handleClickToClass}>
{`${course_info?.name} (${course_info?.teacher}) `}
<View
className="tx"
style={`background-image: url(${publisher_info?.avatar});`}
></View>
<View className="userName">{publisher_info?.nickname}</View>
<View className="time">
{' '}
{formatIsoDate(new Date(ctime as number).toISOString())}
</View>
<View className="stars">
<ShowStar score={star_rating}></ShowStar>
</View>
<Image
style={`display:${isHot ? 'block' : 'none'}`}
className="fire"
src="https://s2.loli.net/2023/11/12/2ITKRcDPMZaQCvk.png"
></Image>
</>
)}
<View className="comment">
{!publisher_info ? (
<>
<View className="italic text-gray-400">加载中 ...</View>
</>
) : (
<>
<View
className="tx"
style={`background-image: url(${publisher_info?.avatar});`}
></View>
<View className="userName">{publisher_info?.nickname}</View>
<View className="time">
{' '}
{formatIsoDate(new Date(ctime as number).toISOString())}
</View>
<View className="stars">
<ShowStar score={star_rating}></ShowStar>
</View>
<Image
style={`display:${isHot ? 'block' : 'none'}`}
className="fire"
src="https://s2.loli.net/2023/11/12/2ITKRcDPMZaQCvk.png"
></Image>
</>
)}
</View>
</>
);
Expand Down
2 changes: 1 addition & 1 deletion src/pages/classInfo/index.config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export default definePageConfig({
navigationBarTitleText: '课程主页',
navigationBarBackgroundColor: '#F9F9F2',
disableScroll: true,
// disableScroll: true,
});
18 changes: 11 additions & 7 deletions src/pages/main/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,9 @@ export default function Index() {
void dispatch
.refershComments()
.then(() => {
Taro.hideLoading();
setTimeout(() => {
Taro.hideLoading();
}, 1000);
})
.catch(() => {
Taro.hideLoading();
Expand Down Expand Up @@ -105,8 +107,12 @@ export default function Index() {
const geneHandler = () => {
let timeNow = Date.now();
return (e) => {
scrollTopMap.current = {
...scrollTopMap.current,
[classType]: scrollTopMap.current[classType] + 200,
};
if (!useCourseStore.getState().loading && Date.now() - timeNow > 1000) {
void Taro.showLoading({ title: '加载中...' });
void Taro.showLoading({ title: '加载中...', mask: true });
void dispatch
.loadMoreComments()
.then(() => {
Expand Down Expand Up @@ -171,17 +177,15 @@ export default function Index() {
current={Object.keys(COURSE_NAME_MAP).indexOf(classType)}
onChange={handleSwiperChange}
>
{Object.entries(scrollTopMap.current).map(([name]) => (
{/* eslint-disable-next-line @typescript-eslint/no-shadow */}
{Object.entries(scrollTopMap.current).map(([name, scrollTop]) => (
<SwiperItem key={name}>
<ScrollView
scrollWithAnimation
onScroll={handleScroll}
scrollAnimationDuration="300"
onScrollToLower={loadMoreHandler}
lowerThreshold={200}
refresherEnabled
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
scrollTop={scrollTopMap.current[name]}
scrollTop={scrollTop}
style={{ height: '70vh' }}
refresherTriggered={refresherTriggered}
scrollY
Expand Down

0 comments on commit 259c0b1

Please sign in to comment.