fix: display index sort

This commit is contained in:
hamster1963 2024-09-29 11:10:25 +08:00
parent f537663892
commit b3f8e8ca8e

View File

@ -14,19 +14,33 @@ export default function ServerListClient() {
<div className="flex flex-col items-center justify-center"> <div className="flex flex-col items-center justify-center">
<p className="text-sm font-medium opacity-40">{error.message}</p> <p className="text-sm font-medium opacity-40">{error.message}</p>
<p className="text-sm font-medium opacity-40"> <p className="text-sm font-medium opacity-40">
Please check your environment variables and review the server console logs for more details. Please check your environment variables and review the server console
logs for more details.
</p> </p>
</div> </div>
); );
if (!data) return null; if (!data) return null;
const sortedServers = data.result.sort((a, b) => {
if (a.display_index && b.display_index) { const { result } = data;
return b.display_index - a.display_index;
} const positiveDisplayIndex = result
if (a.display_index) return -1; .filter((server) => server.display_index > 0)
if (b.display_index) return 1; .sort((a, b) => b.display_index - a.display_index);
return a.id - b.id;
}); 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,
];
return ( return (
<section className="grid grid-cols-1 gap-2 md:grid-cols-2"> <section className="grid grid-cols-1 gap-2 md:grid-cols-2">
{sortedServers.map((serverInfo) => ( {sortedServers.map((serverInfo) => (