mirror of
https://github.com/roleypoly/roleypoly.git
synced 2025-04-26 04:19:11 +00:00
feat(web): show recent guilds in masthead
This commit is contained in:
parent
8ace9abf63
commit
f01325cfba
8 changed files with 81 additions and 37 deletions
|
@ -9,6 +9,7 @@ import { GuildNavItem } from './GuildNav.styled';
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
guilds: GuildSlug[];
|
guilds: GuildSlug[];
|
||||||
|
recentGuilds: string[];
|
||||||
};
|
};
|
||||||
|
|
||||||
const tooltipId = 'guildnav';
|
const tooltipId = 'guildnav';
|
||||||
|
@ -27,7 +28,36 @@ const Badges = (props: { guild: GuildSlug }) => {
|
||||||
}, [props.guild.permissionLevel]);
|
}, [props.guild.permissionLevel]);
|
||||||
};
|
};
|
||||||
|
|
||||||
export const GuildNav = (props: Props) => (
|
const NavList = (props: { guilds: Props['guilds'] }) => (
|
||||||
|
<>
|
||||||
|
{props.guilds.map((guild) => (
|
||||||
|
<GuildNavItem href={`/s/${guild.id}`} key={guild.id}>
|
||||||
|
<NavSlug guild={guild || null} key={guild.id} />
|
||||||
|
<Badges guild={guild} />
|
||||||
|
</GuildNavItem>
|
||||||
|
))}
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
|
||||||
|
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
|
||||||
|
);
|
||||||
|
|
||||||
|
return (
|
||||||
<div>
|
<div>
|
||||||
<Scrollbars
|
<Scrollbars
|
||||||
universal
|
universal
|
||||||
|
@ -35,15 +65,16 @@ export const GuildNav = (props: Props) => (
|
||||||
// autoHeight
|
// autoHeight
|
||||||
style={{ height: 'calc(100vh - 45px - 1.4em)', overflowX: 'hidden' }}
|
style={{ height: 'calc(100vh - 45px - 1.4em)', overflowX: 'hidden' }}
|
||||||
>
|
>
|
||||||
{sortBy(props.guilds, 'name', (a: string, b: string) =>
|
{recentGuildSlugs && (
|
||||||
a.toLowerCase() > b.toLowerCase() ? 1 : -1
|
<>
|
||||||
).map((guild) => (
|
<div>Recents</div>
|
||||||
<GuildNavItem href={`/s/${guild.id}`} key={guild.id}>
|
<NavList guilds={recentGuildSlugs} />
|
||||||
<NavSlug guild={guild || null} key={guild.id} />
|
<div>All Guilds</div>
|
||||||
<Badges guild={guild} />
|
</>
|
||||||
</GuildNavItem>
|
)}
|
||||||
))}
|
<NavList guilds={sortedSlugs} />
|
||||||
<ReactTooltip id={tooltipId} />
|
<ReactTooltip id={tooltipId} />
|
||||||
</Scrollbars>
|
</Scrollbars>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
};
|
||||||
|
|
|
@ -69,7 +69,7 @@ export const Authed = (props: Props) => {
|
||||||
{() => (
|
{() => (
|
||||||
<GuildNav
|
<GuildNav
|
||||||
guilds={props.guilds}
|
guilds={props.guilds}
|
||||||
recentGuilds={props.recentGuilds}
|
recentGuilds={props.recentGuilds || []}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
</Popover>
|
</Popover>
|
||||||
|
|
|
@ -8,9 +8,15 @@ import * as React from 'react';
|
||||||
export type RolePickerTemplateProps = RolePickerProps & Omit<AppShellProps, 'children'>;
|
export type RolePickerTemplateProps = RolePickerProps & Omit<AppShellProps, 'children'>;
|
||||||
|
|
||||||
export const RolePickerTemplate = (props: RolePickerTemplateProps) => {
|
export const RolePickerTemplate = (props: RolePickerTemplateProps) => {
|
||||||
const { user, guilds, activeGuildId, ...pickerProps } = props;
|
const { user, guilds, activeGuildId, recentGuilds, ...pickerProps } = props;
|
||||||
return (
|
return (
|
||||||
<AppShell activeGuildId={activeGuildId} user={user} guilds={guilds} small>
|
<AppShell
|
||||||
|
activeGuildId={activeGuildId}
|
||||||
|
user={user}
|
||||||
|
guilds={guilds}
|
||||||
|
recentGuilds={recentGuilds}
|
||||||
|
small
|
||||||
|
>
|
||||||
<RolePicker {...pickerProps} />
|
<RolePicker {...pickerProps} />
|
||||||
</AppShell>
|
</AppShell>
|
||||||
);
|
);
|
||||||
|
|
|
@ -1,11 +1,8 @@
|
||||||
import { AppShell, AppShellProps } from '@roleypoly/design-system/organisms/app-shell';
|
import { AppShell, AppShellProps } from '@roleypoly/design-system/organisms/app-shell';
|
||||||
import { ServersListing } from '@roleypoly/design-system/organisms/servers-listing/ServersListing';
|
import { ServersListing } from '@roleypoly/design-system/organisms/servers-listing/ServersListing';
|
||||||
import { GuildSlug } from '@roleypoly/types';
|
|
||||||
import * as React from 'react';
|
import * as React from 'react';
|
||||||
|
|
||||||
type ServerTemplateProps = Omit<AppShellProps, 'children'> & {
|
type ServerTemplateProps = Omit<AppShellProps, 'children'>;
|
||||||
guilds: GuildSlug[];
|
|
||||||
};
|
|
||||||
|
|
||||||
export const ServersTemplate = (props: ServerTemplateProps) => (
|
export const ServersTemplate = (props: ServerTemplateProps) => (
|
||||||
<AppShell {...props} disableGuildPicker>
|
<AppShell {...props} disableGuildPicker>
|
||||||
|
|
|
@ -3,11 +3,17 @@ import * as React from 'react';
|
||||||
import { useRecentGuilds } from '../recent-guilds/RecentGuildsContext';
|
import { useRecentGuilds } from '../recent-guilds/RecentGuildsContext';
|
||||||
import { useSessionContext } from '../session/SessionContext';
|
import { useSessionContext } from '../session/SessionContext';
|
||||||
|
|
||||||
type AppShellPropsT = {
|
type AppShellPropsT =
|
||||||
user: AppShellProps['user'];
|
| {
|
||||||
guilds: AppShellProps['guilds'];
|
user: Required<AppShellProps['user']>;
|
||||||
recentGuilds: AppShellProps['recentGuilds'];
|
guilds: Required<AppShellProps['guilds']>;
|
||||||
};
|
recentGuilds: Required<AppShellProps['recentGuilds']>;
|
||||||
|
}
|
||||||
|
| {
|
||||||
|
user: undefined;
|
||||||
|
guilds: undefined;
|
||||||
|
recentGuilds: [];
|
||||||
|
};
|
||||||
|
|
||||||
export const AppShellPropsContext = React.createContext<AppShellPropsT>({
|
export const AppShellPropsContext = React.createContext<AppShellPropsT>({
|
||||||
user: undefined,
|
user: undefined,
|
||||||
|
|
|
@ -1,16 +1,18 @@
|
||||||
import { Redirect } from '@reach/router';
|
import { Redirect } from '@reach/router';
|
||||||
import { LandingTemplate } from '@roleypoly/design-system/templates/landing';
|
import { LandingTemplate } from '@roleypoly/design-system/templates/landing';
|
||||||
import * as React from 'react';
|
import * as React from 'react';
|
||||||
|
import { useAppShellProps } from '../contexts/app-shell/AppShellContext';
|
||||||
import { useSessionContext } from '../contexts/session/SessionContext';
|
import { useSessionContext } from '../contexts/session/SessionContext';
|
||||||
|
|
||||||
const Landing = () => {
|
const Landing = () => {
|
||||||
const { isAuthenticated } = useSessionContext();
|
const { isAuthenticated } = useSessionContext();
|
||||||
|
const appShellProps = useAppShellProps();
|
||||||
|
|
||||||
if (isAuthenticated) {
|
if (isAuthenticated) {
|
||||||
return <Redirect to="/servers" />;
|
return <Redirect to="/servers" />;
|
||||||
}
|
}
|
||||||
|
|
||||||
return <LandingTemplate />;
|
return <LandingTemplate {...appShellProps} />;
|
||||||
};
|
};
|
||||||
|
|
||||||
export default Landing;
|
export default Landing;
|
||||||
|
|
|
@ -3,6 +3,7 @@ import { RolePickerTemplate } from '@roleypoly/design-system/templates/role-pick
|
||||||
import { ServerSetupTemplate } from '@roleypoly/design-system/templates/server-setup';
|
import { ServerSetupTemplate } from '@roleypoly/design-system/templates/server-setup';
|
||||||
import { PresentableGuild, RoleUpdate, UserGuildPermissions } from '@roleypoly/types';
|
import { PresentableGuild, RoleUpdate, UserGuildPermissions } from '@roleypoly/types';
|
||||||
import * as React from 'react';
|
import * as React from 'react';
|
||||||
|
import { useAppShellProps } from '../contexts/app-shell/AppShellContext';
|
||||||
import { useRecentGuilds } from '../contexts/recent-guilds/RecentGuildsContext';
|
import { useRecentGuilds } from '../contexts/recent-guilds/RecentGuildsContext';
|
||||||
import { useSessionContext } from '../contexts/session/SessionContext';
|
import { useSessionContext } from '../contexts/session/SessionContext';
|
||||||
import { makeRoleTransactions } from '../utils/roleTransactions';
|
import { makeRoleTransactions } from '../utils/roleTransactions';
|
||||||
|
@ -14,6 +15,7 @@ type PickerProps = {
|
||||||
const Picker = (props: PickerProps) => {
|
const Picker = (props: PickerProps) => {
|
||||||
const { session, authedFetch, isAuthenticated } = useSessionContext();
|
const { session, authedFetch, isAuthenticated } = useSessionContext();
|
||||||
const { pushRecentGuild } = useRecentGuilds();
|
const { pushRecentGuild } = useRecentGuilds();
|
||||||
|
const appShellProps = useAppShellProps();
|
||||||
|
|
||||||
const [pickerData, setPickerData] = React.useState<PresentableGuild | null | false>(
|
const [pickerData, setPickerData] = React.useState<PresentableGuild | null | false>(
|
||||||
null
|
null
|
||||||
|
@ -58,9 +60,8 @@ const Picker = (props: PickerProps) => {
|
||||||
return (
|
return (
|
||||||
<ServerSetupTemplate
|
<ServerSetupTemplate
|
||||||
activeGuildId={props.serverID}
|
activeGuildId={props.serverID}
|
||||||
user={session.user}
|
|
||||||
guilds={session.guilds || []}
|
|
||||||
guildSlug={guildSlug}
|
guildSlug={guildSlug}
|
||||||
|
{...appShellProps}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -96,8 +97,7 @@ const Picker = (props: PickerProps) => {
|
||||||
return (
|
return (
|
||||||
<RolePickerTemplate
|
<RolePickerTemplate
|
||||||
activeGuildId={props.serverID}
|
activeGuildId={props.serverID}
|
||||||
user={session?.user}
|
{...appShellProps}
|
||||||
guilds={session?.guilds || []}
|
|
||||||
guild={pickerData.guild}
|
guild={pickerData.guild}
|
||||||
guildData={pickerData.data}
|
guildData={pickerData.data}
|
||||||
member={pickerData.member}
|
member={pickerData.member}
|
||||||
|
|
|
@ -1,15 +1,17 @@
|
||||||
import { Redirect } from '@reach/router';
|
import { Redirect } from '@reach/router';
|
||||||
import { ServersTemplate } from '@roleypoly/design-system/templates/servers';
|
import { ServersTemplate } from '@roleypoly/design-system/templates/servers';
|
||||||
import * as React from 'react';
|
import * as React from 'react';
|
||||||
|
import { useAppShellProps } from '../contexts/app-shell/AppShellContext';
|
||||||
import { useSessionContext } from '../contexts/session/SessionContext';
|
import { useSessionContext } from '../contexts/session/SessionContext';
|
||||||
|
|
||||||
const ServersPage = () => {
|
const ServersPage = () => {
|
||||||
const { isAuthenticated, session } = useSessionContext();
|
const { isAuthenticated, session } = useSessionContext();
|
||||||
|
const appShellProps = useAppShellProps();
|
||||||
if (!isAuthenticated || !session) {
|
if (!isAuthenticated || !session) {
|
||||||
return <Redirect to="/" />;
|
return <Redirect to="/" />;
|
||||||
}
|
}
|
||||||
|
|
||||||
return <ServersTemplate guilds={session.guilds || []} user={session.user} />;
|
return <ServersTemplate {...appShellProps} />;
|
||||||
};
|
};
|
||||||
|
|
||||||
export default ServersPage;
|
export default ServersPage;
|
||||||
|
|
Loading…
Add table
Reference in a new issue