enBloc-org / kindly

GNU General Public License v3.0
12 stars 16 forks source link

#133/set-new-conversation-as-current-conversation #176

Closed oskarprzybylski23 closed 1 month ago

oskarprzybylski23 commented 2 months ago

Checklist:

Description

Relates #133 Closes #133

This PR introduced sorting of conversations chronologically based on joined_at field. When a new conversation is started and user is redirected to /conversations, new conversation sits at the top of the list and is opened as the current conversation by deafult.

Note: this fix sorts conversations based on when conversation was created and not based on latest message. E.g. when you send a new message the related conversation will not move to the top of the stack. This feature may be desired and should be further discussed.

Files changed

components/messaging/ConversationList.tsx

const sortedConversations = allConversations.sort(
    (a, b) => new Date(b.joined_at).getTime() - new Date(a.joined_at).getTime()
  );  //added sorting based on joined_at

  return (
    <div className='m-4'>
      {allConversations.length > 0 ? (
        sortedConversations.map((conversation, index) => ( //using sortedConversations to get conversations rendered on the page
          <div key={`${conversation.id}-${index}`}>
            <ConversationCard
              conversationId={conversation.conversation_id}
              joinedAt={conversation.joined_at}
              itemName={conversation.items.item_name}
              imageSrc={conversation.items.imageSrc}
              clickHandler={() => updateOpenConvo(conversation.conversation_id)}
            />
          </div>
        ))
      ) : (
        <p>There are no active conversations</p>
      )}
    </div>
  ); 

UI changes

No changes to UI as part of this PR, other than conversation now appear in order in which they were created.

Changes to Documentation

No changes needed as part of this PR

Tests

It is a minor change and it didn't require new tests in my opinion.

vercel[bot] commented 2 months ago

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
kindly-v2zt ✅ Ready (Inspect) Visit Preview Apr 16, 2024 11:39am
netlify[bot] commented 2 months ago

Deploy Preview for hilarious-gnome-af728f failed.

Name Link
Latest commit 62b2649b70ba4c86475e0066d7fa94681ce90036
Latest deploy log https://app.netlify.com/sites/hilarious-gnome-af728f/deploys/66224590c5a3030008d91fa7
netlify[bot] commented 2 months ago

Deploy Preview for cool-creponne-3e1272 ready!

Name Link
Latest commit 62b2649b70ba4c86475e0066d7fa94681ce90036
Latest deploy log https://app.netlify.com/sites/cool-creponne-3e1272/deploys/6622459018bbaa0008fbd63b
Deploy Preview https://deploy-preview-176--cool-creponne-3e1272.netlify.app
Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

eliazzo commented 1 month ago

Thanks for this pr, it looks great 🤗 We have been discussing the feature and are leaning towards ordering the conversations by recent message so it looks like we no longer need this functionality. Keep on contributing!