save code when it's there
This commit is contained in:
parent
bf07b6da4f
commit
f7558f3c93
2 changed files with 21 additions and 1 deletions
|
@ -10,6 +10,7 @@ import { Temporal } from '@js-temporal/polyfill'
|
|||
import SingleColumnLayout from '../../../layouts/SingleColumnLayout.tsx'
|
||||
import NavBar from '../../../components/NavBar.tsx'
|
||||
import AuthNavButtons from '../../auth/components/AuthNavButtons.tsx'
|
||||
import { useSaveSignupCodeToLocalStorage } from '../../../hooks/useSaveSignupCodeToLocalStorage.ts'
|
||||
|
||||
interface HomePageProps {
|
||||
postsService: PostsService
|
||||
|
@ -18,6 +19,7 @@ interface HomePageProps {
|
|||
|
||||
export default function HomePage({ postsService, mediaService }: HomePageProps) {
|
||||
const { user } = useUser()
|
||||
useSaveSignupCodeToLocalStorage()
|
||||
const [isSubmitting, setIsSubmitting] = useState(false)
|
||||
|
||||
const fetchPosts = useCallback(
|
||||
|
@ -30,7 +32,11 @@ export default function HomePage({ postsService, mediaService }: HomePageProps)
|
|||
const { pages, setPages, loadNextPage } = useFeedViewModel(fetchPosts)
|
||||
|
||||
const onCreatePost = useCallback(
|
||||
async (content: string, files: { file: File; width: number; height: number }[], isPublic: boolean) => {
|
||||
async (
|
||||
content: string,
|
||||
files: { file: File; width: number; height: number }[],
|
||||
isPublic: boolean,
|
||||
) => {
|
||||
setIsSubmitting(true)
|
||||
if (user == null) throw new Error('Not logged in')
|
||||
try {
|
||||
|
|
14
src/hooks/useSaveSignupCodeToLocalStorage.ts
Normal file
14
src/hooks/useSaveSignupCodeToLocalStorage.ts
Normal file
|
@ -0,0 +1,14 @@
|
|||
import { useSearchParams } from 'react-router-dom'
|
||||
import { useEffect } from 'react'
|
||||
|
||||
export function useSaveSignupCodeToLocalStorage() {
|
||||
const [searchParams] = useSearchParams()
|
||||
|
||||
const code = searchParams.get('ck')
|
||||
|
||||
useEffect(() => {
|
||||
if (code) {
|
||||
localStorage.setItem('signupCode', code)
|
||||
}
|
||||
}, [code])
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue