Hmza
Hmza
CCConvex Community
Created by Fredy D. | AmigoPago on 10/2/2024 in #support-community
Is convex.dev suitable for a Web3(crypto) project?
@Fredy D. | AmigoPago sounds like you're trying to integrate crypto wallet login/signup into your Web3 project with Convex. Convex is solid for managing backend stuff like state and data, but are you looking specifically to handle wallet login (like MetaMask or something similar), or are you building an actual wallet yourself? If it's about wallet-based login, libraries like ethers.js or web3.js are typically what you'd use to handle that kind of signing and transaction flow. Convex could probably store user info or transaction history, you could mix those libraries with Convex for the backend.
5 replies
CCConvex Community
Created by M Zeeshan on 10/4/2024 in #support-community
Schedule function
Yeah indy suggested this the other day
27 replies
CCConvex Community
Created by M Zeeshan on 10/4/2024 in #support-community
Schedule function
Sory lol
27 replies
CCConvex Community
Created by M Zeeshan on 10/4/2024 in #support-community
Schedule function
27 replies
CCConvex Community
Created by Web Dev Cody on 10/2/2024 in #support-community
Understanding usePaginatedQuery
i faced same thing a little while ago so i came up with this https://github.com/hamzasaleem2/convex-tanstack-table/blob/main/src/useSimplePaginatedQuery.ts its just a wrap over useQuery but did the job for me for offsets it gives you this hook to use:
const {
status,
currentResults,
loadNext,
loadPrev,
currentPageNum,
setPageSize,
pageSize
} = useSimplePaginatedQuery(myQuery, initialArgs, { initialNumItems: 10 });
const {
status,
currentResults,
loadNext,
loadPrev,
currentPageNum,
setPageSize,
pageSize
} = useSimplePaginatedQuery(myQuery, initialArgs, { initialNumItems: 10 });
tanstack table demo: https://convex-tanstack-table.vercel.app/ i didn't worked out alot of things in this which can be better. but you are welcome to try and happy to take a feedback on this too.
23 replies
CCConvex Community
Created by Fredy D. | AmigoPago on 10/2/2024 in #support-community
running AI Chat with vector search sample
Hi Welcome, find it here please: https://www.convex.dev/templates/ai-chat
3 replies
CCConvex Community
Created by raul.sp on 10/2/2024 in #support-community
getting random "n" entries from a table with db query
there's no native way todo this in convex but can be achieved doing something like this
export default query(async (ctx) => {
const earliest = await ctx.db
.query("table")
.order("asc")
.first();
const latest = await ctx.db
.query("table")
.order("desc")
.first();
if (!earliest || !latest) {
return [];
}
const earliestTime = earliest._creationTime;
const latestTime = latest._creationTime;
const randomTime = earliestTime + Math.random() * (latestTime - earliestTime);
const randomDocs = await ctx.db
.query("table")
.withIndex("by_creation_time", (q) => q.gte("_creationTime", randomTime))
.take(10);
return randomDocs;
})
export default query(async (ctx) => {
const earliest = await ctx.db
.query("table")
.order("asc")
.first();
const latest = await ctx.db
.query("table")
.order("desc")
.first();
if (!earliest || !latest) {
return [];
}
const earliestTime = earliest._creationTime;
const latestTime = latest._creationTime;
const randomTime = earliestTime + Math.random() * (latestTime - earliestTime);
const randomDocs = await ctx.db
.query("table")
.withIndex("by_creation_time", (q) => q.gte("_creationTime", randomTime))
.take(10);
return randomDocs;
})
also this thread is where its discusssed before, another way: https://discord.com/channels/1019350475847499849/1215250213623562250/1215289564856320071
5 replies
CCConvex Community
Created by lexcodeit on 9/30/2024 in #support-community
Is there a way to get list of connected devices to the convex app?
https://stack.convex.dev/presence-with-convex This will help you through the process to implement this kind of functionality
4 replies
CCConvex Community
Created by dannyelo on 9/26/2024 in #support-community
runAfter is not throwing an error on the client
A properly written mutation can be just as secure as an action. The key is to implement proper validation and error handling. Mutations run transactionally, which can provide better data consistency guarantees. to answer your question about the validator errors escaping frontend try/catch you should use ConvexError for structured errors (throw in convex and catch it on client side) https://docs.convex.dev/functions/error-handling //mutation
if (!isValid) {
throw new ConvexError({ code: "INVALID_INPUT", message: "..." });
}
if (!isValid) {
throw new ConvexError({ code: "INVALID_INPUT", message: "..." });
}
//client
try {
await myMutation({ ... });
} catch (error) {
if (error instanceof ConvexError) {
structured errors
} else {
handle other errors
}
}
try {
await myMutation({ ... });
} catch (error) {
if (error instanceof ConvexError) {
structured errors
} else {
handle other errors
}
}
you can also handle without throwing in mutation itself
export const myMutation = mutation({
args: {},
handler: async (ctx, args) => {
//validation
const validationResult = validateArgs(args);
if (!validationResult.isValid) {
// not throwing
return { success: false, error: validationResult.error };
}
return { success: true, data:{} };
},
});
export const myMutation = mutation({
args: {},
handler: async (ctx, args) => {
//validation
const validationResult = validateArgs(args);
if (!validationResult.isValid) {
// not throwing
return { success: false, error: validationResult.error };
}
return { success: true, data:{} };
},
});
for replying event you can use a sourcing pattern that stores your raw events in db and then mutation are run on those to make sure you are processing them right. finally for your 1% problem of errors it might be worth adding more detailed logging or using a debugging tool to trace the error propagation. You could also consider using a global error boundary in React to catch any errors that escape local try/catch blocks.
121 replies
CCConvex Community
Created by Marcin on 9/28/2024 in #support-community
Error: Could not resolve...
5 replies
CCConvex Community
Created by CodingWithJamal on 9/26/2024 in #support-community
Need a little react help
It seems like the issue might be with how the initial value is being read from local storage.double check if the defaultValue option in useLocalStorage is being set correctly, and ensure that it aligns with the value stored in local storage. You could also log the value right after calling useLocalStorage to see what it's retrieving on the first render.
12 replies
CCConvex Community
Created by dannyelo on 9/26/2024 in #support-community
runAfter is not throwing an error on the client
yes this will work well enough for your use case!
121 replies
CCConvex Community
Created by dannyelo on 9/26/2024 in #support-community
runAfter is not throwing an error on the client
Calling an action directly from the frontend can be considered an anti-pattern if you're not capturing the user intent or state in the database. To follow best practices, you should use a mutation to capture intent, store relevant data, and then call the action from the backend. But if your main goal is to handle third-party API calls and return errors in real-time, calling the action directly is acceptable in this case.
121 replies
CCConvex Community
Created by dannyelo on 9/26/2024 in #support-community
runAfter is not throwing an error on the client
If you need to catch errors in real-time from the third-party API, use an action and call it directly from the frontend via useAction. The scheduler
(ctx.scheduler.runAfter)
(ctx.scheduler.runAfter)
is for background tasks and won't return immediate errors to the client. Actions will allow you to handle success or failure directly in the frontend. https://docs.convex.dev/functions/actions
121 replies
CCConvex Community
Created by dannyelo on 9/26/2024 in #support-community
runAfter is not throwing an error on the client
@dannyelo instead of directly calling actions from mutations, you should handle third-party API calls in actions. Move your conditional API logic to an action, and have the mutation schedule this action using ctx.scheduler.runAfter. This way, you follow the correct Convex pattern: mutation > schedule action > action handles API and writes to DB. To handle conditional API calls, use an action for calling third-party APIs, not a mutation. In your case, validate the required fields in the action, and if the fields are incomplete, skip the API call and handle the database mutation separately. Avoid directly calling actions from mutations—use ctx.runAction to follow Convex patterns.
121 replies
CCConvex Community
Created by CodingWithJamal on 9/26/2024 in #support-community
Need a little react help
const [viewCounted, setViewCounted] = useLocalStorage<"no" | "yes">(
"view_counted",
{
defaultValue: "no",
}
);
const [viewCounted, setViewCounted] = useLocalStorage<"no" | "yes">(
"view_counted",
{
defaultValue: "no",
}
);
useLocalStorage might not being read correctly because of the extra wrap defaultValue try this to make sure value is read from localstorage correctly on component mount: const [viewCounted, setViewCounted] = useLocalStorage<"no" | "yes">("view_counted", "no"); @CodingWithJamal
12 replies
CCConvex Community
Created by TwendyKirn on 9/22/2024 in #support-community
Quering random row
If your images count stays around 100 or even 500. the Sequential ID you defined would work fine!
20 replies
CCConvex Community
Created by M Zeeshan on 9/17/2024 in #support-community
Authentication in paginated query
have a great day
58 replies
CCConvex Community
Created by M Zeeshan on 9/17/2024 in #support-community
Authentication in paginated query
got it. i hope that aggregating data suggestion was helpful.
58 replies
CCConvex Community
Created by M Zeeshan on 9/17/2024 in #support-community
Authentication in paginated query
i see this code is splitting pages and aggregating results too. i don't know your use case. but i'll still suggest to let things be handled by convex functions and queries. it'd be more optimised. did you check this ? https://www.npmjs.com/package/convex-helpers#manual-pagination does ton more things for you. also this article is great overview: https://stack.convex.dev/pagination good luck 🙂
58 replies