-
Notifications
You must be signed in to change notification settings - Fork 77
Fix settings link and redirect to user-specific settings page #1752
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
Conversation
import { useEffect, useState } from "react" | ||
import { Redirect } from "wouter" | ||
|
||
import { FullPageLoader } from "@/App" | ||
import { useGlobalStore } from "@/hooks/use-global-store" | ||
|
||
const SettingsRedirectPage = () => { | ||
const session = useGlobalStore((state) => state.session) | ||
const [hasHydrated, setHasHydrated] = useState(() => { | ||
if (typeof window === "undefined") return false | ||
return useGlobalStore.persist?.hasHydrated?.() ?? false | ||
}) | ||
|
||
useEffect(() => { | ||
if (typeof window === "undefined") return | ||
|
||
if (useGlobalStore.persist?.hasHydrated?.()) { | ||
setHasHydrated(true) | ||
return | ||
} | ||
|
||
const unsubFinishHydration = useGlobalStore.persist?.onFinishHydration?.( | ||
() => { | ||
setHasHydrated(true) | ||
}, | ||
) | ||
|
||
return () => { | ||
unsubFinishHydration?.() | ||
} | ||
}, []) | ||
|
||
if (!hasHydrated) { | ||
return <FullPageLoader /> | ||
} | ||
|
||
if (!session?.github_username) { | ||
return <Redirect to="/" /> | ||
} | ||
|
||
return <Redirect to={`/${session.github_username}/settings`} /> | ||
} | ||
|
||
export default SettingsRedirectPage |
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.
File naming inconsistency: The file settings-redirect.tsx
uses kebab-case but does not match the exported component name SettingsRedirectPage
. Fix by either:
- Renaming the file to
SettingsRedirectPage.tsx
to match the export name, or - Renaming the export to
SettingsRedirect
to align with the kebab-case file name
Consistent naming conventions improve code maintainability and follow established project patterns.
import { useEffect, useState } from "react" | |
import { Redirect } from "wouter" | |
import { FullPageLoader } from "@/App" | |
import { useGlobalStore } from "@/hooks/use-global-store" | |
const SettingsRedirectPage = () => { | |
const session = useGlobalStore((state) => state.session) | |
const [hasHydrated, setHasHydrated] = useState(() => { | |
if (typeof window === "undefined") return false | |
return useGlobalStore.persist?.hasHydrated?.() ?? false | |
}) | |
useEffect(() => { | |
if (typeof window === "undefined") return | |
if (useGlobalStore.persist?.hasHydrated?.()) { | |
setHasHydrated(true) | |
return | |
} | |
const unsubFinishHydration = useGlobalStore.persist?.onFinishHydration?.( | |
() => { | |
setHasHydrated(true) | |
}, | |
) | |
return () => { | |
unsubFinishHydration?.() | |
} | |
}, []) | |
if (!hasHydrated) { | |
return <FullPageLoader /> | |
} | |
if (!session?.github_username) { | |
return <Redirect to="/" /> | |
} | |
return <Redirect to={`/${session.github_username}/settings`} /> | |
} | |
export default SettingsRedirectPage | |
import { useEffect, useState } from "react" | |
import { Redirect } from "wouter" | |
import { FullPageLoader } from "@/App" | |
import { useGlobalStore } from "@/hooks/use-global-store" | |
const SettingsRedirect = () => { | |
const session = useGlobalStore((state) => state.session) | |
const [hasHydrated, setHasHydrated] = useState(() => { | |
if (typeof window === "undefined") return false | |
return useGlobalStore.persist?.hasHydrated?.() ?? false | |
}) | |
useEffect(() => { | |
if (typeof window === "undefined") return | |
if (useGlobalStore.persist?.hasHydrated?.()) { | |
setHasHydrated(true) | |
return | |
} | |
const unsubFinishHydration = useGlobalStore.persist?.onFinishHydration?.( | |
() => { | |
setHasHydrated(true) | |
}, | |
) | |
return () => { | |
unsubFinishHydration?.() | |
} | |
}, []) | |
if (!hasHydrated) { | |
return <FullPageLoader /> | |
} | |
if (!session?.github_username) { | |
return <Redirect to="/" /> | |
} | |
return <Redirect to={`/${session.github_username}/settings`} /> | |
} | |
export default SettingsRedirect |
Spotted by Diamond (based on custom rule: Custom rule)
Is this helpful? React 👍 or 👎 to let us know.
Summary
Testing
https://chatgpt.com/codex/tasks/task_b_68e07e7cfd34832ebeb8ffe2c2546a0d