This commit is contained in:
chashaobao
2025-08-24 17:35:13 +08:00
parent 6a2c94c7cf
commit 2cb532c3d7
12 changed files with 148 additions and 71 deletions

View File

@ -1,3 +1,5 @@
import Taro from '@tarojs/taro';
import { List, PullRefresh } from '@taroify/core';
import classNames from 'classnames';
import { isEqual } from 'lodash-es';
@ -5,6 +7,7 @@ import { useCallback, useEffect, useRef, useState } from 'react';
import JobCard from '@/components/job-card';
import ListPlaceholder from '@/components/list-placeholder';
import { EventName } from '@/constants/app';
import { JobType, EmployType, SortType } from '@/constants/job';
import { JobInfo, GetJobsRequest } from '@/types/job';
import { logWithPrefix } from '@/utils/common';
@ -58,6 +61,23 @@ function JobList(props: IJobListProps) {
const prevRequestProps = useRef<IRequestProps>({});
const onListEmptyRef = useRef(onListEmpty);
const handleReadJob = useCallback(
(jobId: string) => {
const index = dataList.findIndex(d => String(d.id) === jobId);
if (index < 0) {
return;
}
const job = dataList[index];
if (!job || job.isRead) {
return;
}
log('auto mark read', jobId);
dataList.splice(index, 1, { ...job, isRead: true });
setDataList([...dataList]);
},
[dataList]
);
const handleRefresh = useCallback(async () => {
log('start pull refresh');
try {
@ -109,6 +129,13 @@ function JobList(props: IJobListProps) {
onListEmptyRef.current = onListEmpty;
}, [onListEmpty]);
useEffect(() => {
Taro.eventCenter.on(EventName.VIEW_JOB_SUCCESS, handleReadJob);
return () => {
Taro.eventCenter.off(EventName.VIEW_JOB_SUCCESS, handleReadJob);
};
}, [handleReadJob]);
useEffect(() => {
log('request params changed');
requestProps.current = {