Skip to content

Commit

Permalink
Auto select first guild
Browse files Browse the repository at this point in the history
  • Loading branch information
eduardozgz committed Oct 20, 2024
1 parent a903b21 commit 7f4020d
Show file tree
Hide file tree
Showing 10 changed files with 824 additions and 771 deletions.
2 changes: 1 addition & 1 deletion apps/website/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -83,4 +83,4 @@
"typescript": "^5.4.5"
},
"prettier": "@mc/prettier-config"
}
}
1,512 changes: 758 additions & 754 deletions apps/website/src/@types/resources.d.ts

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions apps/website/src/app/components/ProgressBarProvider.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use client';
"use client";

import { AppProgressBar as ProgressBar } from 'next-nprogress-bar';
import { AppProgressBar as ProgressBar } from "next-nprogress-bar";

const ProgressBarProvider = ({ children }: { children: React.ReactNode }) => {
return (
Expand All @@ -16,4 +16,4 @@ const ProgressBarProvider = ({ children }: { children: React.ReactNode }) => {
);
};

export default ProgressBarProvider;
export default ProgressBarProvider;
52 changes: 48 additions & 4 deletions apps/website/src/app/dashboard/page.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,56 @@
"use client";

import { MenuButton } from "./Menu";
import { useEffect } from "react";
import { useParams, useRouter } from "next/navigation";
import { Trans } from "react-i18next";

import { LinkUnderlined } from "@mc/ui/LinkUnderlined";

import { Routes } from "~/other/routes";
import { api } from "~/trpc/react";
import { TypographyH3 } from "@mc/ui/TypographyH3";
import { TypographyH4 } from "@mc/ui/TypographyH4";

export default function Page() {
const router = useRouter();
const selected = useParams();
const userGuildsQuery = api.discord.userGuilds.useQuery();

const hasAnythingSelected = Object.keys(selected).length > 0;

// Autoselect the first guild if no guild is selected yet.
useEffect(() => {
console.log(userGuildsQuery.data);

if (!userGuildsQuery.data) return;
if (!userGuildsQuery.data.userGuilds.size) return;
if (hasAnythingSelected) return;

const firstGuildId = [...userGuildsQuery.data.userGuilds.keys()][0];

router.replace(Routes.DashboardServers(firstGuildId));
}, [hasAnythingSelected, router, userGuildsQuery.data]);

return (
<div className="flex flex-col p-1">
<MenuButton />
{"// TODO auto select first guild"}
<div className="flex flex-col p-1 grow justify-center items-center h-full ">
{!userGuildsQuery.isLoading && !userGuildsQuery.data?.userGuilds.size && (
<>
<TypographyH3>
<Trans i18nKey="pages.dashboard.noServers.heading" />
</TypographyH3>
<TypographyH4>
<Trans
i18nKey="pages.dashboard.noServers.subheading"
components={{
CreateServerLink: (
<LinkUnderlined href={Routes.CreateDiscordServer} />
),
JoinSupportServerLink: <LinkUnderlined href={Routes.Support} />,
}}
/>
</TypographyH4>
</ >
)}
</div>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { UserPermissionsContext } from "../UserPermissionsContext";
import { EditTemplate } from "./sections/EditTemplate";
import { EnableTemplate } from "./sections/EnableTemplate";
import { TemplateError } from "./sections/TemplateError";

// TODO fix: enable status is being set to its initial state when template content is changed
export default function Page() {
const { t } = useTranslation();
Expand Down
4 changes: 1 addition & 3 deletions apps/website/src/app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,7 @@ export default function RootLayout({
<I18nProvider>
<TRPCReactProvider>
<NavBar />
<ProgressBarProvider>
{children}
</ProgressBarProvider>
<ProgressBarProvider>{children}</ProgressBarProvider>
</TRPCReactProvider>
</I18nProvider>
</body>
Expand Down
6 changes: 5 additions & 1 deletion apps/website/src/i18n/locales/en-US/main.json
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,10 @@
}
},
"dashboard": {
"noServers": {
"heading": "You aren't in any server. ",
"subheading": "Why you don't start by creating a <CreateServerLink>new one</CreateServerLink> or by <JoinSupportServerLink>joining us</JoinSupportServerLink>?"
},
"servers": {
"suggestedTopics": {
"quickSetup": {
Expand Down Expand Up @@ -751,4 +755,4 @@
}
}
}
}
}
8 changes: 4 additions & 4 deletions apps/website/src/server/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ export function getOAuth2Url() {
export async function exchangeTokens(
exchangeMethod:
| {
code: string;
}
code: string;
}
| {
refreshToken: string;
},
refreshToken: string;
},
): Promise<Session> {
let body = {};
if ("code" in exchangeMethod) {
Expand Down
1 change: 1 addition & 0 deletions packages/common/src/Routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,5 @@ export const Routes = (baseUrl: string) => ({
"/dashboard/servers" +
(guildId ? `/${guildId}` : "") +
(channelId ? `/${channelId}` : ""),
CreateDiscordServer: "https://discord.com/channels/@me",
});
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@ export const DiscordOAuth2TokenExchangeResponseSchema = z.union([
expiresAt: Date.now() + expires_in * 1000,
scope: scope,
}),
)]);
),
]);

0 comments on commit 7f4020d

Please sign in to comment.