Skip to content
This repository has been archived by the owner on Feb 17, 2025. It is now read-only.

Commit

Permalink
fix: Fix loading of conversation when opening tag (#162)
Browse files Browse the repository at this point in the history
  • Loading branch information
taustad authored Oct 10, 2023
1 parent 9b173ae commit efbb1c9
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 16 deletions.
2 changes: 1 addition & 1 deletion src/Components/SideSheet/Comments/CommentSideSheet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ const CommentSideSheet: FC<Props> = ({
(async () => {
try {
if (!activeTagData?.tagNo || !currentContext.currentContext?.externalId) { return }
const newConversations = await (await GetConversationService()).getConversationsForTag(
const newConversations = await (await GetConversationService()).getConversations(
currentContext.currentContext?.externalId,
activeTagData.tagNo,
true,
Expand Down
8 changes: 5 additions & 3 deletions src/Components/SideSheet/Comments/Components/CommentView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,12 @@ const CommentView: React.FC<CommentViewProps> = ({
try {
const currentConversationId = getConversationForProperty(currentProperty)?.id

if (currentConversationId) {
const currentConversation = await (await GetMessageService()).getMessagesForConversation(
if (currentConversationId && currentContext.currentContext && activeTagData?.tagNo) {
const currentConversation = await (await GetConversationService()).getConversation(
currentContext.currentContext.id,
activeTagData?.tagNo,
currentConversationId,
)
)
setActiveConversation(currentConversation)
} else {
setActiveConversation(undefined)
Expand Down
16 changes: 5 additions & 11 deletions src/Views/JIP33InstrumentTabView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,11 @@ function JIP33InstrumentTabView({ }) {
setCurrentProperty("")
}, [setOpen])

const getConversationsForTagReview = async (id: string) => {
if (!currentContext.currentContext?.externalId || !activeTagData?.tagNo) { return }
const getConversationsForTagReview = async (tagNo: string) => {
if (!currentContext.currentContext?.externalId) { return }
const newConversations = await (
await GetConversationService()
).getConversationsForTag(currentContext.currentContext.externalId, activeTagData.tagNo, true)
).getConversations(currentContext.currentContext.externalId, tagNo, true)
setConversations(newConversations)
}

Expand All @@ -128,13 +128,7 @@ function JIP33InstrumentTabView({ }) {
).getTagData(tagId)
setActiveTagData(tagData)

const tagDataReviewId = tagData?.review?.id
if (
tagDataReviewId !== null
&& tagDataReviewId !== undefined
) {
await getConversationsForTagReview(tagDataReviewId)
}
await getConversationsForTagReview(tagId)

setIsLoading(false)
} catch {
Expand All @@ -143,7 +137,7 @@ function JIP33InstrumentTabView({ }) {
}
}
})()
}, [])
}, [tagId])

if (error) {
return <Dialogue type="error" message="Error loading tag" />
Expand Down
9 changes: 8 additions & 1 deletion src/api/ConversationService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,20 @@ import { BaseService } from "./BaseService"
import { config, GetToken, LoginAccessTokenKey } from "./config"

class ConversationService extends BaseService {
async getConversationsForTag(projectId: string, tagNo: string, includeLatestMessage: boolean = false) {
async getConversations(projectId: string, tagNo: string, includeLatestMessage: boolean = false) {
const result: Components.Schemas.GetConversationDto[] = await this.get(
`${projectId}/tags/${tagNo}/conversations?includeLatestMessage=${includeLatestMessage}`,
)
return result
}

async getConversation(projectId: string, tagNo: string, conversationId: string) {
const result: Components.Schemas.GetConversationDto = await this.get(
`${projectId}/tags/${tagNo}/conversations/${conversationId}`,
)
return result
}

async createConversation(projectId: string, tagNo: string, message: Components.Schemas.ConversationDto) {
const result: Components.Schemas.ConversationDto = await this.post(
`${projectId}/tags/${tagNo}/conversations`,
Expand Down

0 comments on commit efbb1c9

Please sign in to comment.