diff --git a/src/components/partner-invite-list/index.tsx b/src/components/partner-invite-list/index.tsx index f882032..79c5384 100644 --- a/src/components/partner-invite-list/index.tsx +++ b/src/components/partner-invite-list/index.tsx @@ -12,6 +12,8 @@ import './index.less'; const PREFIX = 'partner-invite-list'; const log = logWithPrefix(PREFIX); +const FIRST_PAGE = 0; + function PartnerList(props: { refreshDisabled?: boolean; visible?: boolean; @@ -20,10 +22,12 @@ function PartnerList(props: { onListEmpty?: () => void; }) { const { className, listHeight, refreshDisabled, visible = true, onListEmpty } = props; + const [hasMore, setHasMore] = useState(true); const [refreshing, setRefreshing] = useState(false); const [loadingMore, setLoadingMore] = useState(false); const [loadMoreError, setLoadMoreError] = useState(false); const [dataList, setDataList] = useState([]); + const currentPage = useRef(FIRST_PAGE); const onListEmptyRef = useRef(onListEmpty); const handleRefresh = useCallback(async () => { @@ -31,19 +35,44 @@ function PartnerList(props: { try { setRefreshing(true); setLoadMoreError(false); - const list = await requestData(); - setDataList(list); - !list.length && onListEmptyRef.current?.(); + const { content, totalPages } = await requestData({ page: 1 }); + setDataList(content); + currentPage.current = 1; + setHasMore(currentPage.current < totalPages); + !content.length && onListEmptyRef.current?.(); log('pull refresh success'); } catch (e) { setDataList([]); + setHasMore(false); setLoadMoreError(true); + currentPage.current = FIRST_PAGE; log('pull refresh failed'); } finally { setRefreshing(false); } }, []); + const handleLoadMore = useCallback(async () => { + log('start load more', hasMore); + if (!hasMore) { + return; + } + setLoadMoreError(false); + setLoadingMore(true); + try { + const { totalPages, content } = await requestData({ page: currentPage.current + 1 }); + setDataList([...dataList, ...content]); + currentPage.current = currentPage.current + 1; + setHasMore(currentPage.current < totalPages); + log('load more success'); + } catch (e) { + setLoadMoreError(true); + log('load more failed'); + } finally { + setLoadingMore(false); + } + }, [dataList, hasMore]); + useEffect(() => { onListEmptyRef.current = onListEmpty; }, [onListEmpty]); @@ -62,11 +91,14 @@ function PartnerList(props: { setDataList([]); setLoadingMore(true); setLoadMoreError(false); - const list = await requestData(); - setDataList(list); - !list.length && onListEmptyRef.current?.(); + const { totalPages, content } = await requestData({ page: 1 }); + setDataList(content); + currentPage.current = 1; + setHasMore(currentPage.current < totalPages); + !content.length && onListEmptyRef.current?.(); } catch (e) { setDataList([]); + setHasMore(false); setLoadMoreError(true); } finally { log('visible changed, refresh list data end'); @@ -90,8 +122,8 @@ function PartnerList(props: { disabled={refreshDisabled} > {}} + hasMore={hasMore} + onLoad={handleLoadMore} loading={loadingMore || refreshing} disabled={loadMoreError} fixedHeight={typeof listHeight !== 'undefined'} diff --git a/src/pages/anchor/index.tsx b/src/pages/anchor/index.tsx index e0cc517..5ad6fd4 100644 --- a/src/pages/anchor/index.tsx +++ b/src/pages/anchor/index.tsx @@ -27,8 +27,7 @@ import { logWithPrefix } from '@/utils/common'; import { getLastSelectMyJobId, requestJobManageList, setLastSelectMyJobId } from '@/utils/job'; import { getWxLocation } from '@/utils/location'; import { requestUnreadMessageCount } from '@/utils/message'; -import { getInviteCodeFromQueryAndUpdate } from '@/utils/partner'; -import { getPageQuery, navigateTo } from '@/utils/route'; +import { navigateTo } from '@/utils/route'; import { getCommonShareMessage } from '@/utils/share'; import Toast from '@/utils/toast'; import './index.less'; @@ -165,9 +164,6 @@ export default function AnchorPage() { }, [location]); useLoad(async () => { - const query = getPageQuery(); - getInviteCodeFromQueryAndUpdate(query); - try { const { jobResults = [] } = await requestJobManageList({ status: JobManageStatus.Open }); if (!jobResults.length) { diff --git a/src/pages/group-v2/index.tsx b/src/pages/group-v2/index.tsx index be3f6d0..498cf32 100644 --- a/src/pages/group-v2/index.tsx +++ b/src/pages/group-v2/index.tsx @@ -1,4 +1,4 @@ -import { useLoad, useShareAppMessage } from '@tarojs/taro'; +import { useShareAppMessage } from '@tarojs/taro'; import { useCallback } from 'react'; @@ -8,8 +8,6 @@ import { GROUPS } from '@/constants/group'; import useInviteCode from '@/hooks/use-invite-code'; import { openCustomerServiceChat } from '@/utils/common'; import { getCurrentCityCode } from '@/utils/location'; -import { getInviteCodeFromQueryAndUpdate } from '@/utils/partner'; -import { getPageQuery } from '@/utils/route'; import { getCommonShareMessage } from '@/utils/share'; import './index.less'; @@ -18,11 +16,6 @@ const PREFIX = 'group-v2-page'; export default function GroupV2() { const inviteCode = useInviteCode(); - useLoad(() => { - const query = getPageQuery(); - getInviteCodeFromQueryAndUpdate(query); - }); - useShareAppMessage(() => getCommonShareMessage(true, inviteCode)); const handleSelectCity = useCallback(cityCode => { diff --git a/src/pages/job-detail/index.tsx b/src/pages/job-detail/index.tsx index a939a34..c4a3ce1 100644 --- a/src/pages/job-detail/index.tsx +++ b/src/pages/job-detail/index.tsx @@ -28,7 +28,6 @@ import { getJobTitle, getJobSalary, postPublishJob, requestJobDetail } from '@/u import { calcDistance, isValidLocation } from '@/utils/location'; import { requestProfileDetail } from '@/utils/material'; import { isChatWithSelf, postCreateChat } from '@/utils/message'; -import { getInviteCodeFromQueryAndUpdate } from '@/utils/partner'; import { getJumpUrl, getPageQuery, navigateTo } from '@/utils/route'; import { getCommonShareMessage } from '@/utils/share'; import { formatDate } from '@/utils/time'; @@ -219,8 +218,7 @@ export default function JobDetail() { }, []); useLoad(async () => { - const query = getPageQuery & { c: string }>(); - getInviteCodeFromQueryAndUpdate(query); + const query = getPageQuery>(); const jobId = query?.id; if (!jobId) { return; diff --git a/src/pages/job/index.tsx b/src/pages/job/index.tsx index 384c54b..303b772 100644 --- a/src/pages/job/index.tsx +++ b/src/pages/job/index.tsx @@ -17,7 +17,6 @@ import { Coordinate } from '@/types/location'; import { logWithPrefix } from '@/utils/common'; import { getWxLocation, isNotNeedAuthorizeLocation, requestLocation } from '@/utils/location'; import { requestUnreadMessageCount } from '@/utils/message'; -import { getInviteCodeFromQueryAndUpdate } from '@/utils/partner'; import { getJumpUrl, getPageQuery, navigateTo } from '@/utils/route'; import { getCommonShareMessage } from '@/utils/share'; import Toast from '@/utils/toast'; @@ -109,7 +108,6 @@ export default function Job() { if (type === SortType.CREATE_TIME) { setSortType(type); } - getInviteCodeFromQueryAndUpdate(query); if (await isNotNeedAuthorizeLocation()) { log('not need authorize location'); requestLocation(); diff --git a/src/pages/material-view/index.tsx b/src/pages/material-view/index.tsx index 442faa3..8451b8b 100644 --- a/src/pages/material-view/index.tsx +++ b/src/pages/material-view/index.tsx @@ -21,7 +21,6 @@ import { collectEvent } from '@/utils/event'; import { requestHasPublishedJob, requestJobDetail } from '@/utils/job'; import { getMaterialShareMessage, requestReadProfile, requestShareProfile } from '@/utils/material'; import { isChatWithSelf, postCreateChat } from '@/utils/message'; -import { getInviteCodeFromQueryAndUpdate } from '@/utils/partner'; import { getPageQuery, navigateBack, navigateTo, redirectTo } from '@/utils/route'; import Toast from '@/utils/toast'; import './index.less'; @@ -142,7 +141,6 @@ export default function MaterialViewPage() { useLoad(async () => { const context = getPageQuery(); - getInviteCodeFromQueryAndUpdate(context as BL.Anything); try { const profileDetail = await requestProfile(context); setProfile(profileDetail); diff --git a/src/utils/partner.ts b/src/utils/partner.ts index ac85582..d48ee2a 100644 --- a/src/utils/partner.ts +++ b/src/utils/partner.ts @@ -5,6 +5,7 @@ import http from '@/http'; import { API } from '@/http/api'; import store from '@/store'; import { setInviteCode } from '@/store/actions/partner'; +import { IPaginationRequest } from '@/types/common'; import { GetProfitRequest, InviteUserInfo, @@ -51,8 +52,11 @@ export const getPartnerQrcode = async () => { export const getPartnerProfitStat = async () => { return await http.post(API.GET_PROFIT_STAT); }; -export const getPartnerInviteList = async () => { - return await http.post(API.GET_INVITE_LIST); +export const getPartnerInviteList = async (data: IPaginationRequest) => { + return await http.post<{ content: InviteUserInfo[]; totalPages: number }>(API.GET_INVITE_LIST, { + data, + contentType: 'application/x-www-form-urlencoded', + }); }; export const dispatchUpdateInviteCode = (code: string) => store.dispatch(setInviteCode(code)); export const getInviteCode = async () => {