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) { export function PhotoPeopleList(props: PhotoPeopleListProps) {
const [people, setPeople] = useState<Array<Person>>([]); const [people, setPeople] = useState<Array<Person>>([]);
const updateFaceImages = async () => {
const people = await getPeopleList(props.file);
setPeople(people);
};
useEffect(() => { useEffect(() => {
// TODO: handle multiple async updates let didCancel = false;
async function updateFaceImages() {
const people = await getPeopleList(props.file);
!didCancel && setPeople(people);
}
updateFaceImages(); updateFaceImages();
return () => {
didCancel = true;
};
}, [props.file]); }, [props.file]);
return <PeopleList people={people} onSelect={props.onSelect}></PeopleList>; return <PeopleList people={people} onSelect={props.onSelect}></PeopleList>;
@ -76,20 +81,22 @@ export function AllPeopleList(props: AllPeopleListProps) {
const [people, setPeople] = useState<Array<Person>>([]); const [people, setPeople] = useState<Array<Person>>([]);
useEffect(() => { useEffect(() => {
// TODO: handle multiple async updates let didCancel = false;
async function updateFaceImages() { async function updateFaceImages() {
let people = await getAllPeople(); let people = await getAllPeople();
if (props.limit) { if (props.limit) {
people = people.slice(0, props.limit); people = people.slice(0, props.limit);
} }
setPeople(people); !didCancel && setPeople(people);
} }
updateFaceImages(); updateFaceImages();
return () => { return () => {
setPeople([]); didCancel = true;
}; };
}, [props]); }, [props.limit]);
return <PeopleList people={people} onSelect={props.onSelect}></PeopleList>; 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 = { export const DEFAULT_ML_SYNC_CONFIG: MLSyncConfig = {
syncIntervalSec: 5, // 300 syncIntervalSec: 5, // 20
batchSize: 5, // 200 batchSize: 200,
faceDetection: { faceDetection: {
method: { method: {
value: 'BlazeFace', value: 'BlazeFace',