From e303e5ea8f6ed7aa463e07319bd7004add58a1c5 Mon Sep 17 00:00:00 2001 From: Kalle <38327916+Sendouc@users.noreply.github.com> Date: Thu, 26 May 2022 12:19:50 +0300 Subject: [PATCH] Adjust plus routes --- app/routes/plus.tsx | 4 +- app/routes/plus/index.tsx | 175 +----------------- app/routes/plus/suggestions.tsx | 174 +++++++++++++++++ app/routes/plus/{ => suggestions}/comment.tsx | 2 +- 4 files changed, 180 insertions(+), 175 deletions(-) create mode 100644 app/routes/plus/suggestions.tsx rename app/routes/plus/{ => suggestions}/comment.tsx (78%) diff --git a/app/routes/plus.tsx b/app/routes/plus.tsx index 16a244058..eaee74376 100644 --- a/app/routes/plus.tsx +++ b/app/routes/plus.tsx @@ -2,11 +2,11 @@ import { Outlet } from "@remix-run/react"; import { Main } from "~/components/Main"; import { SubNav, SubNavLink } from "~/components/SubNav"; -export default function UserPageLayout() { +export default function PlusPageLayout() { return ( <> - + Profile diff --git a/app/routes/plus/index.tsx b/app/routes/plus/index.tsx index a6fc58f9f..e872035f8 100644 --- a/app/routes/plus/index.tsx +++ b/app/routes/plus/index.tsx @@ -1,174 +1,5 @@ -import type { - LinksFunction, - LoaderFunction, - MetaFunction, -} from "@remix-run/node"; -import { json } from "@remix-run/node"; -import { Outlet, useLoaderData } from "@remix-run/react"; -import * as React from "react"; -import invariant from "tiny-invariant"; -import { Avatar } from "~/components/Avatar"; -import { Button } from "~/components/Button"; -import { Catcher } from "~/components/Catcher"; -import { upcomingVoting } from "~/core/plus"; -import { db } from "~/db"; -import type * as plusSuggestions from "~/db/models/plusSuggestions.server"; -import { useUser } from "~/hooks/useUser"; -import styles from "~/styles/plus.css"; -import { databaseTimestampToDate } from "~/utils/dates"; -import { makeTitle, requireUser } from "~/utils/remix"; -import { discordFullName } from "~/utils/strings"; -import type { Unpacked } from "~/utils/types"; +import { redirect } from "@remix-run/node"; -export const links: LinksFunction = () => { - return [{ rel: "stylesheet", href: styles }]; +export const loader = () => { + return redirect("/plus/suggestions"); }; - -export const meta: MetaFunction = () => { - return { - title: makeTitle("Plus Server suggestions"), - description: "This month's suggestions for +1, +2 and +3.", - }; -}; - -interface PlusLoaderData { - suggestions?: plusSuggestions.FindResult; - suggestedForTiers: number[]; -} - -export const loader: LoaderFunction = async ({ request }) => { - const user = await requireUser(request); - - return json({ - suggestions: db.plusSuggestions.find({ - ...upcomingVoting(new Date()), - plusTier: user.plusTier, - }), - suggestedForTiers: db.plusSuggestions.tiersSuggestedFor({ - ...upcomingVoting(new Date()), - userId: user.id, - }), - }); -}; - -export default function PlusPage() { - const data = useLoaderData(); - const [tierVisible, setTierVisible] = React.useState( - data.suggestions?.[0].tier ?? 0 - ); - - if (!data.suggestions) { - return ; - } - - const visibleSuggestions = data.suggestions.find( - ({ tier }) => tier === tierVisible - ); - invariant(visibleSuggestions); - - return ( - <> - -
- -
-
- {data.suggestions.map(({ tier, users }) => { - const id = String(tier); - return ( -
- - setTierVisible(tier)} - /> -
- ); - })} -
-
- {visibleSuggestions.users.map((u) => ( - - ))} -
-
-
- - ); -} - -function SuggestedForInfo() { - const data = useLoaderData(); - const user = useUser(); - - // no need to show anything if they can't be suggested anyway... - if (user?.plusTier === 1) { - return null; - } - - if (data.suggestedForTiers.length === 0) { - return ( -
- You are not suggested yet this month. -
- ); - } - - return ( -
- You are suggested for{" "} - {data.suggestedForTiers.map((tier) => `+${tier}`).join(" and ")} this - month. -
- ); -} - -function SuggestedUser({ - user, -}: { - user: Unpacked>["users"]>; -}) { - return ( -
-
- -

{user.info.discordName}

- -
-
- - Comments ({user.suggestions.length}) - -
- {user.suggestions.map((s) => ( -
- {discordFullName(s.author)} - {s.text} - - {" "} - ―{" "} - - -
- ))} -
-
-
- ); -} - -export const CatchBoundary = Catcher; diff --git a/app/routes/plus/suggestions.tsx b/app/routes/plus/suggestions.tsx new file mode 100644 index 000000000..a6fc58f9f --- /dev/null +++ b/app/routes/plus/suggestions.tsx @@ -0,0 +1,174 @@ +import type { + LinksFunction, + LoaderFunction, + MetaFunction, +} from "@remix-run/node"; +import { json } from "@remix-run/node"; +import { Outlet, useLoaderData } from "@remix-run/react"; +import * as React from "react"; +import invariant from "tiny-invariant"; +import { Avatar } from "~/components/Avatar"; +import { Button } from "~/components/Button"; +import { Catcher } from "~/components/Catcher"; +import { upcomingVoting } from "~/core/plus"; +import { db } from "~/db"; +import type * as plusSuggestions from "~/db/models/plusSuggestions.server"; +import { useUser } from "~/hooks/useUser"; +import styles from "~/styles/plus.css"; +import { databaseTimestampToDate } from "~/utils/dates"; +import { makeTitle, requireUser } from "~/utils/remix"; +import { discordFullName } from "~/utils/strings"; +import type { Unpacked } from "~/utils/types"; + +export const links: LinksFunction = () => { + return [{ rel: "stylesheet", href: styles }]; +}; + +export const meta: MetaFunction = () => { + return { + title: makeTitle("Plus Server suggestions"), + description: "This month's suggestions for +1, +2 and +3.", + }; +}; + +interface PlusLoaderData { + suggestions?: plusSuggestions.FindResult; + suggestedForTiers: number[]; +} + +export const loader: LoaderFunction = async ({ request }) => { + const user = await requireUser(request); + + return json({ + suggestions: db.plusSuggestions.find({ + ...upcomingVoting(new Date()), + plusTier: user.plusTier, + }), + suggestedForTiers: db.plusSuggestions.tiersSuggestedFor({ + ...upcomingVoting(new Date()), + userId: user.id, + }), + }); +}; + +export default function PlusPage() { + const data = useLoaderData(); + const [tierVisible, setTierVisible] = React.useState( + data.suggestions?.[0].tier ?? 0 + ); + + if (!data.suggestions) { + return ; + } + + const visibleSuggestions = data.suggestions.find( + ({ tier }) => tier === tierVisible + ); + invariant(visibleSuggestions); + + return ( + <> + +
+ +
+
+ {data.suggestions.map(({ tier, users }) => { + const id = String(tier); + return ( +
+ + setTierVisible(tier)} + /> +
+ ); + })} +
+
+ {visibleSuggestions.users.map((u) => ( + + ))} +
+
+
+ + ); +} + +function SuggestedForInfo() { + const data = useLoaderData(); + const user = useUser(); + + // no need to show anything if they can't be suggested anyway... + if (user?.plusTier === 1) { + return null; + } + + if (data.suggestedForTiers.length === 0) { + return ( +
+ You are not suggested yet this month. +
+ ); + } + + return ( +
+ You are suggested for{" "} + {data.suggestedForTiers.map((tier) => `+${tier}`).join(" and ")} this + month. +
+ ); +} + +function SuggestedUser({ + user, +}: { + user: Unpacked>["users"]>; +}) { + return ( +
+
+ +

{user.info.discordName}

+ +
+
+ + Comments ({user.suggestions.length}) + +
+ {user.suggestions.map((s) => ( +
+ {discordFullName(s.author)} + {s.text} + + {" "} + ―{" "} + + +
+ ))} +
+
+
+ ); +} + +export const CatchBoundary = Catcher; diff --git a/app/routes/plus/comment.tsx b/app/routes/plus/suggestions/comment.tsx similarity index 78% rename from app/routes/plus/comment.tsx rename to app/routes/plus/suggestions/comment.tsx index 97d0f3f02..3db916721 100644 --- a/app/routes/plus/comment.tsx +++ b/app/routes/plus/suggestions/comment.tsx @@ -4,7 +4,7 @@ import { Dialog } from "~/components/Dialog"; export default function PlusCommentModalPage() { const navigate = useNavigate(); return ( - navigate("/plus")}> + navigate("/plus/suggestions")}> hello world );