Skip to content
This repository was archived by the owner on Aug 2, 2025. It is now read-only.

Commit 9e7d635

Browse files
committed
chore: remove workaround for badgateway/oauth2-client#110
1 parent c1700fe commit 9e7d635

File tree

4 files changed

+58
-202
lines changed

4 files changed

+58
-202
lines changed

apps/client/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
"setup": "pnpm install && pnpm validate"
1818
},
1919
"dependencies": {
20-
"@badgateway/oauth2-client": "^2.2.1",
20+
"@badgateway/oauth2-client": "^2.2.3",
2121
"@chakra-ui/icons": "^2.0.19",
2222
"@chakra-ui/react": "^2.7.1",
2323
"@chakra-ui/theme-tools": "^2.0.18",

apps/client/src/routes/Main/Home/Cycle.tsx

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
Center,
99
Spinner,
1010
Spacer,
11+
Button,
1112
} from "@chakra-ui/react";
1213
import { useTimetable } from "../../../services/sbhsApi/useTimetable";
1314
import { TimetableDay } from "../../../services/sbhsApi/schemas";
@@ -19,25 +20,33 @@ function Period(props: {
1920
activeSubject: string | null;
2021
}) {
2122
const isActive = props.activeSubject === props.period.title;
23+
const highlightColor = useColorModeValue("primary.300", "primary.600");
2224

2325
return (
24-
<Flex
25-
direction={["column", "column", "row"]}
26+
<Button
27+
display="flex"
28+
flexDirection={["column", "column", "row"]}
2629
bg={useToken("colors", useColorModeValue("gray.300", "gray.700")) + "55"}
2730
rounded={"lg"}
2831
gap={1}
29-
align="center"
32+
alignItems="center"
3033
fontFamily={"Poppins, sans-serif"}
34+
variant="unstyled"
35+
_hover={{
36+
bg:
37+
useToken("colors", useColorModeValue("gray.300", "gray.700")) + "ff",
38+
}}
3139
onClick={() =>
3240
props.setActiveSubject(isActive ? null : props.period.title)
3341
}
3442
shadow={isActive ? "outline" : undefined}
43+
height="auto"
3544
>
3645
<Text
3746
fontSize={"sm"}
3847
bg={
3948
props.period.room && (isActive || props.activeSubject === null)
40-
? "primary.500"
49+
? highlightColor
4150
: undefined
4251
}
4352
p={2}
@@ -51,7 +60,7 @@ function Period(props: {
5160
<Text fontSize={"sm"} fontWeight={"bold"} pr={[0, 0, 2]}>
5261
{props.period.room}
5362
</Text>
54-
</Flex>
63+
</Button>
5564
);
5665
}
5766

apps/client/src/stores/auth/actions/fetchAuthenticated.ts

Lines changed: 9 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,8 @@ import { SbhsApiEndpoint } from "../../../services/sbhsApi/schemas";
55
import NetworkError from "../../../errors/NetworkError";
66
import HTTPError from "../../../errors/HTTPError";
77

8-
let ready = false;
9-
10-
const initialiseFetchWrapper = async () => {
11-
const fetchWrapper = new OAuth2Fetch({
8+
const initialiseFetchWrapper = () =>
9+
new OAuth2Fetch({
1210
client: getClient(),
1311

1412
getNewToken: () => {
@@ -26,21 +24,11 @@ const initialiseFetchWrapper = async () => {
2624
},
2725

2826
onError: (error) => {
29-
if (ready) {
30-
// Set the status to expired
31-
useAuthStore.setState({ status: AuthStatus.EXPIRED });
32-
console.error(error);
33-
}
27+
// Set the status to expired
28+
useAuthStore.setState({ status: AuthStatus.EXPIRED });
29+
console.error(error);
3430
},
3531
});
36-
try {
37-
await fetchWrapper.getToken();
38-
} catch {
39-
// Ignore we expect this to error because the library has a bug
40-
}
41-
ready = true;
42-
return fetchWrapper;
43-
};
4432

4533
let _fetchWrapper: OAuth2Fetch | null = null;
4634

@@ -49,12 +37,11 @@ export const resetFetchWrapper = () => {
4937
initialiseFetchWrapper();
5038
};
5139

52-
// We defer initialisation until the first call to fetchAuthenticated to ensure that initialisation has been completed
53-
const getFetchWrapper = async () => {
40+
// We defer initialisation until the first call to fetchAuthenticated to ensure that any mocks have been set up
41+
const getFetchWrapper = () => {
5442
if (!_fetchWrapper) {
55-
_fetchWrapper = await initialiseFetchWrapper();
43+
_fetchWrapper = initialiseFetchWrapper();
5644
}
57-
6;
5845

5946
return _fetchWrapper;
6047
};
@@ -68,7 +55,7 @@ export const fetchAuthenticated = async <TSbhsApiData>(
6855
) => {
6956
let res: Response;
7057
try {
71-
const fetchWrapper = await getFetchWrapper();
58+
const fetchWrapper = getFetchWrapper();
7259
res = await fetchWrapper.fetch(
7360
"https://student.sbhs.net.au/api/" +
7461
endpoint +

0 commit comments

Comments
 (0)