Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[C-5141] Generate comment id in onMutate #10031

Merged
merged 2 commits into from
Oct 15, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion packages/common/src/api/tan-query/comments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,8 @@ export const usePostComment = () => {
const isReply = parentCommentId !== undefined
// This executes before the mutationFn is called, and the reference to comment is the same in both
// therefore, this sets the id that will be posted to the server
const newId = Math.floor(Math.random() * 1000000) // TODO: need to request an unused id instead of a random number
const sdk = await audiusSdk()
const newId = await sdk.comments.generateCommentId()
// hack alert: there is no way to send context from onMutate to mutationFn so we hack it into the args
args.newId = newId
const newComment: Comment = {
Expand Down
2 changes: 1 addition & 1 deletion packages/libs/src/sdk/api/comments/CommentsAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export class CommentsApi extends GeneratedCommentsApi {
super(configuration)
}

private async generateCommentId() {
async generateCommentId() {
const response = await this.getUnclaimedCommentID()
const { data: unclaimedId } = response
if (!unclaimedId) {
Expand Down