-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #144 from MZT7/main
Dynamic Blocks and Landmines
- Loading branch information
Showing
15 changed files
with
205 additions
and
44 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 |
---|---|---|
|
@@ -37,3 +37,5 @@ next-env.d.ts | |
|
||
# ignored for the template, you probably want to remove it: | ||
package-lock.json | ||
|
||
.env.local |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
"use client" | ||
|
||
import * as React from "react" | ||
import * as LabelPrimitive from "@radix-ui/react-label" | ||
import { cva, type VariantProps } from "class-variance-authority" | ||
|
||
import { cn } from "@/lib/utils" | ||
|
||
const labelVariants = cva( | ||
"text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70" | ||
) | ||
|
||
const Label = React.forwardRef< | ||
React.ElementRef<typeof LabelPrimitive.Root>, | ||
React.ComponentPropsWithoutRef<typeof LabelPrimitive.Root> & | ||
VariantProps<typeof labelVariants> | ||
>(({ className, ...props }, ref) => ( | ||
<LabelPrimitive.Root | ||
ref={ref} | ||
className={cn(labelVariants(), className)} | ||
{...props} | ||
/> | ||
)) | ||
Label.displayName = LabelPrimitive.Root.displayName | ||
|
||
export { Label } |
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,90 @@ | ||
# Welcome to your Convex functions directory! | ||
|
||
Write your Convex functions here. | ||
See https://docs.convex.dev/functions for more. | ||
|
||
A query function that takes two arguments looks like: | ||
|
||
```ts | ||
// functions.js | ||
import { query } from "./_generated/server"; | ||
import { v } from "convex/values"; | ||
|
||
export const myQueryFunction = query({ | ||
// Validators for arguments. | ||
args: { | ||
first: v.number(), | ||
second: v.string(), | ||
}, | ||
|
||
// Function implementation. | ||
handler: async (ctx, args) => { | ||
// Read the database as many times as you need here. | ||
// See https://docs.convex.dev/database/reading-data. | ||
const documents = await ctx.db.query("tablename").collect(); | ||
|
||
// Arguments passed from the client are properties of the args object. | ||
console.log(args.first, args.second); | ||
|
||
// Write arbitrary JavaScript here: filter, aggregate, build derived data, | ||
// remove non-public properties, or create new objects. | ||
return documents; | ||
}, | ||
}); | ||
``` | ||
|
||
Using this query function in a React component looks like: | ||
|
||
```ts | ||
const data = useQuery(api.functions.myQueryFunction, { | ||
first: 10, | ||
second: "hello", | ||
}); | ||
``` | ||
|
||
A mutation function looks like: | ||
|
||
```ts | ||
// functions.js | ||
import { mutation } from "./_generated/server"; | ||
import { v } from "convex/values"; | ||
|
||
export const myMutationFunction = mutation({ | ||
// Validators for arguments. | ||
args: { | ||
first: v.string(), | ||
second: v.string(), | ||
}, | ||
|
||
// Function implementation. | ||
handler: async (ctx, args) => { | ||
// Insert or modify documents in the database here. | ||
// Mutations can also read from the database like queries. | ||
// See https://docs.convex.dev/database/writing-data. | ||
const message = { body: args.first, author: args.second }; | ||
const id = await ctx.db.insert("messages", message); | ||
|
||
// Optionally, return a value from your mutation. | ||
return await ctx.db.get(id); | ||
}, | ||
}); | ||
``` | ||
|
||
Using this mutation function in a React component looks like: | ||
|
||
```ts | ||
const mutation = useMutation(api.functions.myMutationFunction); | ||
function handleButtonPress() { | ||
// fire and forget, the most common way to use mutations | ||
mutation({ first: "Hello!", second: "me" }); | ||
// OR | ||
// use the result once the mutation has completed | ||
mutation({ first: "Hello!", second: "me" }).then((result) => | ||
console.log(result), | ||
); | ||
} | ||
``` | ||
|
||
Use the Convex CLI to push your functions to a deployment. See everything | ||
the Convex CLI can do by running `npx convex -h` in your project root | ||
directory. To learn more, launch the docs with `npx convex docs`. |
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
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
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
Oops, something went wrong.