Skip to content

Commit

Permalink
Sorted the conversationss by desc
Browse files Browse the repository at this point in the history
  • Loading branch information
JackWaz28 committed Feb 11, 2022
1 parent c6d2c77 commit eaaa374
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/components/Messaging/AllConversations.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export default function AllConversations() {
const conversationToCreate = {
users: [newUser, user.uid],
messages: [newMessage],
//createdAt: timestamp.fromDate(new Date()),
createdAt: timestamp.fromDate(new Date()),
updatedAt: timestamp.fromDate(new Date()),
title: newTitle,
Expand Down
4 changes: 2 additions & 2 deletions src/components/Messaging/AllMessages.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { useState } from "react"
import { timestamp } from "../../firebase/fbConfig"
import { useAuthContext } from "../../hooks/useAuthContext"
import { useFirestore } from "../../hooks/useFirestore"
import Avatar from "../UI/Avatar"
// import Avatar from "../UI/Avatar"
import Sidebar from "../Dashboard/Sidebar"
import { Link } from "react-router-dom"

Expand All @@ -24,7 +24,7 @@ export default function AllMessages({ conversation }) {

await updateDocument(conversation.id, {
messages: [...conversation.messages, messageToAdd],
updatedAt: timestamp.fromDate(new Date())
updatedAt: timestamp.now()
})
if (!response.error) {
setNewMessage('')
Expand Down
3 changes: 2 additions & 1 deletion src/hooks/useAllConversations.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ export const useAllConversations = (id) => {
// realtime document data
useEffect(() => {
const conversationsRef = projectFirestore.collection('conversations')
let userConversations = conversationsRef.where('users', 'array-contains', id)
let userConversations = conversationsRef.where('users', 'array-contains', id).orderBy('updatedAt', 'desc')
//let orderedUserConversations = userConversations.orderBy('updatedAt')

const unsubscribe = userConversations.onSnapshot(snapshot => {
// need to make sure the doc exists & has data
Expand Down

0 comments on commit eaaa374

Please sign in to comment.