Handle async updates in PeopleList

This commit is contained in:
Shailesh Pandit 2021-11-29 11:46:29 +05:30
parent 1d41644ac8
commit 7bfddfedce
2 changed files with 19 additions and 12 deletions

View file

@ -55,14 +55,19 @@ export interface PhotoPeopleListProps extends PeopleListPropsBase {
export function PhotoPeopleList(props: PhotoPeopleListProps) {
const [people, setPeople] = useState<Array<Person>>([]);
const updateFaceImages = async () => {
const people = await getPeopleList(props.file);
setPeople(people);
};
useEffect(() => {
// TODO: handle multiple async updates
let didCancel = false;
async function updateFaceImages() {
const people = await getPeopleList(props.file);
!didCancel && setPeople(people);
}
updateFaceImages();
return () => {
didCancel = true;
};
}, [props.file]);
return <PeopleList people={people} onSelect={props.onSelect}></PeopleList>;
@ -76,20 +81,22 @@ export function AllPeopleList(props: AllPeopleListProps) {
const [people, setPeople] = useState<Array<Person>>([]);
useEffect(() => {
// TODO: handle multiple async updates
let didCancel = false;
async function updateFaceImages() {
let people = await getAllPeople();
if (props.limit) {
people = people.slice(0, props.limit);
}
setPeople(people);
!didCancel && setPeople(people);
}
updateFaceImages();
return () => {
setPeople([]);
didCancel = true;
};
}, [props]);
}, [props.limit]);
return <PeopleList people={people} onSelect={props.onSelect}></PeopleList>;
}

View file

@ -229,8 +229,8 @@ export function findFirstIfSorted<T>(
}
export const DEFAULT_ML_SYNC_CONFIG: MLSyncConfig = {
syncIntervalSec: 5, // 300
batchSize: 5, // 200
syncIntervalSec: 5, // 20
batchSize: 200,
faceDetection: {
method: {
value: 'BlazeFace',