import { ChangeEvent, useEffect, useState } from 'react'; import { useTranslation } from 'react-i18next'; import { PATHS } from '@/shared/constants/paths'; import { useNavigate } from '@/shared/lib/hooks/use-navigate'; import { useNoticeListMutation } from '@/entities/support/api/use-notice-list-mutation'; import { DEFAULT_PAGE_PARAM } from '@/entities/common/model/constant'; import { NoticeItem } from '@/entities/support/model/types'; import { SupportNoticeItem } from '@/entities/support/ui/notice-item'; import { HeaderType } from '@/entities/common/model/types'; import { useSetHeaderTitle, useSetHeaderType, useSetFooterMode, useSetOnBack } from '@/widgets/sub-layout/use-sub-layout'; export const NoticeListPage = () => { const { navigate } = useNavigate(); const { t } = useTranslation(); const [pageParam, setPageParam] = useState(DEFAULT_PAGE_PARAM); const [searchKeyword, setSearchKeyword] = useState(''); const [selectedCategory, setSelectedCategory] = useState('ALL'); const [resultList, setResultList] = useState>([]); useSetHeaderTitle(t('support.notice.title')); useSetHeaderType(HeaderType.LeftArrow); useSetFooterMode(false); useSetOnBack(() => { navigate(PATHS.home); }); const { mutateAsync: noticeList } = useNoticeListMutation(); const callList = () => { let listParams = { category: selectedCategory, searchKeyword: searchKeyword, ...{page: pageParam} }; noticeList(listParams).then((rs) => { console.log(rs) setResultList(rs.content); }); }; const onClickToAction = () => { // Remove focus from active element if (document.activeElement instanceof HTMLElement) { document.activeElement.blur(); } callList(); }; const getNoticeList = () => { let rs = []; for(let i=0;i ) } return rs; }; useEffect(() => { callList(); // eslint-disable-next-line react-hooks/exhaustive-deps }, [selectedCategory]); return ( <>
) => setSearchKeyword(e.target.value) } onKeyDown={ (e: React.KeyboardEvent) => { if (e.key === 'Enter' && !e.nativeEvent.isComposing) { onClickToAction(); } }} />
{ getNoticeList() }
); };