From af73ef41fd45ef1927ecda03708e75ddec33ada8 Mon Sep 17 00:00:00 2001 From: hamster1963 <1410514192@qq.com> Date: Mon, 30 Sep 2024 09:05:29 +0800 Subject: [PATCH] fix: jitter caused by the same display_index --- .../ClientComponents/ServerListClient.tsx | 22 +++++-------------- 1 file changed, 5 insertions(+), 17 deletions(-) diff --git a/app/[locale]/(main)/ClientComponents/ServerListClient.tsx b/app/[locale]/(main)/ClientComponents/ServerListClient.tsx index ab96e56..6d4b586 100644 --- a/app/[locale]/(main)/ClientComponents/ServerListClient.tsx +++ b/app/[locale]/(main)/ClientComponents/ServerListClient.tsx @@ -23,23 +23,11 @@ export default function ServerListClient() { const { result } = data; - const positiveDisplayIndex = result - .filter((server) => server.display_index > 0) - .sort((a, b) => b.display_index - a.display_index); - - const noDisplayIndex = result - .filter((server) => !server.display_index) - .sort((a, b) => a.id - b.id); - - const negativeDisplayIndex = result - .filter((server) => server.display_index < 0) - .sort((a, b) => b.display_index - a.display_index); - - const sortedServers = [ - ...positiveDisplayIndex, - ...noDisplayIndex, - ...negativeDisplayIndex, - ]; + const sortedServers = result.sort((a, b) => { + const displayIndexDiff = (b.display_index || 0) - (a.display_index || 0); + if (displayIndexDiff !== 0) return displayIndexDiff; + return a.id - b.id; + }); return (