Skip to content

Commit 592c450

Browse files
committed
Error in console when going to the next page from skills page
1 parent 053ba7d commit 592c450

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

src/libs/core/lib/profile/profile-context/profile.context-provider.tsx

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Dispatch, FC, ReactNode, SetStateAction, useEffect, useState } from 'react'
1+
import { Dispatch, FC, ReactNode, SetStateAction, useEffect, useRef, useState } from 'react'
22

33
import { userUpdatePasswordAsync } from '../../auth'
44
import { ChangePasswordRequest } from '../change-password-request.model'
@@ -18,13 +18,21 @@ export const ProfileProvider: FC<ProfileProviderProps> = (props: ProfileProvider
1818
const [profileContextData, setProfileContextData]:
1919
[ProfileContextData, Dispatch<SetStateAction<ProfileContextData>>]
2020
= useState<ProfileContextData>(defaultProfileContextData)
21+
const isFetchingProfileRef = useRef<boolean>(false)
2122

2223
function changePassword(userId: number, request: ChangePasswordRequest): Promise<void> {
2324
return userUpdatePasswordAsync(userId, request.password, request.newPassword)
2425
}
2526

2627
async function getAndSetProfileAsync(): Promise<void> {
27-
const profile: UserProfile | undefined = await profileGetLoggedInAsync()
28+
isFetchingProfileRef.current = true
29+
let profile: UserProfile | undefined
30+
try {
31+
profile = await profileGetLoggedInAsync()
32+
} catch (error) {
33+
}
34+
35+
isFetchingProfileRef.current = false
2836
const contextData: ProfileContextData = {
2937
changePassword,
3038
initialized: true,
@@ -67,7 +75,7 @@ export const ProfileProvider: FC<ProfileProviderProps> = (props: ProfileProvider
6775
useEffect(() => {
6876

6977
// if our profile is already initialized, no need to continue
70-
if (profileContextData.initialized) {
78+
if (profileContextData.initialized || isFetchingProfileRef.current) {
7179
return
7280
}
7381

src/libs/shared/lib/services/emsi-skills/emsi-skills.service.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ import { xhrGetAsync, xhrPostAsync, xhrPutAsync } from '~/libs/core'
44
import { EmsiSkill, Skill } from './skill.model'
55

66
export async function autoCompleteSkills(queryTerm: string): Promise<Skill[]> {
7+
if (!queryTerm) {
8+
return Promise.resolve([])
9+
}
10+
711
return xhrGetAsync(`${EnvironmentConfig.API.V5}/emsi-skills/skills/auto-complete?term=${queryTerm}`)
812
}
913

0 commit comments

Comments
 (0)