함수 공용화
This commit is contained in:
@@ -4,7 +4,7 @@ import { AdditionalServiceCategory } from "../../model/types";
|
||||
import { ListDateGroup } from "../list-date-group";
|
||||
import { useGroupDateOnStore, useGroupDateStore } from "@/shared/model/store";
|
||||
import { useEffect, useState } from "react";
|
||||
import { GetListHeight, IMAGE_ROOT, ListScrollOn } from "@/shared/constants/common";
|
||||
import { GetListHeight, IMAGE_ROOT, ListScrollOn, setScrollAction } from "@/shared/constants/common";
|
||||
|
||||
export const PayoutList = ({
|
||||
additionalServiceCategory,
|
||||
@@ -71,62 +71,21 @@ export const PayoutList = ({
|
||||
return rs;
|
||||
};
|
||||
|
||||
const getMax = (data: Array<Record<string, any>>) => {
|
||||
let maxItem = null;
|
||||
if(data.length > 0){
|
||||
let numberArr = data.map((
|
||||
value: Record<string, any>,
|
||||
index: number
|
||||
) => {
|
||||
return value.top;
|
||||
});
|
||||
let max = Math.max(...numberArr);
|
||||
maxItem = data.filter((
|
||||
value: Record<string, any>,
|
||||
index: number
|
||||
) => {
|
||||
return value.top === max;
|
||||
});
|
||||
}
|
||||
|
||||
return maxItem? maxItem[0]: null;
|
||||
};
|
||||
|
||||
const setScrollAction = (e: Event) => {
|
||||
let dateHeader = document.querySelectorAll('.date-header');
|
||||
let posData: Array<Record<string, any>> = [];
|
||||
dateHeader.forEach((value, index) => {
|
||||
let date: string = value.innerHTML;
|
||||
let top: number = value.getBoundingClientRect().top;
|
||||
if(top < 10){
|
||||
posData.push({
|
||||
date: date,
|
||||
top: top
|
||||
});
|
||||
}
|
||||
});
|
||||
let maxItem = getMax(posData);
|
||||
if(maxItem){
|
||||
setGroupDateOn(true);
|
||||
setGroupDate(maxItem.date);
|
||||
}
|
||||
else{
|
||||
setGroupDateOn(false);
|
||||
setGroupDate('');
|
||||
}
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
ListScrollOn(true);
|
||||
let heightList = GetListHeight();
|
||||
setListHeight(heightList.listHeight);
|
||||
|
||||
let tabContent = document.querySelector('.tab-content');
|
||||
tabContent?.addEventListener('scroll', setScrollAction);
|
||||
tabContent?.addEventListener('scroll', (e: Event) => {
|
||||
setScrollAction(e, setGroupDate, setGroupDateOn);
|
||||
});
|
||||
|
||||
return () => {
|
||||
ListScrollOn(false);
|
||||
tabContent?.removeEventListener('scroll', setScrollAction);
|
||||
tabContent?.removeEventListener('scroll', (e: Event) => {
|
||||
setScrollAction(e, setGroupDate, setGroupDateOn);
|
||||
});
|
||||
};
|
||||
}, []);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user