Skip to content

Commit

Permalink
chore(personresolver): updating personresolver to align with fusion-f…
Browse files Browse the repository at this point in the history
…ramework-cli
  • Loading branch information
eikeland committed Nov 1, 2023
1 parent a2c77a3 commit ba17297
Showing 1 changed file with 23 additions and 32 deletions.
55 changes: 23 additions & 32 deletions src/start-app/components/PersonResolver/usePersonResolver.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,49 +8,40 @@ const createPersonClient = (client: IHttpClient) => {
// TODO - good cache amount? 3min?
const expire = 3 * 60 * 1000;
const queryDetails = new Query({
expire,
queueOperator: 'merge',
key: (azureId) => azureId,
client: {
fn: async (azureId: string) => {
const user = await client.json<PersonDetails>(`/persons/${azureId}?api-version=4.0&$expand=positions,manager`);

try {
const image = await client.json<string>(`/persons/${azureId}/photo?api-version=1.0`);
user.pictureSrc = image;
} catch (error) {
// for default image (user.pictureSrc = '/images/profiles/');
console.error(error);
}

return user;
expire,
queueOperator: 'merge',
key: (azureId) => azureId,
client: {
fn: (azureId: string) => {
return client.json<PersonDetails>(`/persons/${azureId}?api-version=4.0`);
},
},
},
});

const queryPresence = new Query({
expire,
queueOperator: 'merge',
key: (azureId) => azureId,
client: {
fn: (azureId: string) => client.json<PersonPresence>(`/persons/${azureId}/presence?api-version=1.0`),
},
expire,
queueOperator: 'merge',
key: (azureId) => azureId,
client: {
fn: (azureId: string) =>
client.json<PersonPresence>(`/persons/${azureId}/presence?api-version=1.0`),
},
});

return {
getDetails: (azureId: string) => queryDetails.queryAsync(azureId).then((x) => x.value),
getPresence: (azureId: string) => queryPresence.queryAsync(azureId).then((x) => x.value),
getDetails: (azureId: string) => queryDetails.queryAsync(azureId).then((x) => x.value),
getPresence: (azureId: string) => queryPresence.queryAsync(azureId).then((x) => x.value),
};
};

export const usePersonResolver = (): PersonResolver => {
const [resolver, setResolver] = useState<PersonResolver | undefined>(undefined);
export const usePersonResolver = () => {
const [resolver, setResolver] = useState<any | undefined>(undefined);
const framework = useFramework();
useMemo(() => {
framework.modules.serviceDiscovery
.createClient('people')
.then((httpClient) => createPersonClient(httpClient))
.then(setResolver);
framework.modules.serviceDiscovery
.createClient('people')
.then((httpClient) => createPersonClient(httpClient))
.then(setResolver);
}, [framework]);
return resolver as PersonResolver;
return resolver;
};

0 comments on commit ba17297

Please sign in to comment.