mirror of
https://github.com/roleypoly/roleypoly.git
synced 2025-06-17 01:59:08 +00:00
feat(web): functionally add recents to servers list
This commit is contained in:
parent
f01325cfba
commit
994d7bba2c
4 changed files with 69 additions and 34 deletions
26
packages/misc-utils/guildListing.ts
Normal file
26
packages/misc-utils/guildListing.ts
Normal file
|
@ -0,0 +1,26 @@
|
|||
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
|
||||
),
|
||||
};
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue