-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
19 changed files
with
407 additions
and
253 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"namesake": minor | ||
--- | ||
|
||
Improve design of browse page and allow previewing quests before addition |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
src/components/browse/AddOrGoToQuestButton/AddOrGoToQuestButton.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import { Button, Link } from "@/components/common"; | ||
import { api } from "@convex/_generated/api"; | ||
import type { Doc } from "@convex/_generated/dataModel"; | ||
import { useMutation, useQuery } from "convex/react"; | ||
import { ArrowRight, LoaderCircle, Plus } from "lucide-react"; | ||
import { useState } from "react"; | ||
import { toast } from "sonner"; | ||
|
||
interface AddOrGoToQuestButtonProps { | ||
quest: Doc<"quests">; | ||
size?: "small" | "medium"; | ||
className?: string; | ||
} | ||
|
||
export function AddOrGoToQuestButton({ | ||
quest, | ||
size = "medium", | ||
className, | ||
}: AddOrGoToQuestButtonProps) { | ||
const [isAdding, setIsAdding] = useState(false); | ||
const addQuest = useMutation(api.userQuests.create); | ||
const userQuest = useQuery(api.userQuests.getByQuestId, { | ||
questId: quest._id, | ||
}); | ||
|
||
if (quest === undefined) return null; | ||
if (quest === null) return null; | ||
|
||
const handleAddQuest = () => { | ||
setIsAdding(true); | ||
addQuest({ questId: quest._id }) | ||
.then(() => { | ||
toast.success(`Added ${quest.title} quest`); | ||
}) | ||
.then(() => setIsAdding(false)); | ||
}; | ||
|
||
if (userQuest === undefined) return null; | ||
|
||
if (!userQuest) { | ||
return ( | ||
<Button | ||
onPress={handleAddQuest} | ||
isDisabled={isAdding} | ||
aria-label={isAdding ? "Adding" : "Add quest"} | ||
size={size} | ||
variant={size === "small" ? "secondary" : "primary"} | ||
className={className} | ||
> | ||
{isAdding ? ( | ||
<LoaderCircle size={16} className="animate-spin" /> | ||
) : ( | ||
<Plus size={16} /> | ||
)} | ||
Add | ||
</Button> | ||
); | ||
} | ||
|
||
return ( | ||
<Link | ||
href={{ to: "/quests/$questId", params: { questId: quest._id } }} | ||
button={{ variant: "secondary", size }} | ||
aria-label="Go to quest" | ||
className={className} | ||
> | ||
{size === "small" ? <ArrowRight size={16} /> : "Go to quest"} | ||
</Link> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from "./AddOrGoToQuestButton"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from "./AddOrGoToQuestButton"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { PageHeader, type PageHeaderProps } from "@/components/app"; | ||
import { Badge } from "@/components/common"; | ||
import type { Doc } from "@convex/_generated/dataModel"; | ||
|
||
interface QuestPageHeaderProps extends Omit<PageHeaderProps, "title"> { | ||
quest?: Doc<"quests"> | null; | ||
} | ||
|
||
export function QuestPageHeader({ | ||
quest, | ||
badge, | ||
icon: Icon, | ||
children, | ||
className, | ||
}: QuestPageHeaderProps) { | ||
return ( | ||
<PageHeader | ||
title={quest === null ? "Unknown" : (quest?.title ?? "")} | ||
icon={Icon} | ||
badge={ | ||
<> | ||
{quest?.jurisdiction && <Badge>{quest.jurisdiction}</Badge>} | ||
{badge} | ||
</> | ||
} | ||
className={className} | ||
> | ||
{children} | ||
</PageHeader> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from "./QuestPageHeader"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.