From 534aeaaef6a359bede27b69e79d42687b8d205e1 Mon Sep 17 00:00:00 2001 From: Elias Nahum Date: Wed, 30 Oct 2024 17:12:58 +0800 Subject: [PATCH] Fix sidebar teams order (#8281) --- .../team_sidebar/team_list/index.ts | 25 ++++++++----------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/app/components/team_sidebar/team_list/index.ts b/app/components/team_sidebar/team_list/index.ts index f8862828f..d30b8c24b 100644 --- a/app/components/team_sidebar/team_list/index.ts +++ b/app/components/team_sidebar/team_list/index.ts @@ -14,6 +14,7 @@ import {queryJoinedTeams, queryMyTeams} from '@queries/servers/team'; import TeamList from './team_list'; import type {WithDatabaseArgs} from '@typings/database/database'; +import type MyTeamModel from '@typings/database/models/servers/my_team'; const withTeams = withObservables([], ({database}: WithDatabaseArgs) => { const myTeams = queryMyTeams(database).observe(); @@ -33,22 +34,18 @@ const withTeams = withObservables([], ({database}: WithDatabaseArgs) => { map((t) => t.id); } - const indexes: {[x: string]: number} = {}; - const originalIndexes: {[x: string]: number} = {}; - ids.forEach((v, i) => { - indexes[v] = i; - }); + const teamMap = ts.reduce<{[x: string]: MyTeamModel}>((result, team) => { + result[team.id] = team; + return result; + }, {}); - ts.forEach((t, i) => { - originalIndexes[t.id] = i; - }); - - return ts.sort((a, b) => { - if ((indexes[a.id] != null) || (indexes[b.id] != null)) { - return (indexes[a.id] ?? tids.length) - (indexes[b.id] ?? tids.length); + return ids.reduce((result, id) => { + const t = teamMap[id]; + if (t) { + result.push(t); } - return (originalIndexes[a.id] - originalIndexes[b.id]); - }); + return result; + }, []); }), ); return {