page update

This commit is contained in:
focp212@naver.com
2025-10-20 09:51:04 +09:00
parent 18d278465d
commit e3e4ec8b83
2 changed files with 90 additions and 64 deletions

View File

@@ -20,25 +20,6 @@ export const FaqListPage = () => {
const { t } = useTranslation(); const { t } = useTranslation();
const [onActionIntersect, setOnActionIntersect] = useState<boolean>(false); const [onActionIntersect, setOnActionIntersect] = useState<boolean>(false);
const onIntersect: IntersectionObserverCallback = (entries: Array<IntersectionObserverEntry>) => {
entries.forEach((entry: IntersectionObserverEntry) => {
if(entry.isIntersecting){
console.log('Element is now intersecting with the root. [' + onActionIntersect + ']');
if(onActionIntersect){
callList();
}
}
else{
console.log('Element is no longer intersecting with the root.');
}
});
};
const { setTarget } = useIntersectionObserver({
threshold: 1,
onIntersect
});
const [pageParam, setPageParam] = useState<DefaultRequestPagination>(DEFAULT_PAGE_PARAM); const [pageParam, setPageParam] = useState<DefaultRequestPagination>(DEFAULT_PAGE_PARAM);
const [nextCursor, setNextCursor] = useState<string | null>(null); const [nextCursor, setNextCursor] = useState<string | null>(null);
const [searchCl, setSearchCl] = useState<string | null>('HEAD'); const [searchCl, setSearchCl] = useState<string | null>('HEAD');
@@ -54,26 +35,59 @@ export const FaqListPage = () => {
}); });
const { mutateAsync: faqList } = useFaqListMutation(); const { mutateAsync: faqList } = useFaqListMutation();
const callList = () => {
const onIntersect: IntersectionObserverCallback = (entries: Array<IntersectionObserverEntry>) => {
entries.forEach((entry: IntersectionObserverEntry) => {
if(entry.isIntersecting){
console.log('Element is now intersecting with the root. [' + onActionIntersect + ']');
if(onActionIntersect && !!nextCursor){
callList('page');
}
}
else{
console.log('Element is no longer intersecting with the root.');
}
});
};
const { setTarget } = useIntersectionObserver({
threshold: 1,
onIntersect
});
const callList = (type?: string) => {
setOnActionIntersect(false); setOnActionIntersect(false);
let listParams: FaqListParams = { let listParams: FaqListParams = {
category: selectedCategory, category: selectedCategory,
searchCl: (!!searchValue)? searchCl: null, searchCl: (!!searchValue)? searchCl: null,
searchValue: searchValue, searchValue: searchValue,
...{page: pageParam} ...{
page: pageParam
}
}; };
if(type === 'page'){
if(listParams.page){
listParams.page.cursor = nextCursor;
}
}
else{
setNextCursor(null);
if(listParams.page){
listParams.page.cursor = null;
}
}
faqList(listParams).then((rs: FaqListResponse) => { faqList(listParams).then((rs: FaqListResponse) => {
if(type === 'page'){
setResultList([ setResultList([
...resultList, ...resultList,
...rs.content ...rs.content
]); ]);
}
else{
setResultList(rs.content);
}
if(rs.hasNext){ if(rs.hasNext){
setNextCursor(rs.nextCursor); setNextCursor(rs.nextCursor);
setPageParam({
...pageParam,
cursor: rs.nextCursor
});
setOnActionIntersect(true); setOnActionIntersect(true);
} }
else{ else{
@@ -113,8 +127,8 @@ export const FaqListPage = () => {
}; };
useEffect(() => { useEffect(() => {
setNextCursor(null);
callList(); callList();
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [selectedCategory]); }, [selectedCategory]);
return ( return (

View File

@@ -18,31 +18,12 @@ import useIntersectionObserver from '@/widgets/intersection-observer';
export const QnaListPage = () => { export const QnaListPage = () => {
const { navigate } = useNavigate(); const { navigate } = useNavigate();
const { t } = useTranslation();
const [onActionIntersect, setOnActionIntersect] = useState<boolean>(false);
const onIntersect: IntersectionObserverCallback = (entries: Array<IntersectionObserverEntry>) => {
entries.forEach((entry: IntersectionObserverEntry) => {
if(entry.isIntersecting){
console.log('Element is now intersecting with the root. [' + onActionIntersect + ']');
if(onActionIntersect){
callList();
}
}
else{
console.log('Element is no longer intersecting with the root.');
}
});
};
const { setTarget } = useIntersectionObserver({
threshold: 1,
onIntersect
});
const midOptions = useStore.getState().UserStore.selectOptionsMids; const midOptions = useStore.getState().UserStore.selectOptionsMids;
const userMid = useStore.getState().UserStore.mid; const userMid = useStore.getState().UserStore.mid;
const { t } = useTranslation();
const [onActionIntersect, setOnActionIntersect] = useState<boolean>(false);
const [mid, setMid] = useState<string>(userMid); const [mid, setMid] = useState<string>(userMid);
const [pageParam, setPageParam] = useState<DefaultRequestPagination>(DEFAULT_PAGE_PARAM); const [pageParam, setPageParam] = useState<DefaultRequestPagination>(DEFAULT_PAGE_PARAM);
const [nextCursor, setNextCursor] = useState<string | null>(null); const [nextCursor, setNextCursor] = useState<string | null>(null);
@@ -57,7 +38,27 @@ export const QnaListPage = () => {
}); });
const { mutateAsync: qnaList } = useQnaListMutation(); const { mutateAsync: qnaList } = useQnaListMutation();
const callList = () => {
const onIntersect: IntersectionObserverCallback = (entries: Array<IntersectionObserverEntry>) => {
entries.forEach((entry: IntersectionObserverEntry) => {
if(entry.isIntersecting){
console.log('Element is now intersecting with the root. [' + onActionIntersect + ']');
if(onActionIntersect && !!nextCursor){
callList('page');
}
}
else{
console.log('Element is no longer intersecting with the root.');
}
});
};
const { setTarget } = useIntersectionObserver({
threshold: 1,
onIntersect
});
const callList = (type?: string) => {
setOnActionIntersect(false); setOnActionIntersect(false);
let listParams: QnaListParams = { let listParams: QnaListParams = {
mid: mid, mid: mid,
@@ -66,18 +67,30 @@ export const QnaListPage = () => {
page: pageParam page: pageParam
} }
}; };
if(type === 'page'){
if(listParams.page){
listParams.page.cursor = nextCursor;
}
}
else{
setNextCursor(null);
if(listParams.page){
listParams.page.cursor = null;
}
}
qnaList(listParams).then((rs: QnaListResponse) => { qnaList(listParams).then((rs: QnaListResponse) => {
if(type === 'page'){
setResultList([ setResultList([
...resultList, ...resultList,
...rs.content ...rs.content
]); ]);
}
else{
setResultList(rs.content);
}
if(rs.hasNext){ if(rs.hasNext){
setNextCursor(rs.nextCursor); setNextCursor(rs.nextCursor);
setPageParam({
...pageParam,
cursor: rs.nextCursor
});
setOnActionIntersect(true); setOnActionIntersect(true);
} }
else{ else{
@@ -86,8 +99,6 @@ export const QnaListPage = () => {
}); });
}; };
const getQnaList = () => { const getQnaList = () => {
let rs = []; let rs = [];
for(let i=0;i<resultList.length;i++){ for(let i=0;i<resultList.length;i++){
@@ -115,6 +126,7 @@ export const QnaListPage = () => {
}; };
useEffect(() => { useEffect(() => {
setNextCursor(null);
callList(); callList();
}, [statusCode]); }, [statusCode]);