-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: removed calls that we shouldn't do when we are not logged in
- Loading branch information
1 parent
49b5c9c
commit 7fdbd05
Showing
10 changed files
with
79 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,26 @@ | ||
import { useEffect, useState } from 'react'; | ||
import { useAPI } from '@/api/api'; | ||
import { AnnalMetadata, AnnalType } from '@/api/annals/annal.interface'; | ||
import { useLoggedIn } from '@/module/session'; | ||
|
||
export default function useAnnalMetadata(code: string): [types: AnnalType[] | null, semesters: string[] | null] { | ||
const [availableTypes, setAvailableTypes] = useState<AnnalType[] | null>(null); | ||
const [availableSemesters, setAvailableSemesters] = useState<string[] | null>(null); | ||
export default function useAnnalMetadata( | ||
code: string, | ||
): [types: AnnalType[] | null | undefined, semesters: string[] | null | undefined] { | ||
const [availableTypes, setAvailableTypes] = useState<AnnalType[] | null | undefined>(undefined); | ||
const [availableSemesters, setAvailableSemesters] = useState<string[] | null | undefined>(undefined); | ||
const api = useAPI(); | ||
const logged = useLoggedIn(); | ||
|
||
useEffect(() => { | ||
api.get<AnnalMetadata>(`/ue/annals/metadata?ueCode=${code}`).on('success', (metadata) => { | ||
setAvailableTypes(metadata.types); | ||
setAvailableSemesters(metadata.semesters); | ||
}); | ||
if (logged && (!availableTypes || !availableSemesters)) { | ||
api.get<AnnalMetadata>(`/ue/annals/metadata?ueCode=${code}`).on('success', (metadata) => { | ||
setAvailableTypes(metadata.types); | ||
setAvailableSemesters(metadata.semesters); | ||
}); | ||
} else if (!logged) { | ||
setAvailableTypes(null); | ||
setAvailableSemesters(null); | ||
} | ||
}, []); | ||
return [availableTypes, availableSemesters]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,18 @@ | ||
import { UERate } from '@/api/ueRate/ueRateCriterion.interface'; | ||
import { useAPI } from '@/api/api'; | ||
import { useEffect, useState } from 'react'; | ||
import { useLoggedIn } from '@/module/session'; | ||
|
||
export default function useUERate(ueCode: string): [UERate[] | null, (newVal: UERate[]) => void] { | ||
const [rates, setRates] = useState<UERate[] | null>(null); | ||
export default function useUERate(ueCode: string): [UERate[] | null | undefined, (newVal: UERate[]) => void] { | ||
const [rates, setRates] = useState<UERate[] | null | undefined>(undefined); | ||
const logged = useLoggedIn(); | ||
const api = useAPI(); | ||
useEffect(() => { | ||
api.get<UERate[]>(`ue/${ueCode}/rate`).on('success', setRates); | ||
}, []); | ||
if (logged && !rates) { | ||
api.get<UERate[]>(`ue/${ueCode}/rate`).on('success', setRates); | ||
} else if (!logged) { | ||
setRates(null); | ||
} | ||
}, [logged]); | ||
return [rates, setRates]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,18 @@ | ||
import { useEffect, useState } from 'react'; | ||
import { useAPI } from '@/api/api'; | ||
import { User } from '@/api/users/user.interface'; | ||
import { useLoggedIn } from '@/module/session'; | ||
|
||
export default function useTodaysBirthdays(): User[] | null { | ||
const [users, setUsers] = useState<User[] | null>(null); | ||
export default function useTodaysBirthdays(): User[] | null | undefined { | ||
const [users, setUsers] = useState<User[] | null | undefined>(undefined); | ||
const api = useAPI(); | ||
const logged = useLoggedIn(); | ||
useEffect(() => { | ||
api.get<User[]>('/users/birthdays/today').on('success', setUsers); | ||
if (logged && !users) { | ||
api.get<User[]>('/users/birthdays/today').on('success', setUsers); | ||
} else if (!logged) { | ||
setUsers(null); | ||
} | ||
}, []); | ||
return users; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters