fix: topic for guest auth (#149)

* wip

* chore: redirect instead of toast

* refactor: remove useRouter
This commit is contained in:
Aslam
2024-09-08 04:30:11 +07:00
committed by GitHub
parent 9e4544894c
commit cb9e8f46da
5 changed files with 215 additions and 256 deletions

View File

@@ -6,13 +6,16 @@ import { ListOfTopics, Topic } from "@/lib/schema"
import { LearningStateSelector } from "@/components/custom/learning-state-selector"
import { useAccountOrGuest } from "@/lib/providers/jazz-provider"
import { LearningStateValue } from "@/lib/constants"
import { toast } from "sonner"
import { useClerk } from "@clerk/nextjs"
import { usePathname } from "next/navigation"
interface TopicDetailHeaderProps {
topic: Topic
}
export const TopicDetailHeader = React.memo(function TopicDetailHeader({ topic }: TopicDetailHeaderProps) {
const clerk = useClerk()
const pathname = usePathname()
const { me } = useAccountOrGuest({
root: {
topicsWantToLearn: [],
@@ -32,7 +35,6 @@ export const TopicDetailHeader = React.memo(function TopicDetailHeader({ topic }
if (wantToLearnIndex !== -1) {
p = {
index: wantToLearnIndex,
// TODO: fix this type error by doing better conditionals on both index and p
topic: me && me._type !== "Anonymous" ? me.root.topicsWantToLearn[wantToLearnIndex] : undefined,
learningState: "wantToLearn"
}
@@ -60,9 +62,9 @@ export const TopicDetailHeader = React.memo(function TopicDetailHeader({ topic }
const handleAddToProfile = (learningState: LearningStateValue) => {
if (me?._type === "Anonymous") {
// TODO: handle better
toast.error("You need to sign in to add links to your personal list.")
return
return clerk.redirectToSignIn({
redirectUrl: pathname
})
}
const topicLists: Record<LearningStateValue, (ListOfTopics | null) | undefined> = {