함수 공용화
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import packageInfo from '../../../package.json';
|
||||
import { useGroupDateOnStore, useGroupDateStore } from '../model/store';
|
||||
|
||||
export const IMAGE_ROOT = '/images';
|
||||
export const RELEASE_VERSION = packageInfo.version;
|
||||
@@ -32,4 +33,53 @@ export const GetListHeight = () => {
|
||||
filterSectionHeight: filterSectionHeight,
|
||||
listHeight: innerHeight - headerHeight - summarySectionHeight - filterSectionHeight
|
||||
}
|
||||
};
|
||||
|
||||
export 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;
|
||||
};
|
||||
|
||||
export const setScrollAction = (
|
||||
e: Event,
|
||||
setGroupDate: (groupDate: string) => void,
|
||||
setGroupDateOn: (groupDateOn: boolean) => void
|
||||
) => {
|
||||
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('');
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user