함수 공용화
This commit is contained in:
@@ -3,7 +3,7 @@ import { LinkPaymentWaitListProps } from '../../model/link-pay/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 LinkPaymentWaitList = ({
|
||||
additionalServiceCategory,
|
||||
@@ -68,62 +68,21 @@ export const LinkPaymentWaitList = ({
|
||||
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