diff --git a/app/plus/api.ts b/app/plus/api.ts new file mode 100644 index 000000000..addbf9bed --- /dev/null +++ b/app/plus/api.ts @@ -0,0 +1,40 @@ +import { createRouter } from "pages/api/trpc/[trpc]"; +import * as z from "zod"; + +// The app's context - is generated for each incoming request +// export type Context = {}; +// const createContext = ({ +// req, +// res, +// }: trpcNext.CreateNextContextOptions): Context => { +// return {}; +// }; + +// function createRouter() { +// return trpc.router(); +// } +// Important: only use this export with SSR/SSG +const plusApi = createRouter().query("voting-history", { + input: z + .object({ + text: z.string().optional(), + }) + .optional(), + resolve({ input }) { + // the `input` here is parsed by the parser passed in `input` the type inferred + return { + greeting: `hello ${input?.text ?? "world"}`, + }; + }, +}); + +// Exporting type _type_ AppRouter only exposes types that can be used for inference +// https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-8.html#type-only-imports-and-export +// export type AppRouter = typeof appRouter; + +// export default trpcNext.createNextApiHandler({ +// router: appRouter, +// createContext, +// }); + +export default plusApi; diff --git a/components/plus/PlusHomePage.tsx b/app/plus/components/PlusHomePage.tsx similarity index 96% rename from components/plus/PlusHomePage.tsx rename to app/plus/components/PlusHomePage.tsx index a64c87ba8..f946c509a 100644 --- a/components/plus/PlusHomePage.tsx +++ b/app/plus/components/PlusHomePage.tsx @@ -7,12 +7,12 @@ import { RadioGroup, } from "@chakra-ui/react"; import { Trans } from "@lingui/macro"; +import { usePlusHomePage } from "app/plus/hooks/usePlusHomePage"; +import { PlusStatuses, Suggestions } from "app/plus/service"; import MyHead from "components/common/MyHead"; import SubText from "components/common/SubText"; import { useUser } from "hooks/common"; -import { usePlus } from "hooks/plus"; import { Fragment } from "react"; -import { PlusStatuses, Suggestions } from "services/plus"; import { getFullUsername } from "utils/strings"; import Suggestion from "./Suggestion"; import SuggestionModal from "./SuggestionModal"; @@ -33,7 +33,7 @@ const PlusHomePage = ({ suggestions, statuses }: PlusHomePageProps) => { suggestionCounts, setSuggestionsFilter, vouchedPlusStatusData, - } = usePlus({ suggestions, statuses }); + } = usePlusHomePage({ suggestions, statuses }); return ( <> diff --git a/components/plus/PlusVotingHistoryPage.tsx b/app/plus/components/PlusVotingHistoryPage.tsx similarity index 100% rename from components/plus/PlusVotingHistoryPage.tsx rename to app/plus/components/PlusVotingHistoryPage.tsx diff --git a/components/plus/Suggestion.tsx b/app/plus/components/Suggestion.tsx similarity index 98% rename from components/plus/Suggestion.tsx rename to app/plus/components/Suggestion.tsx index ad2580879..5b8661c58 100644 --- a/components/plus/Suggestion.tsx +++ b/app/plus/components/Suggestion.tsx @@ -9,6 +9,7 @@ import { } from "@chakra-ui/react"; import { zodResolver } from "@hookform/resolvers/zod"; import { Trans } from "@lingui/macro"; +import { Suggestions } from "app/plus/service"; import MyLink from "components/common/MyLink"; import SubText from "components/common/SubText"; import UserAvatar from "components/common/UserAvatar"; @@ -16,7 +17,6 @@ import { useMyTheme } from "hooks/common"; import useMutation from "hooks/useMutation"; import { useState } from "react"; import { useForm } from "react-hook-form"; -import { Suggestions } from "services/plus"; import { getFullUsername } from "utils/strings"; import { Unpacked } from "utils/types"; import { diff --git a/components/plus/SuggestionModal.tsx b/app/plus/components/SuggestionModal.tsx similarity index 100% rename from components/plus/SuggestionModal.tsx rename to app/plus/components/SuggestionModal.tsx diff --git a/components/plus/VotingInfoHeader.tsx b/app/plus/components/VotingInfoHeader.tsx similarity index 100% rename from components/plus/VotingInfoHeader.tsx rename to app/plus/components/VotingInfoHeader.tsx diff --git a/components/plus/VouchModal.tsx b/app/plus/components/VouchModal.tsx similarity index 100% rename from components/plus/VouchModal.tsx rename to app/plus/components/VouchModal.tsx diff --git a/hooks/plus.ts b/app/plus/hooks/usePlusHomePage.ts similarity index 90% rename from hooks/plus.ts rename to app/plus/hooks/usePlusHomePage.ts index 6b39047b2..8ac55d81d 100644 --- a/hooks/plus.ts +++ b/app/plus/hooks/usePlusHomePage.ts @@ -1,9 +1,9 @@ +import { PlusStatuses, Suggestions } from "app/plus/service"; import { useState } from "react"; -import { PlusStatuses, Suggestions } from "services/plus"; import useSWR from "swr"; -import { useUser } from "./common"; +import { useUser } from "../../../hooks/common"; -export function usePlus({ +export function usePlusHomePage({ suggestions: suggestionsInitial, statuses: statusesInitial, }: { diff --git a/services/plus.ts b/app/plus/service.ts similarity index 100% rename from services/plus.ts rename to app/plus/service.ts diff --git a/pages/api/plus/index.ts b/pages/api/plus/index.ts index 811b6d04d..0c88bca3d 100644 --- a/pages/api/plus/index.ts +++ b/pages/api/plus/index.ts @@ -1,5 +1,5 @@ +import plusService from "app/plus/service"; import { NextApiRequest, NextApiResponse } from "next"; -import plusService from "services/plus"; const plusHandler = async (req: NextApiRequest, res: NextApiResponse) => { switch (req.method) { diff --git a/pages/api/plus/suggestions.ts b/pages/api/plus/suggestions.ts index 3fe4720d9..471088bae 100644 --- a/pages/api/plus/suggestions.ts +++ b/pages/api/plus/suggestions.ts @@ -1,5 +1,5 @@ +import plusService from "app/plus/service"; import { NextApiRequest, NextApiResponse } from "next"; -import plusService from "services/plus"; import { getMySession } from "utils/api"; import { UserError } from "utils/errors"; import { ZodError } from "zod"; diff --git a/pages/api/plus/vouch.ts b/pages/api/plus/vouch.ts index 180ea03ff..58b146ff7 100644 --- a/pages/api/plus/vouch.ts +++ b/pages/api/plus/vouch.ts @@ -1,5 +1,5 @@ +import plusService from "app/plus/service"; import { NextApiRequest, NextApiResponse } from "next"; -import plusService from "services/plus"; import { getMySession } from "utils/api"; import { UserError } from "utils/errors"; import { ZodError } from "zod"; diff --git a/pages/api/trpc/[trpc].ts b/pages/api/trpc/[trpc].ts index e0f0fcee5..7c146c2f7 100644 --- a/pages/api/trpc/[trpc].ts +++ b/pages/api/trpc/[trpc].ts @@ -11,7 +11,7 @@ const createContext = ({ return {}; }; -function createRouter() { +export function createRouter() { return trpc.router(); } // Important: only use this export with SSR/SSG diff --git a/pages/plus/history/[[...slug]].tsx b/pages/plus/history/[[...slug]].tsx index edd1f7e32..53dc4f3ef 100644 --- a/pages/plus/history/[[...slug]].tsx +++ b/pages/plus/history/[[...slug]].tsx @@ -1,9 +1,9 @@ -import { GetStaticPaths, GetStaticProps } from "next"; import PlusVotingHistoryPage, { PlusVotingHistoryPageProps, -} from "components/plus/PlusVotingHistoryPage"; -import plusService from "services/plus"; +} from "app/plus/components/PlusVotingHistoryPage"; +import plusService from "app/plus/service"; import HeaderBanner from "components/layout/HeaderBanner"; +import { GetStaticPaths, GetStaticProps } from "next"; export const getStaticPaths: GetStaticPaths = async () => { return { diff --git a/pages/plus/index.tsx b/pages/plus/index.tsx index f54213fc4..b1204425a 100644 --- a/pages/plus/index.tsx +++ b/pages/plus/index.tsx @@ -1,7 +1,9 @@ +import PlusHomePage, { + PlusHomePageProps, +} from "app/plus/components/PlusHomePage"; +import plusService from "app/plus/service"; import HeaderBanner from "components/layout/HeaderBanner"; -import PlusHomePage, { PlusHomePageProps } from "components/plus/PlusHomePage"; import { GetStaticProps } from "next"; -import plusService from "services/plus"; export const getStaticProps: GetStaticProps = async () => { const [suggestions, statuses] = await Promise.all([