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

Updating Conversation Queries #78

Merged
merged 6 commits into from
Jun 25, 2020
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
1 change: 1 addition & 0 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const App = () => {
<Route path="/tag" exact component={TagPage} />
<Route path="/tag/add" exact component={Tag} />
<Route path="/tag/:id/edit" exact component={Tag} />
{/* Doesn't this error without a passed in `contactId`? */}
Copy link
Contributor Author

@claalmve claalmve Jun 25, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because I was getting an error page on the default /chat route, I did a little digging into it, and I believe because contactId is never passed in for this route, the page will not render properly. So, I'm not completely sure how this worked before, or if I did something wrong on my end, but now to see the page properly, you need to add a ID at the end of the URL (i.e. localhost:3000/chat/2)

<Route path="/chat" exact component={ChatPage} />
<Route
exact
Expand Down
9 changes: 7 additions & 2 deletions src/containers/Chat/ChatConversations/ChatConversations.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,13 @@ export interface ChatConversationsProps {}
export const ChatConversations: React.SFC<ChatConversationsProps> = () => {
const { loading, error, data } = useQuery<any>(GET_CONVERSATION_QUERY, {
variables: {
count: 20,
size: 1,
contactOpts: {
limit: 20,
},
filter: {},
messageOpts: {
limit: 1,
},
},
});

Expand Down
4 changes: 3 additions & 1 deletion src/containers/Chat/ChatMessages/ChatMessages.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,11 @@ type OptionalChatQueryResult = ChatMessagesInterface | null;
export const ChatMessages: React.SFC<ChatMessagesProps> = ({ contactId }) => {
// let's get the conversation for last contacted contact.
const queryVariables = {
size: 25,
contactId: contactId,
filter: {},
messageOpts: {
limit: 25,
},
};
const { loading, error, data } = useQuery<any>(GET_CONVERSATION_MESSAGE_QUERY, {
variables: queryVariables,
Expand Down
38 changes: 19 additions & 19 deletions src/graphql/queries/Chat.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { gql } from '@apollo/client';

export const GET_CONVERSATION_QUERY = gql`
query conversations($count: Int!, $size: Int!) {
conversations(numberOfConversations: $count, sizeOfConversations: $size) {
query conversations($contactOpts: Opts!, $filter: ConversationsFilter!, $messageOpts: Opts!) {
conversations(contactOpts: $contactOpts, filter: $filter, messageOpts: $messageOpts) {
contact {
id
name
Expand All @@ -21,27 +21,27 @@ export const GET_CONVERSATION_QUERY = gql`
`;

export const GET_CONVERSATION_MESSAGE_QUERY = gql`
query conversation($size: Int!, $contactId: Gid!, $filter: ConversationFilter! ) {
conversation(sizeOfConversations: $size, contactId: $contactId, filter: $filter) {
contact {
id
name
}
messages {
id
body
insertedAt
receiver {
id
}
sender {
query conversation($contactId: Gid!, $filter: ConversationFilter!, $messageOpts: Opts!) {
conversation(contactId: $contactId, filter: $filter, messageOpts: $messageOpts) {
contact {
id
name
}
tags {
messages {
id
label
body
insertedAt
receiver {
id
}
sender {
id
}
tags {
id
label
}
}
}
}
}
`;