Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { Id } from '@audius/sdk'
import { useMutation, useQueryClient } from '@tanstack/react-query'
import { cloneDeep } from 'lodash'
import { useDispatch } from 'react-redux'
Expand Down Expand Up @@ -27,7 +28,10 @@ export const useDeleteComment = () => {
const dispatch = useDispatch()
return useMutation({
mutationFn: async ({ commentId, userId }: DeleteCommentArgs) => {
const commentData = { userId, entityId: commentId }
const commentData = {
userId: Id.parse(userId),
commentId: Id.parse(commentId)
}
const sdk = await audiusSdk()
return await sdk.comments.deleteComment(commentData)
},
Expand Down
24 changes: 12 additions & 12 deletions packages/common/src/api/tan-query/comments/useEditComment.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { EntityType, CommentMention } from '@audius/sdk'
import { EntityType, CommentMention, Id } from '@audius/sdk'
import { useMutation, useQueryClient } from '@tanstack/react-query'
import { useDispatch } from 'react-redux'

Expand Down Expand Up @@ -29,19 +29,19 @@ export const useEditComment = () => {
userId,
newMessage,
trackId,
mentions,
entityType = EntityType.TRACK
mentions
}: EditCommentArgs) => {
const commentData = {
body: newMessage,
userId,
entityId: commentId,
trackId,
entityType,
mentions: mentions?.map((mention) => mention.userId) ?? []
}
const sdk = await audiusSdk()
await sdk.comments.editComment(commentData)
await sdk.comments.updateComment({
userId: Id.parse(userId)!,
commentId: Id.parse(commentId)!,
metadata: {
body: newMessage,
entityId: trackId,
entityType: 'Track',
mentions: mentions?.map((mention) => mention.userId) ?? []
}
})
},
onMutate: ({ commentId, newMessage, mentions }) => {
const prevComment = queryClient.getQueryData(
Expand Down
24 changes: 18 additions & 6 deletions packages/common/src/api/tan-query/comments/usePinComment.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { Id } from '@audius/sdk'
import { useMutation, useQueryClient } from '@tanstack/react-query'
import { cloneDeep } from 'lodash'
import { useDispatch } from 'react-redux'
Expand Down Expand Up @@ -29,12 +30,23 @@ export const usePinComment = () => {
mutationFn: async (args: PinCommentArgs) => {
const { userId, commentId, isPinned, trackId } = args
const sdk = await audiusSdk()
return await sdk.comments.pinComment({
userId,
entityId: commentId,
trackId,
isPin: isPinned
})
if (isPinned) {
return await sdk.comments.pinComment({
userId: Id.parse(userId)!,
commentId: Id.parse(commentId)!,
metadata: {
entityId: trackId
}
})
} else {
return await sdk.comments.unpinComment({
userId: Id.parse(userId)!,
commentId: Id.parse(commentId)!,
metadata: {
entityId: trackId
}
})
}
},
onMutate: ({ commentId, isPinned, trackId, currentSort }) => {
if (isPinned) {
Expand Down
18 changes: 12 additions & 6 deletions packages/common/src/api/tan-query/comments/usePostComment.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { CommentMention, EntityType } from '@audius/sdk'
import { CommentMention, EntityType, Id } from '@audius/sdk'
import { useMutation, useQueryClient } from '@tanstack/react-query'
import { cloneDeep } from 'lodash'

Expand Down Expand Up @@ -32,11 +32,17 @@ export const usePostComment = () => {
return useMutation({
mutationFn: async (args: PostCommentArgs) => {
const sdk = await audiusSdk()
return await sdk.comments.postComment({
...args,
mentions: args.mentions?.map((mention) => mention.userId) ?? [],
entityId: args.trackId,
commentId: args.newId
return await sdk.comments.createComment({
userId: Id.parse(args.userId)!,
metadata: {
commentId: args.newId,
entityId: args.trackId,
entityType: 'Track',
body: args.body,
trackTimestampS: args.trackTimestampS,
mentions: args.mentions?.map((mention) => mention.userId) ?? [],
parentId: args.parentCommentId
}
})
},
onMutate: async (args: PostCommentArgs) => {
Expand Down
15 changes: 14 additions & 1 deletion packages/common/src/api/tan-query/comments/useReactToComment.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { Id } from '@audius/sdk'
import { useMutation, useQueryClient } from '@tanstack/react-query'
import { useDispatch } from 'react-redux'

Expand Down Expand Up @@ -29,7 +30,19 @@ export const useReactToComment = () => {
trackId
}: ReactToCommentArgs) => {
const sdk = await audiusSdk()
await sdk.comments.reactComment({ userId, commentId, isLiked, trackId })
if (isLiked) {
await sdk.comments.reactToComment({
userId: Id.parse(userId)!,
commentId: Id.parse(commentId)!,
metadata: { entityId: trackId, entityType: 'Track' }
})
} else {
await sdk.comments.unreactToComment({
userId: Id.parse(userId)!,
commentId: Id.parse(commentId)!,
metadata: { entityId: trackId, entityType: 'Track' }
})
}
},
mutationKey: ['reactToComment'],
onMutate: async ({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { Id } from '@audius/sdk'
import { useMutation, useQueryClient } from '@tanstack/react-query'
import { cloneDeep } from 'lodash'
import { useDispatch } from 'react-redux'
Expand Down Expand Up @@ -28,7 +29,10 @@ export const useReportComment = () => {
return useMutation({
mutationFn: async ({ userId, commentId }: ReportCommentArgs) => {
const sdk = await audiusSdk()
await sdk.comments.reportComment(userId, commentId)
await sdk.comments.reportComment({
userId: Id.parse(userId)!,
commentId: Id.parse(commentId)!
})
},
onMutate: ({ trackId, commentId, currentSort, parentCommentId }) => {
// Optimistic update - filter out the comment from either the top list or the parent comment's replies
Expand Down
30 changes: 15 additions & 15 deletions packages/sdk/src/sdk/api/comments/CommentsAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,16 +85,17 @@ export class CommentsApi extends GeneratedCommentsApi {
requestInit?: RequestInit
) {
if (this.entityManager) {
const { createCommentRequestBody, userId } = params
const metadata: EntityManagerCreateCommentRequest = {
const { metadata, userId } = params
const commentId = await this.createCommentWithEntityManager({
userId,
entityId: createCommentRequestBody.entityId,
entityType: createCommentRequestBody.entityType,
body: createCommentRequestBody.body,
commentId: createCommentRequestBody.commentId,
parentCommentId: createCommentRequestBody.parentId
}
const commentId = await this.createCommentWithEntityManager(metadata)
entityId: encodeHashId(metadata.entityId) ?? '',
entityType: metadata.entityType,
body: metadata.body,
commentId: metadata.commentId,
parentCommentId: metadata.parentId,
trackTimestampS: metadata.trackTimestampS,
mentions: metadata.mentions
})
return {
success: true,
commentId: commentId ?? undefined
Expand Down Expand Up @@ -132,14 +133,13 @@ export class CommentsApi extends GeneratedCommentsApi {
requestInit?: RequestInit
) {
if (this.entityManager) {
const { updateCommentRequestBody, userId, commentId } = params
const metadata: EntityManagerUpdateCommentRequest = {
const { metadata, userId, commentId } = params
await this.updateCommentWithEntityManager({
userId,
entityId: commentId,
trackId: commentId, // trackId is used for the entity being commented on
body: updateCommentRequestBody.body
}
await this.updateCommentWithEntityManager(metadata)
trackId: encodeHashId(metadata.entityId) ?? '',
body: metadata.body
})
return {
success: true
}
Expand Down
38 changes: 38 additions & 0 deletions packages/sdk/src/sdk/api/generated/default/apis/CommentsApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import type {
CommentResponse,
CreateCommentRequestBody,
CreateCommentResponse,
PinCommentRequestBody,
ReactCommentRequestBody,
UnclaimedIdResponse,
UpdateCommentRequestBody,
WriteResponse,
Expand All @@ -33,6 +35,10 @@ import {
CreateCommentRequestBodyToJSON,
CreateCommentResponseFromJSON,
CreateCommentResponseToJSON,
PinCommentRequestBodyFromJSON,
PinCommentRequestBodyToJSON,
ReactCommentRequestBodyFromJSON,
ReactCommentRequestBodyToJSON,
UnclaimedIdResponseFromJSON,
UnclaimedIdResponseToJSON,
UpdateCommentRequestBodyFromJSON,
Expand Down Expand Up @@ -65,11 +71,13 @@ export interface GetCommentRepliesRequest {
export interface PinCommentRequest {
commentId: string;
userId: string;
metadata: PinCommentRequestBody;
}

export interface ReactToCommentRequest {
commentId: string;
userId: string;
metadata: ReactCommentRequestBody;
}

export interface ReportCommentRequest {
Expand All @@ -80,11 +88,13 @@ export interface ReportCommentRequest {
export interface UnpinCommentRequest {
commentId: string;
userId: string;
metadata: PinCommentRequestBody;
}

export interface UnreactToCommentRequest {
commentId: string;
userId: string;
metadata: ReactCommentRequestBody;
}

export interface UpdateCommentRequest {
Expand Down Expand Up @@ -315,6 +325,10 @@ export class CommentsApi extends runtime.BaseAPI {
throw new runtime.RequiredError('userId','Required parameter params.userId was null or undefined when calling pinComment.');
}

if (params.metadata === null || params.metadata === undefined) {
throw new runtime.RequiredError('metadata','Required parameter params.metadata was null or undefined when calling pinComment.');
}

const queryParameters: any = {};

if (params.userId !== undefined) {
Expand All @@ -323,6 +337,8 @@ export class CommentsApi extends runtime.BaseAPI {

const headerParameters: runtime.HTTPHeaders = {};

headerParameters['Content-Type'] = 'application/json';

if (this.configuration && (this.configuration.username !== undefined || this.configuration.password !== undefined)) {
headerParameters["Authorization"] = "Basic " + btoa(this.configuration.username + ":" + this.configuration.password);
}
Expand All @@ -339,6 +355,7 @@ export class CommentsApi extends runtime.BaseAPI {
method: 'POST',
headers: headerParameters,
query: queryParameters,
body: PinCommentRequestBodyToJSON(params.metadata),
}, initOverrides);

return new runtime.JSONApiResponse(response, (jsonValue) => WriteResponseFromJSON(jsonValue));
Expand All @@ -365,6 +382,10 @@ export class CommentsApi extends runtime.BaseAPI {
throw new runtime.RequiredError('userId','Required parameter params.userId was null or undefined when calling reactToComment.');
}

if (params.metadata === null || params.metadata === undefined) {
throw new runtime.RequiredError('metadata','Required parameter params.metadata was null or undefined when calling reactToComment.');
}

const queryParameters: any = {};

if (params.userId !== undefined) {
Expand All @@ -373,6 +394,8 @@ export class CommentsApi extends runtime.BaseAPI {

const headerParameters: runtime.HTTPHeaders = {};

headerParameters['Content-Type'] = 'application/json';

if (this.configuration && (this.configuration.username !== undefined || this.configuration.password !== undefined)) {
headerParameters["Authorization"] = "Basic " + btoa(this.configuration.username + ":" + this.configuration.password);
}
Expand All @@ -389,6 +412,7 @@ export class CommentsApi extends runtime.BaseAPI {
method: 'POST',
headers: headerParameters,
query: queryParameters,
body: ReactCommentRequestBodyToJSON(params.metadata),
}, initOverrides);

return new runtime.JSONApiResponse(response, (jsonValue) => WriteResponseFromJSON(jsonValue));
Expand Down Expand Up @@ -465,6 +489,10 @@ export class CommentsApi extends runtime.BaseAPI {
throw new runtime.RequiredError('userId','Required parameter params.userId was null or undefined when calling unpinComment.');
}

if (params.metadata === null || params.metadata === undefined) {
throw new runtime.RequiredError('metadata','Required parameter params.metadata was null or undefined when calling unpinComment.');
}

const queryParameters: any = {};

if (params.userId !== undefined) {
Expand All @@ -473,6 +501,8 @@ export class CommentsApi extends runtime.BaseAPI {

const headerParameters: runtime.HTTPHeaders = {};

headerParameters['Content-Type'] = 'application/json';

if (this.configuration && (this.configuration.username !== undefined || this.configuration.password !== undefined)) {
headerParameters["Authorization"] = "Basic " + btoa(this.configuration.username + ":" + this.configuration.password);
}
Expand All @@ -489,6 +519,7 @@ export class CommentsApi extends runtime.BaseAPI {
method: 'DELETE',
headers: headerParameters,
query: queryParameters,
body: PinCommentRequestBodyToJSON(params.metadata),
}, initOverrides);

return new runtime.JSONApiResponse(response, (jsonValue) => WriteResponseFromJSON(jsonValue));
Expand All @@ -515,6 +546,10 @@ export class CommentsApi extends runtime.BaseAPI {
throw new runtime.RequiredError('userId','Required parameter params.userId was null or undefined when calling unreactToComment.');
}

if (params.metadata === null || params.metadata === undefined) {
throw new runtime.RequiredError('metadata','Required parameter params.metadata was null or undefined when calling unreactToComment.');
}

const queryParameters: any = {};

if (params.userId !== undefined) {
Expand All @@ -523,6 +558,8 @@ export class CommentsApi extends runtime.BaseAPI {

const headerParameters: runtime.HTTPHeaders = {};

headerParameters['Content-Type'] = 'application/json';

if (this.configuration && (this.configuration.username !== undefined || this.configuration.password !== undefined)) {
headerParameters["Authorization"] = "Basic " + btoa(this.configuration.username + ":" + this.configuration.password);
}
Expand All @@ -539,6 +576,7 @@ export class CommentsApi extends runtime.BaseAPI {
method: 'DELETE',
headers: headerParameters,
query: queryParameters,
body: ReactCommentRequestBodyToJSON(params.metadata),
}, initOverrides);

return new runtime.JSONApiResponse(response, (jsonValue) => WriteResponseFromJSON(jsonValue));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@


/**
* Type of entity that can be commented on
*
* @export
*/
export const CommentEntityType = {
Expand Down
Loading
Loading