diff --git a/backend/src/main/java/com/petshop/backend/repository/ConversationRepository.java b/backend/src/main/java/com/petshop/backend/repository/ConversationRepository.java index 98d457b8..9ec1fde9 100644 --- a/backend/src/main/java/com/petshop/backend/repository/ConversationRepository.java +++ b/backend/src/main/java/com/petshop/backend/repository/ConversationRepository.java @@ -8,7 +8,8 @@ import java.util.List; @Repository public interface ConversationRepository extends JpaRepository { - List findByCustomerId(Long customerId); - List findByStaffId(Long staffId); - List findByStaffIdIsNull(); + List findByCustomerIdOrderByUpdatedAtDesc(Long customerId); + List findByStaffIdOrderByUpdatedAtDesc(Long staffId); + List findByStaffIdIsNullOrderByUpdatedAtDesc(); + List findAllByOrderByUpdatedAtDesc(); } diff --git a/backend/src/main/java/com/petshop/backend/repository/RefundRepository.java b/backend/src/main/java/com/petshop/backend/repository/RefundRepository.java index b71dde0c..92ba34a8 100644 --- a/backend/src/main/java/com/petshop/backend/repository/RefundRepository.java +++ b/backend/src/main/java/com/petshop/backend/repository/RefundRepository.java @@ -8,6 +8,7 @@ import java.util.List; @Repository public interface RefundRepository extends JpaRepository { - List findByCustomerId(Long customerId); + List findByCustomerIdOrderByCreatedAtDesc(Long customerId); + List findAllByOrderByCreatedAtDesc(); List findBySaleId(Long saleId); } diff --git a/backend/src/main/java/com/petshop/backend/service/ChatService.java b/backend/src/main/java/com/petshop/backend/service/ChatService.java index 0e80fc1a..138b5006 100644 --- a/backend/src/main/java/com/petshop/backend/service/ChatService.java +++ b/backend/src/main/java/com/petshop/backend/service/ChatService.java @@ -73,14 +73,14 @@ public class ChatService { List conversations; if (mine || role == User.Role.CUSTOMER) { - conversations = conversationRepository.findByCustomerId(userId); + conversations = conversationRepository.findByCustomerIdOrderByUpdatedAtDesc(userId); } else if (role == User.Role.STAFF) { - List assignedToMe = conversationRepository.findByStaffId(userId); - List unassigned = conversationRepository.findByStaffIdIsNull(); + List assignedToMe = conversationRepository.findByStaffIdOrderByUpdatedAtDesc(userId); + List unassigned = conversationRepository.findByStaffIdIsNullOrderByUpdatedAtDesc(); conversations = new java.util.ArrayList<>(assignedToMe); conversations.addAll(unassigned); } else { - conversations = conversationRepository.findAll(); + conversations = conversationRepository.findAllByOrderByUpdatedAtDesc(); } return conversations.stream() diff --git a/backend/src/main/java/com/petshop/backend/service/RefundService.java b/backend/src/main/java/com/petshop/backend/service/RefundService.java index 90bf397b..961efb24 100644 --- a/backend/src/main/java/com/petshop/backend/service/RefundService.java +++ b/backend/src/main/java/com/petshop/backend/service/RefundService.java @@ -100,9 +100,9 @@ public class RefundService { List refunds; if (customerId != null) { - refunds = refundRepository.findByCustomerId(customerId); + refunds = refundRepository.findByCustomerIdOrderByCreatedAtDesc(customerId); } else { - refunds = refundRepository.findAll(); + refunds = refundRepository.findAllByOrderByCreatedAtDesc(); } return refunds.stream() diff --git a/web/app/chat/page.js b/web/app/chat/page.js index 20ed7f41..7feeb5dd 100644 --- a/web/app/chat/page.js +++ b/web/app/chat/page.js @@ -45,9 +45,9 @@ function ChatPage() { lastScrolledIdRef.current = lastMsg.id; const area = messagesAreaRef.current; if (!area) return; - const nearBottom = area.scrollHeight - area.scrollTop - area.clientHeight < 150; + const nearBottom = area.scrollHeight - area.scrollTop - area.clientHeight < 80; if (nearBottom) { - messagesEndRef.current?.scrollIntoView({ behavior: "smooth" }); + area.scrollTop = area.scrollHeight; } }, [messages]);