mirror of
https://github.com/PeWu/topola-viewer.git
synced 2026-03-17 21:13:44 +00:00
Use getPeople WikiTree API instead of getAncestors (#262)
The getAncestors API is deprecated
This commit is contained in:
@@ -12,8 +12,8 @@ import {
|
|||||||
import {StringUtils} from 'turbocommons-ts';
|
import {StringUtils} from 'turbocommons-ts';
|
||||||
import {
|
import {
|
||||||
clientLogin,
|
clientLogin,
|
||||||
getAncestors as getAncestorsApi,
|
|
||||||
getLoggedInUserName,
|
getLoggedInUserName,
|
||||||
|
getPeople,
|
||||||
getRelatives as getRelativesApi,
|
getRelatives as getRelativesApi,
|
||||||
Person,
|
Person,
|
||||||
} from 'wikitree-js';
|
} from 'wikitree-js';
|
||||||
@@ -67,12 +67,19 @@ async function getAncestors(
|
|||||||
key: string,
|
key: string,
|
||||||
handleCors: boolean,
|
handleCors: boolean,
|
||||||
): Promise<Person[]> {
|
): Promise<Person[]> {
|
||||||
|
// Limit the number of generations of ancestors.
|
||||||
|
const ancestorsGenerationLimit = 5;
|
||||||
|
|
||||||
const cacheKey = `wikitree:ancestors:${key}`;
|
const cacheKey = `wikitree:ancestors:${key}`;
|
||||||
const cachedData = getSessionStorageItem(cacheKey);
|
const cachedData = getSessionStorageItem(cacheKey);
|
||||||
if (cachedData) {
|
if (cachedData) {
|
||||||
return JSON.parse(cachedData);
|
return JSON.parse(cachedData);
|
||||||
}
|
}
|
||||||
const result = await getAncestorsApi(key, {}, getApiOptions(handleCors));
|
const result = await getPeople(
|
||||||
|
[key],
|
||||||
|
{ancestors: ancestorsGenerationLimit},
|
||||||
|
getApiOptions(handleCors),
|
||||||
|
);
|
||||||
setSessionStorageItem(cacheKey, JSON.stringify(result));
|
setSessionStorageItem(cacheKey, JSON.stringify(result));
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user