함수 공용화
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import moment from 'moment';
|
||||
import { useEffect, useState } from 'react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { GetListHeight, IMAGE_ROOT, ListScrollOn } from '@/shared/constants/common';
|
||||
import { GetListHeight, IMAGE_ROOT, ListScrollOn, setScrollAction } from '@/shared/constants/common';
|
||||
import { ListFilter } from './filter/list-filter';
|
||||
import { SortTypeBox } from '@/entities/common/ui/sort-type-box';
|
||||
import { DefaultRequestPagination, SortTypeKeys } from '@/entities/common/model/types';
|
||||
@@ -214,51 +214,6 @@ export const ListWrap = () => {
|
||||
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(() => {
|
||||
callList();
|
||||
}, [
|
||||
@@ -272,11 +227,15 @@ export const ListWrap = () => {
|
||||
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