-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Display quest icons, refactor quest steps schema (#108)
- Loading branch information
Showing
17 changed files
with
511 additions
and
208 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 | ||
--- | ||
|
||
Display icons for quests and improve quest step appearance |
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 was deleted.
Oops, something went wrong.
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,46 @@ | ||
import { v } from "convex/values"; | ||
import { query } from "./_generated/server"; | ||
import { userMutation } from "./helpers"; | ||
|
||
// TODO: Add `returns` value validation | ||
// https://docs.convex.dev/functions/validation | ||
|
||
export const create = userMutation({ | ||
args: { | ||
questId: v.id("quests"), | ||
title: v.string(), | ||
description: v.optional(v.string()), | ||
}, | ||
handler: async (ctx, args) => { | ||
const questStepId = await ctx.db.insert("questSteps", { | ||
questId: args.questId, | ||
title: args.title, | ||
description: args.description, | ||
creationUser: ctx.userId, | ||
}); | ||
|
||
const quest = await ctx.db.get(args.questId); | ||
|
||
if (!quest) throw new Error("Quest not found"); | ||
|
||
await ctx.db.patch(args.questId, { | ||
steps: [...(quest.steps ?? []), questStepId], | ||
}); | ||
}, | ||
}); | ||
|
||
export const getStepsForQuest = query({ | ||
args: { questId: v.id("quests") }, | ||
handler: async (ctx, args) => { | ||
const quest = await ctx.db.get(args.questId); | ||
if (!quest) throw new Error("Quest not found"); | ||
if (!quest.steps) return []; | ||
|
||
const steps = await Promise.all( | ||
quest.steps.map(async (stepId) => { | ||
return await ctx.db.get(stepId); | ||
}), | ||
); | ||
return steps; | ||
}, | ||
}); |
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.