Skip to content

Commit

Permalink
fix: jitter caused by the same display_index
Browse files Browse the repository at this point in the history
  • Loading branch information
hamster1963 committed Sep 30, 2024
1 parent 4ace10a commit af73ef4
Showing 1 changed file with 5 additions and 17 deletions.
22 changes: 5 additions & 17 deletions app/[locale]/(main)/ClientComponents/ServerListClient.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
<section className="grid grid-cols-1 gap-2 md:grid-cols-2">
Expand Down

0 comments on commit af73ef4

Please sign in to comment.