v3/packages/misc-utils/guildListing.ts
Katalina 99952aa19f
Feat/recent guilds (#89) (#167)
* feat(web): add server-setup page for when bot isn't in the server picked

* chore: move contexts into their own folder

* feat(web): add recent guilds context, and app shell helper context

* feat(web): show recent guilds in masthead

* feat(web): functionally add recents to servers list

* fix(web): correct styling for servers listing recents/all headers

* fix(web): correct some type issues with appShellProps

* fix(web): don't show ServerListing recents when recents is empty
2021-03-13 19:31:36 -05:00

26 lines
739 B
TypeScript

import { sortBy } from '@roleypoly/misc-utils/sortBy';
import { GuildSlug } from '@roleypoly/types';
type RecentAndSortedT = {
recentGuildSlugs: GuildSlug[];
sortedGuildSlugs: GuildSlug[];
};
export const getRecentAndSortedGuilds = (
guilds: GuildSlug[],
recentGuilds: string[]
): RecentAndSortedT => {
return {
recentGuildSlugs: recentGuilds.reduce<GuildSlug[]>((acc, id) => {
const guild = guilds.find((guild) => guild.id === id);
if (guild) {
acc.push(guild);
}
return acc;
}, []),
sortedGuildSlugs: sortBy(guilds, 'name', (a: string, b: string) =>
a.toLowerCase() > b.toLowerCase() ? 1 : -1
),
};
};