mirror of
https://github.com/roleypoly/roleypoly.git
synced 2025-04-25 11:59:11 +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
|
@ -1,5 +1,5 @@
|
|||
import { NavSlug } from '@roleypoly/design-system/molecules/nav-slug';
|
||||
import { sortBy } from '@roleypoly/misc-utils/sortBy';
|
||||
import { getRecentAndSortedGuilds } from '@roleypoly/misc-utils/guildListing';
|
||||
import { GuildSlug, UserGuildPermissions } from '@roleypoly/types';
|
||||
import * as React from 'react';
|
||||
import Scrollbars from 'react-custom-scrollbars';
|
||||
|
@ -40,21 +40,9 @@ const NavList = (props: { guilds: Props['guilds'] }) => (
|
|||
);
|
||||
|
||||
export const GuildNav = (props: Props) => {
|
||||
const recentGuildSlugs: GuildSlug[] = props.recentGuilds
|
||||
.reduce<(GuildSlug | undefined)[]>(
|
||||
(acc, id) => [...acc, props.guilds.find((guild) => guild.id === id)],
|
||||
[]
|
||||
)
|
||||
.filter((slug) => slug !== undefined);
|
||||
|
||||
console.log({
|
||||
recentGuilds: props.recentGuilds,
|
||||
slugs: props.guilds,
|
||||
recentSlugs: recentGuildSlugs,
|
||||
});
|
||||
|
||||
const sortedSlugs = sortBy(props.guilds, 'name', (a: string, b: string) =>
|
||||
a.toLowerCase() > b.toLowerCase() ? 1 : -1
|
||||
const { sortedGuildSlugs, recentGuildSlugs } = getRecentAndSortedGuilds(
|
||||
props.guilds,
|
||||
props.recentGuilds
|
||||
);
|
||||
|
||||
return (
|
||||
|
@ -72,7 +60,7 @@ export const GuildNav = (props: Props) => {
|
|||
<div>All Guilds</div>
|
||||
</>
|
||||
)}
|
||||
<NavList guilds={sortedSlugs} />
|
||||
<NavList guilds={sortedGuildSlugs} />
|
||||
<ReactTooltip id={tooltipId} />
|
||||
</Scrollbars>
|
||||
</div>
|
||||
|
|
|
@ -1,20 +1,18 @@
|
|||
import { CompletelyStylelessLink } from '@roleypoly/design-system/atoms/typography';
|
||||
import { ServerListingCard } from '@roleypoly/design-system/molecules/server-listing-card';
|
||||
import { sortBy } from '@roleypoly/misc-utils/sortBy';
|
||||
import { getRecentAndSortedGuilds } from '@roleypoly/misc-utils/guildListing';
|
||||
import { GuildSlug } from '@roleypoly/types';
|
||||
import * as React from 'react';
|
||||
import { CardContainer, ContentContainer } from './ServersListing.styled';
|
||||
|
||||
type ServersListingProps = {
|
||||
guilds: GuildSlug[];
|
||||
recentGuilds: string[];
|
||||
};
|
||||
|
||||
export const ServersListing = (props: ServersListingProps) => (
|
||||
<ContentContainer>
|
||||
{props.guilds &&
|
||||
sortBy(props.guilds, 'name', (a: string, b: string) =>
|
||||
a.toLowerCase() > b.toLowerCase() ? 1 : -1
|
||||
).map((guild, idx) => (
|
||||
const CardList = (props: { guilds: GuildSlug[] }) => (
|
||||
<>
|
||||
{props.guilds.map((guild, idx) => (
|
||||
<CardContainer key={idx}>
|
||||
<a href={`/s/${guild.id}`}>
|
||||
<CompletelyStylelessLink>
|
||||
|
@ -23,5 +21,25 @@ export const ServersListing = (props: ServersListingProps) => (
|
|||
</a>
|
||||
</CardContainer>
|
||||
))}
|
||||
</ContentContainer>
|
||||
</>
|
||||
);
|
||||
|
||||
export const ServersListing = (props: ServersListingProps) => {
|
||||
const { recentGuildSlugs, sortedGuildSlugs } = getRecentAndSortedGuilds(
|
||||
props.guilds,
|
||||
props.recentGuilds
|
||||
);
|
||||
|
||||
return (
|
||||
<ContentContainer>
|
||||
{recentGuildSlugs && (
|
||||
<>
|
||||
<div>Recent Guilds</div>
|
||||
<CardList guilds={recentGuildSlugs} />
|
||||
<div>All Guilds</div>
|
||||
</>
|
||||
)}
|
||||
<CardList guilds={sortedGuildSlugs} />
|
||||
</ContentContainer>
|
||||
);
|
||||
};
|
||||
|
|
|
@ -6,6 +6,9 @@ type ServerTemplateProps = Omit<AppShellProps, 'children'>;
|
|||
|
||||
export const ServersTemplate = (props: ServerTemplateProps) => (
|
||||
<AppShell {...props} disableGuildPicker>
|
||||
<ServersListing guilds={props.guilds}></ServersListing>
|
||||
<ServersListing
|
||||
guilds={props.guilds}
|
||||
recentGuilds={props.recentGuilds}
|
||||
></ServersListing>
|
||||
</AppShell>
|
||||
);
|
||||
|
|
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
Reference in a new issue