Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 13 additions & 12 deletions client-next/src/app/settings/topics/page.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use client'

import { useState, useEffect } from 'react'
import { useState, useEffect, useCallback } from 'react'
import { useAuth } from '@/context/AuthContext'
import { useRouter } from 'next/navigation'
import Link from 'next/link'
Expand All @@ -20,22 +20,14 @@ function flattenTopics(topics) {
}

export default function TopicsPage() {
const { user } = useAuth()
const { user, isLoading: authLoading } = useAuth()
const router = useRouter()
const [followed, setFollowed] = useState([])
const [allTopics, setAllTopics] = useState([])
const [loading, setLoading] = useState(true)
const [actionLoading, setActionLoading] = useState(null)

useEffect(() => {
if (!user) {
router.push('/login')
return
}
loadData()
}, [user])

async function loadData() {
const loadData = useCallback(async () => {
setLoading(true)
try {
const [followedData, topicsData] = await Promise.all([
Expand All @@ -49,7 +41,16 @@ export default function TopicsPage() {
} finally {
setLoading(false)
}
}
}, [])

useEffect(() => {
if (authLoading) return
if (!user) {
router.replace('/login')
return
}
loadData()
}, [user, authLoading, router, loadData])

const followedSlugs = new Set(followed.map(t => t.topic))

Expand Down
11 changes: 4 additions & 7 deletions client-next/src/app/start/page.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ function CustomTagInput({ customTagInput, setCustomTagInput, parseCustomTags })
}

export default function Start() {
const { user } = useAuth()
const { user, isLoading } = useAuth()
const router = useRouter()

const [doi, setDoi] = useState('')
Expand All @@ -112,17 +112,14 @@ export default function Start() {
.catch(() => {})
}, [])

const [isReady, setIsReady] = useState(false)

useEffect(() => {
if (isLoading) return
if (!user) {
router.replace('/login')
} else {
setIsReady(true)
}
}, [user, router])
}, [user, isLoading, router])

if (!isReady || !user) {
if (isLoading || !user) {
return null
}

Expand Down
Loading