-
Notifications
You must be signed in to change notification settings - Fork 0
π§Ή [Code Health] Fix ESLint and TypeScript issues #75
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,7 +10,7 @@ import Link from "next/link" | |
| export default function CreateCourse() { | ||
| const { data: session, status } = useSession() | ||
| const router = useRouter() | ||
| const [isLoading, setIsLoading] = useState(true) | ||
| const [mounted, setMounted] = useState(false) | ||
| const [courseName, setCourseName] = useState("") | ||
| const [subject, setSubject] = useState("") | ||
| const [description, setDescription] = useState("") | ||
|
|
@@ -22,12 +22,16 @@ export default function CreateCourse() { | |
| const email = session?.user?.email; | ||
| if (email && !isOnboardingComplete(email)) { | ||
| router.push("/onboarding") | ||
| } else { | ||
| setIsLoading(false) | ||
| } | ||
| } | ||
| }, [status, session, router]) | ||
|
|
||
| useEffect(() => { | ||
| setMounted(true) | ||
| }, []) | ||
|
|
||
| const isLoading = !mounted || status === "loading" | ||
|
|
||
|
Comment on lines
+29
to
+34
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 1. Protected ui renders pre-redirect CreateCourse (and the same pattern in Schedule/Dashboard/MyQuizzes) now sets `isLoading = !mounted || status === "loading", so after mounted` flips true the page can render its main UI even when status === "unauthenticated" or onboarding is incomplete. Because the redirect happens in useEffect (post-paint), users can briefly see and interact with protected pages before navigation occurs. Agent Prompt
|
||
| const handleSubmit = (e: React.FormEvent) => { | ||
| e.preventDefault() | ||
| // In a real app, this would save to a database | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -20,13 +20,14 @@ export function ThemeProvider({ children }: { children: React.ReactNode }) { | |||||||||||||||||||||||||||||||||||||||||||||
| // Initialize theme from localStorage or system preference | ||||||||||||||||||||||||||||||||||||||||||||||
| useEffect(() => { | ||||||||||||||||||||||||||||||||||||||||||||||
| const savedTheme = localStorage.getItem("theme") as Theme | null | ||||||||||||||||||||||||||||||||||||||||||||||
| let initialTheme: Theme = "light" | ||||||||||||||||||||||||||||||||||||||||||||||
| if (savedTheme) { | ||||||||||||||||||||||||||||||||||||||||||||||
| setThemeState(savedTheme) | ||||||||||||||||||||||||||||||||||||||||||||||
| initialTheme = savedTheme | ||||||||||||||||||||||||||||||||||||||||||||||
| } else if (window.matchMedia("(prefers-color-scheme: dark)").matches) { | ||||||||||||||||||||||||||||||||||||||||||||||
| setThemeState("dark") | ||||||||||||||||||||||||||||||||||||||||||||||
| } else { | ||||||||||||||||||||||||||||||||||||||||||||||
| setThemeState("light") | ||||||||||||||||||||||||||||||||||||||||||||||
| initialTheme = "dark" | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| setThemeState(initialTheme) | ||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
22
to
+30
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Validate the persisted theme before treating it as
π‘οΈ Proposed fix- const savedTheme = localStorage.getItem("theme") as Theme | null
+ const savedTheme = localStorage.getItem("theme")
let initialTheme: Theme = "light"
- if (savedTheme) {
+ if (savedTheme === "light" || savedTheme === "dark") {
initialTheme = savedTheme
} else if (window.matchMedia("(prefers-color-scheme: dark)").matches) {
initialTheme = "dark"
}π Committable suggestion
Suggested change
π€ Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||
| setMounted(true) | ||||||||||||||||||||||||||||||||||||||||||||||
| // eslint-disable-next-line react-hooks/exhaustive-deps | ||||||||||||||||||||||||||||||||||||||||||||||
| }, []) | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -63,7 +63,7 @@ describe('security lib', () => { | |||||||||
|
|
||||||||||
| // Passing something that isn't a string might trigger an error if not handled | ||||||||||
| // although verifyData expects a string type. | ||||||||||
| // @ts-ignore | ||||||||||
| // @ts-expect-error Types may be incomplete or global variables need mocking | ||||||||||
| const isValid = verifyData(testData, { not: 'a string' }); | ||||||||||
|
Comment on lines
+66
to
67
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. π§© Analysis chainπ Script executed: cat -n lib/security.test.ts | head -100Repository: APPLEPIE6969/StudyFlow Length of output: 3287 π Script executed: cat -n lib/security.ts | head -50Repository: APPLEPIE6969/StudyFlow Length of output: 1703 Update the The current comment references "global variables need mocking" which is unrelated to this test. The test intentionally passes an object instead of the expected string to verify error handling. βοΈ Suggested edit- // `@ts-expect-error` Types may be incomplete or global variables need mocking
+ // `@ts-expect-error` Intentional type mismatch: verifyData expects signature as string
const isValid = verifyData(testData, { not: 'a string' });π Committable suggestion
Suggested change
π€ Prompt for AI Agents |
||||||||||
| assert.strictEqual(isValid, false); | ||||||||||
| }); | ||||||||||
|
|
||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Validate and normalize
historybefore mapping rolesLine 64βs inline type is compile-time only;
historyis still untrusted JSON at runtime. Also, Line 65 currently maps any non-"ai"role to"user", which misclassifies"system"/invalid roles. Please sanitize first, then map only allowed roles.Proposed fix
π€ Prompt for AI Agents