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 { 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 { GuildSlug, UserGuildPermissions } from '@roleypoly/types';
|
||||||
import * as React from 'react';
|
import * as React from 'react';
|
||||||
import Scrollbars from 'react-custom-scrollbars';
|
import Scrollbars from 'react-custom-scrollbars';
|
||||||
|
@ -40,21 +40,9 @@ const NavList = (props: { guilds: Props['guilds'] }) => (
|
||||||
);
|
);
|
||||||
|
|
||||||
export const GuildNav = (props: Props) => {
|
export const GuildNav = (props: Props) => {
|
||||||
const recentGuildSlugs: GuildSlug[] = props.recentGuilds
|
const { sortedGuildSlugs, recentGuildSlugs } = getRecentAndSortedGuilds(
|
||||||
.reduce<(GuildSlug | undefined)[]>(
|
props.guilds,
|
||||||
(acc, id) => [...acc, props.guilds.find((guild) => guild.id === id)],
|
props.recentGuilds
|
||||||
[]
|
|
||||||
)
|
|
||||||
.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
|
|
||||||
);
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
@ -72,7 +60,7 @@ export const GuildNav = (props: Props) => {
|
||||||
<div>All Guilds</div>
|
<div>All Guilds</div>
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
<NavList guilds={sortedSlugs} />
|
<NavList guilds={sortedGuildSlugs} />
|
||||||
<ReactTooltip id={tooltipId} />
|
<ReactTooltip id={tooltipId} />
|
||||||
</Scrollbars>
|
</Scrollbars>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -1,27 +1,45 @@
|
||||||
import { CompletelyStylelessLink } from '@roleypoly/design-system/atoms/typography';
|
import { CompletelyStylelessLink } from '@roleypoly/design-system/atoms/typography';
|
||||||
import { ServerListingCard } from '@roleypoly/design-system/molecules/server-listing-card';
|
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 { GuildSlug } from '@roleypoly/types';
|
||||||
import * as React from 'react';
|
import * as React from 'react';
|
||||||
import { CardContainer, ContentContainer } from './ServersListing.styled';
|
import { CardContainer, ContentContainer } from './ServersListing.styled';
|
||||||
|
|
||||||
type ServersListingProps = {
|
type ServersListingProps = {
|
||||||
guilds: GuildSlug[];
|
guilds: GuildSlug[];
|
||||||
|
recentGuilds: string[];
|
||||||
};
|
};
|
||||||
|
|
||||||
export const ServersListing = (props: ServersListingProps) => (
|
const CardList = (props: { guilds: GuildSlug[] }) => (
|
||||||
<ContentContainer>
|
<>
|
||||||
{props.guilds &&
|
{props.guilds.map((guild, idx) => (
|
||||||
sortBy(props.guilds, 'name', (a: string, b: string) =>
|
<CardContainer key={idx}>
|
||||||
a.toLowerCase() > b.toLowerCase() ? 1 : -1
|
<a href={`/s/${guild.id}`}>
|
||||||
).map((guild, idx) => (
|
<CompletelyStylelessLink>
|
||||||
<CardContainer key={idx}>
|
<ServerListingCard guild={guild} />
|
||||||
<a href={`/s/${guild.id}`}>
|
</CompletelyStylelessLink>
|
||||||
<CompletelyStylelessLink>
|
</a>
|
||||||
<ServerListingCard guild={guild} />
|
</CardContainer>
|
||||||
</CompletelyStylelessLink>
|
))}
|
||||||
</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) => (
|
export const ServersTemplate = (props: ServerTemplateProps) => (
|
||||||
<AppShell {...props} disableGuildPicker>
|
<AppShell {...props} disableGuildPicker>
|
||||||
<ServersListing guilds={props.guilds}></ServersListing>
|
<ServersListing
|
||||||
|
guilds={props.guilds}
|
||||||
|
recentGuilds={props.recentGuilds}
|
||||||
|
></ServersListing>
|
||||||
</AppShell>
|
</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