Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat. link preview for role groups #1577

Merged
merged 2 commits into from
Dec 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
120 changes: 60 additions & 60 deletions src/pages/[guild]/[group].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,68 +66,61 @@ const GroupPage = (): JSX.Element => {
const { localThemeColor } = useThemeContext()

return (
<>
<Head>
<meta name="theme-color" content={localThemeColor} />
</Head>

<Layout>
<LayoutHero className="pb-24">
<LayoutBanner>
<GuildPageBanner />
</LayoutBanner>

<Header className="mb-10" />

<LayoutContainer className="-mb-16 mt-6 max-w-screen-xl">
<GuildImageAndName />
<Layout>
<LayoutHero className="pb-24">
<LayoutBanner>
<GuildPageBanner />
</LayoutBanner>

<Header className="mb-10" />

<LayoutContainer className="-mb-16 mt-6 max-w-screen-xl">
<GuildImageAndName />
</LayoutContainer>

<LayoutHeadline className="max-w-screen-xl pt-12">
<GroupPageImageAndName />

<div className="ml-auto">
{isAdmin && isDetailed ? (
<DynamicAddSolutionsAndEditGuildButton />
) : !isMember ? (
<JoinButton />
) : (
<DynamicRecheckAccessesAndLeaveButton />
)}
</div>
</LayoutHeadline>

{group?.description && (
<LayoutContainer className="mt-6 max-w-screen-xl font-semibold">
{parseDescription(group.description)}
</LayoutContainer>

<LayoutHeadline className="max-w-screen-xl pt-12">
<GroupPageImageAndName />

<div className="ml-auto">
{isAdmin && isDetailed ? (
<DynamicAddSolutionsAndEditGuildButton />
) : !isMember ? (
<JoinButton />
) : (
<DynamicRecheckAccessesAndLeaveButton />
)}
</div>
</LayoutHeadline>

{group?.description && (
<LayoutContainer className="mt-6 max-w-screen-xl font-semibold">
{parseDescription(group.description)}
</LayoutContainer>
)}
</LayoutHero>

<LayoutMain className="-top-16 flex max-w-screen-xl flex-col items-start gap-8">
<AccessHub />

<Section
titleRightElement={isAdmin ? <DynamicAddAndOrderRoles /> : undefined}
>
<Roles />
</Section>
</LayoutMain>
</Layout>
</>
)}
</LayoutHero>

<LayoutMain className="-top-16 flex max-w-screen-xl flex-col items-start gap-8">
<AccessHub />

<Section
titleRightElement={isAdmin ? <DynamicAddAndOrderRoles /> : undefined}
>
<Roles />
</Section>
</LayoutMain>
</Layout>
)
}

type Props = {
groupUrlName: string
fallback: { string: Guild }
}

const GroupPageWrapper = ({ fallback }: Props): JSX.Element => {
const GroupPageWrapper = ({ groupUrlName, fallback }: Props): JSX.Element => {
const guild = useGuild()

const group = useRoleGroup()

if (!fallback || !guild.id || !group?.id) {
if (!fallback && !guild.id) {
return (
<Center h="100vh" w="screen">
<Spinner />
Expand All @@ -138,15 +131,21 @@ const GroupPageWrapper = ({ fallback }: Props): JSX.Element => {
)
}

const [fallbackGuild] = Object.values(fallback)
const fallbackGroup = fallbackGuild?.groups.find((g) => (g.urlName = groupUrlName))

return (
<>
<LinkPreviewHead
path={fallback ? Object.values(fallback)[0].urlName : guild.urlName}
/>
<Head>
<title>{group.name}</title>
<meta property="og:title" content={group.name} />
</Head>
{fallbackGuild && fallbackGroup && (
<>
<LinkPreviewHead path={`${fallbackGuild.urlName}/${groupUrlName}`} />
<Head>
<title>{fallbackGroup.name}</title>
<meta property="og:title" content={fallbackGroup.name} />
<meta name="theme-color" content={guild.theme?.color} />
</Head>
</>
)}
<SWRConfig value={fallback && { fallback }}>
<ThemeProvider>
<JoinModalProvider>
Expand All @@ -159,7 +158,7 @@ const GroupPageWrapper = ({ fallback }: Props): JSX.Element => {
}

const getStaticProps: GetStaticProps = async ({ params }) => {
const endpoint = `/v2/guilds/guild-page/${params.guild?.toString()}`
const endpoint = `/v2/guilds/guild-page/${params?.guild?.toString()}`

const data = await fetcher(endpoint).catch((_) => ({}))

Expand All @@ -183,6 +182,7 @@ const getStaticProps: GetStaticProps = async ({ params }) => {

return {
props: {
groupUrlName: params?.group?.toString(),
fallback: {
[endpoint]: filteredData,
},
Expand Down
Loading
Loading