fix scroll sorting

This commit is contained in:
2026-04-15 13:05:50 -06:00
parent 762f01ae71
commit 1146d3c768
5 changed files with 14 additions and 12 deletions

View File

@@ -8,7 +8,8 @@ import java.util.List;
@Repository @Repository
public interface ConversationRepository extends JpaRepository<Conversation, Long> { public interface ConversationRepository extends JpaRepository<Conversation, Long> {
List<Conversation> findByCustomerId(Long customerId); List<Conversation> findByCustomerIdOrderByUpdatedAtDesc(Long customerId);
List<Conversation> findByStaffId(Long staffId); List<Conversation> findByStaffIdOrderByUpdatedAtDesc(Long staffId);
List<Conversation> findByStaffIdIsNull(); List<Conversation> findByStaffIdIsNullOrderByUpdatedAtDesc();
List<Conversation> findAllByOrderByUpdatedAtDesc();
} }

View File

@@ -8,6 +8,7 @@ import java.util.List;
@Repository @Repository
public interface RefundRepository extends JpaRepository<Refund, Long> { public interface RefundRepository extends JpaRepository<Refund, Long> {
List<Refund> findByCustomerId(Long customerId); List<Refund> findByCustomerIdOrderByCreatedAtDesc(Long customerId);
List<Refund> findAllByOrderByCreatedAtDesc();
List<Refund> findBySaleId(Long saleId); List<Refund> findBySaleId(Long saleId);
} }

View File

@@ -73,14 +73,14 @@ public class ChatService {
List<Conversation> conversations; List<Conversation> conversations;
if (mine || role == User.Role.CUSTOMER) { if (mine || role == User.Role.CUSTOMER) {
conversations = conversationRepository.findByCustomerId(userId); conversations = conversationRepository.findByCustomerIdOrderByUpdatedAtDesc(userId);
} else if (role == User.Role.STAFF) { } else if (role == User.Role.STAFF) {
List<Conversation> assignedToMe = conversationRepository.findByStaffId(userId); List<Conversation> assignedToMe = conversationRepository.findByStaffIdOrderByUpdatedAtDesc(userId);
List<Conversation> unassigned = conversationRepository.findByStaffIdIsNull(); List<Conversation> unassigned = conversationRepository.findByStaffIdIsNullOrderByUpdatedAtDesc();
conversations = new java.util.ArrayList<>(assignedToMe); conversations = new java.util.ArrayList<>(assignedToMe);
conversations.addAll(unassigned); conversations.addAll(unassigned);
} else { } else {
conversations = conversationRepository.findAll(); conversations = conversationRepository.findAllByOrderByUpdatedAtDesc();
} }
return conversations.stream() return conversations.stream()

View File

@@ -100,9 +100,9 @@ public class RefundService {
List<Refund> refunds; List<Refund> refunds;
if (customerId != null) { if (customerId != null) {
refunds = refundRepository.findByCustomerId(customerId); refunds = refundRepository.findByCustomerIdOrderByCreatedAtDesc(customerId);
} else { } else {
refunds = refundRepository.findAll(); refunds = refundRepository.findAllByOrderByCreatedAtDesc();
} }
return refunds.stream() return refunds.stream()

View File

@@ -45,9 +45,9 @@ function ChatPage() {
lastScrolledIdRef.current = lastMsg.id; lastScrolledIdRef.current = lastMsg.id;
const area = messagesAreaRef.current; const area = messagesAreaRef.current;
if (!area) return; if (!area) return;
const nearBottom = area.scrollHeight - area.scrollTop - area.clientHeight < 150; const nearBottom = area.scrollHeight - area.scrollTop - area.clientHeight < 80;
if (nearBottom) { if (nearBottom) {
messagesEndRef.current?.scrollIntoView({ behavior: "smooth" }); area.scrollTop = area.scrollHeight;
} }
}, [messages]); }, [messages]);