mirror of
https://github.com/Sendouc/sendou.ink.git
synced 2026-09-30 15:17:43 -05:00
migrate plus location
This commit is contained in:
40
app/plus/api.ts
Normal file
40
app/plus/api.ts
Normal file
@@ -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<Context>();
|
||||
// }
|
||||
// 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;
|
||||
@@ -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 (
|
||||
<>
|
||||
@@ -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 {
|
||||
@@ -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,
|
||||
}: {
|
||||
@@ -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) {
|
||||
|
||||
@@ -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";
|
||||
|
||||
@@ -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";
|
||||
|
||||
@@ -11,7 +11,7 @@ const createContext = ({
|
||||
return {};
|
||||
};
|
||||
|
||||
function createRouter() {
|
||||
export function createRouter() {
|
||||
return trpc.router<Context>();
|
||||
}
|
||||
// Important: only use this export with SSR/SSG
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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<PlusHomePageProps> = async () => {
|
||||
const [suggestions, statuses] = await Promise.all([
|
||||
|
||||
Reference in New Issue
Block a user