-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: year updates when subject changed in form
- Loading branch information
Showing
7 changed files
with
90 additions
and
6 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 |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { LAST_SEMESTER } from "@/config" | ||
import { db } from "@/lib/db" | ||
|
||
export async function GET(req: Request) { | ||
const url = new URL(req.url) | ||
const acronym = url.searchParams.get("acronym") | ||
|
||
if (!acronym) return new Response("Invalid query", { status: 400 }) | ||
|
||
const semester = ( | ||
await db.subject.findFirst({ | ||
where: { acronym }, | ||
select: { semester: true }, | ||
}) | ||
)?.semester | ||
if (!semester) return new Response("Subject not found", { status: 404 }) | ||
|
||
const results = semester[0] === "Q" ? parseInt(semester[1]) : LAST_SEMESTER | ||
|
||
return new Response(JSON.stringify(results)) | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export const INFINITE_SCROLL_PAGINATION_RESULTS = 4 | ||
export const GCED_START = 2017 | ||
export const LAST_SEMESTER = 8 |
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 |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { useState, useEffect } from "react" | ||
import axios from "axios" // You might need to install axios | ||
import { LAST_SEMESTER } from "@/config" | ||
|
||
const useSemesterHook = (subjectAcronym: string) => { | ||
const [data, setData] = useState(LAST_SEMESTER) | ||
const [isLoading, setIsLoading] = useState(false) | ||
|
||
useEffect(() => { | ||
const fetchData = async () => { | ||
setIsLoading(true) | ||
if (subjectAcronym === "") { | ||
setData(-1) | ||
} else { | ||
const response = await axios.get( | ||
`/api/semester?acronym=${subjectAcronym}`, | ||
) | ||
setData(response.data) | ||
} | ||
setIsLoading(false) | ||
} | ||
|
||
if (subjectAcronym !== null && subjectAcronym !== undefined) { | ||
// Assuming subjectAcronym can be null or undefined initially | ||
fetchData() | ||
} | ||
}, [subjectAcronym]) | ||
|
||
return { data, isLoading, setIsLoading } | ||
} | ||
|
||
export default useSemesterHook |
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