From 9b659191ca5759d56d159331d134d4bde86c4aa7 Mon Sep 17 00:00:00 2001 From: rjmacarthy Date: Fri, 20 Jan 2023 09:37:02 +0000 Subject: [PATCH] Extract common getStaticProps to single file --- website/src/lib/default_static_props.ts | 7 +++++++ website/src/pages/404.tsx | 8 +------- website/src/pages/500.tsx | 8 +------- website/src/pages/about.tsx | 8 +------- website/src/pages/account/edit.tsx | 8 +------- website/src/pages/account/index.tsx | 8 +------- website/src/pages/admin/index.tsx | 8 +------- website/src/pages/create/assistant_reply.tsx | 8 +------- website/src/pages/create/initial_prompt.tsx | 8 +------- website/src/pages/create/user_reply.tsx | 8 +------- website/src/pages/dashboard.tsx | 8 +------- website/src/pages/evaluate/rank_assistant_replies.tsx | 8 +------- website/src/pages/evaluate/rank_initial_prompts.tsx | 8 +------- website/src/pages/evaluate/rank_user_replies.tsx | 8 +------- website/src/pages/label/label_assistant_reply.tsx | 8 +------- website/src/pages/label/label_initial_prompt.tsx | 8 +------- website/src/pages/label/label_prompter_reply.tsx | 8 +------- website/src/pages/leaderboard.tsx | 8 +------- website/src/pages/messages/index.tsx | 8 +------- website/src/pages/privacy-policy.tsx | 8 +------- website/src/pages/terms-of-service.tsx | 8 +------- 21 files changed, 27 insertions(+), 140 deletions(-) create mode 100644 website/src/lib/default_static_props.ts diff --git a/website/src/lib/default_static_props.ts b/website/src/lib/default_static_props.ts new file mode 100644 index 00000000..3cc311e8 --- /dev/null +++ b/website/src/lib/default_static_props.ts @@ -0,0 +1,7 @@ +import { serverSideTranslations } from "next-i18next/serverSideTranslations"; + +export const getDefaultStaticProps = async ({ locale }) => ({ + props: { + ...(await serverSideTranslations(locale)), + }, +}); \ No newline at end of file diff --git a/website/src/pages/404.tsx b/website/src/pages/404.tsx index 11185057..d4c58b54 100644 --- a/website/src/pages/404.tsx +++ b/website/src/pages/404.tsx @@ -1,9 +1,9 @@ import { Box, Button, Center, Link, Text } from "@chakra-ui/react"; import Head from "next/head"; -import { serverSideTranslations } from "next-i18next/serverSideTranslations"; import { FiAlertTriangle } from "react-icons/fi"; import { EmptyState } from "src/components/EmptyState"; import { getTransparentHeaderLayout } from "src/components/Layout"; +export { getDefaultStaticProps as getStaticProps } from "src/lib/default_static_props"; function Error() { return ( @@ -41,10 +41,4 @@ function Error() { Error.getLayout = getTransparentHeaderLayout; -export const getStaticProps = async ({ locale }) => ({ - props: { - ...(await serverSideTranslations(locale, ["common"])), - }, -}); - export default Error; diff --git a/website/src/pages/500.tsx b/website/src/pages/500.tsx index bd0fac2f..378bdfff 100644 --- a/website/src/pages/500.tsx +++ b/website/src/pages/500.tsx @@ -1,9 +1,9 @@ import { Box, Button, Center, Link, Text } from "@chakra-ui/react"; import Head from "next/head"; -import { serverSideTranslations } from "next-i18next/serverSideTranslations"; import { FiAlertTriangle } from "react-icons/fi"; import { EmptyState } from "src/components/EmptyState"; import { getTransparentHeaderLayout } from "src/components/Layout"; +export { getDefaultStaticProps as getStaticProps } from "src/lib/default_static_props"; function ServerError() { return ( @@ -44,10 +44,4 @@ function ServerError() { ServerError.getLayout = getTransparentHeaderLayout; -export const getStaticProps = async ({ locale }) => ({ - props: { - ...(await serverSideTranslations(locale, ["common"])), - }, -}); - export default ServerError; diff --git a/website/src/pages/about.tsx b/website/src/pages/about.tsx index 08d2bea7..01182be0 100644 --- a/website/src/pages/about.tsx +++ b/website/src/pages/about.tsx @@ -1,10 +1,10 @@ import Image from "next/image"; -import { serverSideTranslations } from "next-i18next/serverSideTranslations"; import { CallToAction } from "src/components/CallToAction"; import { Container } from "src/components/Container"; import Roadmap from "src/components/Roadmap"; import Services from "src/components/Services"; import Vision from "src/components/Vision"; +export { getDefaultStaticProps as getStaticProps } from "src/lib/default_static_props"; const AboutPage = () => { return ( @@ -37,10 +37,4 @@ const AboutPage = () => { ); }; -export const getStaticProps = async ({ locale }) => ({ - props: { - ...(await serverSideTranslations(locale, ["common"])), - }, -}); - export default AboutPage; diff --git a/website/src/pages/account/edit.tsx b/website/src/pages/account/edit.tsx index 9120322a..52af7e5e 100644 --- a/website/src/pages/account/edit.tsx +++ b/website/src/pages/account/edit.tsx @@ -2,9 +2,9 @@ import { Button, Input, InputGroup } from "@chakra-ui/react"; import Head from "next/head"; import Router from "next/router"; import { useSession } from "next-auth/react"; -import { serverSideTranslations } from "next-i18next/serverSideTranslations"; import React from "react"; import { Control, useForm, useWatch } from "react-hook-form"; +export { getDefaultStaticProps as getStaticProps } from "src/lib/default_static_props"; export default function Account() { const { data: session } = useSession(); @@ -31,12 +31,6 @@ export default function Account() { ); } -export const getStaticProps = async ({ locale }) => ({ - props: { - ...(await serverSideTranslations(locale, ["common"])), - }, -}); - const EditForm = () => { const { data: session } = useSession(); diff --git a/website/src/pages/account/index.tsx b/website/src/pages/account/index.tsx index b6e95594..813ce8ea 100644 --- a/website/src/pages/account/index.tsx +++ b/website/src/pages/account/index.tsx @@ -2,8 +2,8 @@ import { Button } from "@chakra-ui/react"; import Head from "next/head"; import Link from "next/link"; import { useSession } from "next-auth/react"; -import { serverSideTranslations } from "next-i18next/serverSideTranslations"; import React from "react"; +export { getDefaultStaticProps as getStaticProps } from "src/lib/default_static_props"; export default function Account() { const { data: session } = useSession(); @@ -32,9 +32,3 @@ export default function Account() { ); } - -export const getStaticProps = async ({ locale }) => ({ - props: { - ...(await serverSideTranslations(locale, ["common"])), - }, -}); diff --git a/website/src/pages/admin/index.tsx b/website/src/pages/admin/index.tsx index ef5abe2c..f8827049 100644 --- a/website/src/pages/admin/index.tsx +++ b/website/src/pages/admin/index.tsx @@ -1,10 +1,10 @@ import Head from "next/head"; import { useRouter } from "next/router"; import { useSession } from "next-auth/react"; -import { serverSideTranslations } from "next-i18next/serverSideTranslations"; import { useEffect } from "react"; import { getAdminLayout } from "src/components/Layout"; import UsersCell from "src/components/UsersCell"; +export { getDefaultStaticProps as getStaticProps } from "src/lib/default_static_props"; /** * Provides the admin index page that will display a list of users and give @@ -45,10 +45,4 @@ const AdminIndex = () => { AdminIndex.getLayout = getAdminLayout; -export const getStaticProps = async ({ locale }) => ({ - props: { - ...(await serverSideTranslations(locale, ["common"])), - }, -}); - export default AdminIndex; diff --git a/website/src/pages/create/assistant_reply.tsx b/website/src/pages/create/assistant_reply.tsx index 9002ad3e..1c83eb23 100644 --- a/website/src/pages/create/assistant_reply.tsx +++ b/website/src/pages/create/assistant_reply.tsx @@ -1,10 +1,10 @@ import Head from "next/head"; -import { serverSideTranslations } from "next-i18next/serverSideTranslations"; import { TaskEmptyState } from "src/components/EmptyState"; import { getDashboardLayout } from "src/components/Layout"; import { LoadingScreen } from "src/components/Loading/LoadingScreen"; import { Task } from "src/components/Tasks/Task"; import { useCreateAssistantReply } from "src/hooks/tasks/useCreateReply"; +export { getDefaultStaticProps as getStaticProps } from "src/lib/default_static_props"; const AssistantReply = () => { const { tasks, isLoading, reset, trigger } = useCreateAssistantReply(); @@ -30,10 +30,4 @@ const AssistantReply = () => { AssistantReply.getLayout = getDashboardLayout; -export const getStaticProps = async ({ locale }) => ({ - props: { - ...(await serverSideTranslations(locale, ["common"])), - }, -}); - export default AssistantReply; diff --git a/website/src/pages/create/initial_prompt.tsx b/website/src/pages/create/initial_prompt.tsx index 496e000c..639df68f 100644 --- a/website/src/pages/create/initial_prompt.tsx +++ b/website/src/pages/create/initial_prompt.tsx @@ -1,10 +1,10 @@ import Head from "next/head"; -import { serverSideTranslations } from "next-i18next/serverSideTranslations"; import { TaskEmptyState } from "src/components/EmptyState"; import { getDashboardLayout } from "src/components/Layout"; import { LoadingScreen } from "src/components/Loading/LoadingScreen"; import { Task } from "src/components/Tasks/Task"; import { useCreateInitialPrompt } from "src/hooks/tasks/useCreateReply"; +export { getDefaultStaticProps as getStaticProps } from "src/lib/default_static_props"; const InitialPrompt = () => { const { tasks, isLoading, reset, trigger } = useCreateInitialPrompt(); @@ -30,10 +30,4 @@ const InitialPrompt = () => { InitialPrompt.getLayout = getDashboardLayout; -export const getStaticProps = async ({ locale }) => ({ - props: { - ...(await serverSideTranslations(locale, ["common"])), - }, -}); - export default InitialPrompt; diff --git a/website/src/pages/create/user_reply.tsx b/website/src/pages/create/user_reply.tsx index 86f29826..5898439c 100644 --- a/website/src/pages/create/user_reply.tsx +++ b/website/src/pages/create/user_reply.tsx @@ -1,10 +1,10 @@ import Head from "next/head"; -import { serverSideTranslations } from "next-i18next/serverSideTranslations"; import { TaskEmptyState } from "src/components/EmptyState"; import { getDashboardLayout } from "src/components/Layout"; import { LoadingScreen } from "src/components/Loading/LoadingScreen"; import { Task } from "src/components/Tasks/Task"; import { useCreatePrompterReply } from "src/hooks/tasks/useCreateReply"; +export { getDefaultStaticProps as getStaticProps } from "src/lib/default_static_props"; const UserReply = () => { const { tasks, isLoading, reset, trigger } = useCreatePrompterReply(); @@ -30,10 +30,4 @@ const UserReply = () => { UserReply.getLayout = getDashboardLayout; -export const getStaticProps = async ({ locale }) => ({ - props: { - ...(await serverSideTranslations(locale, ["common"])), - }, -}); - export default UserReply; diff --git a/website/src/pages/dashboard.tsx b/website/src/pages/dashboard.tsx index ed2b20e1..3d6beb8b 100644 --- a/website/src/pages/dashboard.tsx +++ b/website/src/pages/dashboard.tsx @@ -1,9 +1,9 @@ import { Flex } from "@chakra-ui/react"; import Head from "next/head"; -import { serverSideTranslations } from "next-i18next/serverSideTranslations"; import { LeaderboardTable, TaskOption, WelcomeCard } from "src/components/Dashboard"; import { getDashboardLayout } from "src/components/Layout"; import { TaskCategory } from "src/components/Tasks/TaskTypes"; +export { getDefaultStaticProps as getStaticProps } from "src/lib/default_static_props"; const Dashboard = () => { return ( @@ -23,10 +23,4 @@ const Dashboard = () => { Dashboard.getLayout = (page) => getDashboardLayout(page); -export const getStaticProps = async ({ locale }) => ({ - props: { - ...(await serverSideTranslations(locale, ["common"])), - }, -}); - export default Dashboard; diff --git a/website/src/pages/evaluate/rank_assistant_replies.tsx b/website/src/pages/evaluate/rank_assistant_replies.tsx index dcd2d30b..da79d92f 100644 --- a/website/src/pages/evaluate/rank_assistant_replies.tsx +++ b/website/src/pages/evaluate/rank_assistant_replies.tsx @@ -1,10 +1,10 @@ import Head from "next/head"; -import { serverSideTranslations } from "next-i18next/serverSideTranslations"; import { TaskEmptyState } from "src/components/EmptyState"; import { getDashboardLayout } from "src/components/Layout"; import { LoadingScreen } from "src/components/Loading/LoadingScreen"; import { Task } from "src/components/Tasks/Task"; import { useRankAssistantRepliesTask } from "src/hooks/tasks/useRankReplies"; +export { getDefaultStaticProps as getStaticProps } from "src/lib/default_static_props"; const RankAssistantReplies = () => { const { tasks, isLoading, reset, trigger } = useRankAssistantRepliesTask(); @@ -30,10 +30,4 @@ const RankAssistantReplies = () => { RankAssistantReplies.getLayout = getDashboardLayout; -export const getStaticProps = async ({ locale }) => ({ - props: { - ...(await serverSideTranslations(locale, ["common"])), - }, -}); - export default RankAssistantReplies; diff --git a/website/src/pages/evaluate/rank_initial_prompts.tsx b/website/src/pages/evaluate/rank_initial_prompts.tsx index 4c997faa..f23fc0ed 100644 --- a/website/src/pages/evaluate/rank_initial_prompts.tsx +++ b/website/src/pages/evaluate/rank_initial_prompts.tsx @@ -1,10 +1,10 @@ import Head from "next/head"; -import { serverSideTranslations } from "next-i18next/serverSideTranslations"; import { TaskEmptyState } from "src/components/EmptyState"; import { getDashboardLayout } from "src/components/Layout"; import { LoadingScreen } from "src/components/Loading/LoadingScreen"; import { Task } from "src/components/Tasks/Task"; import { useRankInitialPromptsTask } from "src/hooks/tasks/useRankReplies"; +export { getDefaultStaticProps as getStaticProps } from "src/lib/default_static_props"; const RankInitialPrompts = () => { const { tasks, isLoading, reset, trigger } = useRankInitialPromptsTask(); @@ -30,10 +30,4 @@ const RankInitialPrompts = () => { RankInitialPrompts.getLayout = getDashboardLayout; -export const getStaticProps = async ({ locale }) => ({ - props: { - ...(await serverSideTranslations(locale, ["common"])), - }, -}); - export default RankInitialPrompts; diff --git a/website/src/pages/evaluate/rank_user_replies.tsx b/website/src/pages/evaluate/rank_user_replies.tsx index 0982d36d..cee82b87 100644 --- a/website/src/pages/evaluate/rank_user_replies.tsx +++ b/website/src/pages/evaluate/rank_user_replies.tsx @@ -1,10 +1,10 @@ import Head from "next/head"; -import { serverSideTranslations } from "next-i18next/serverSideTranslations"; import { TaskEmptyState } from "src/components/EmptyState"; import { getDashboardLayout } from "src/components/Layout"; import { LoadingScreen } from "src/components/Loading/LoadingScreen"; import { Task } from "src/components/Tasks/Task"; import { useRankPrompterRepliesTask } from "src/hooks/tasks/useRankReplies"; +export { getDefaultStaticProps as getStaticProps } from "src/lib/default_static_props"; const RankUserReplies = () => { const { tasks, isLoading, reset, trigger } = useRankPrompterRepliesTask(); @@ -30,10 +30,4 @@ const RankUserReplies = () => { RankUserReplies.getLayout = getDashboardLayout; -export const getStaticProps = async ({ locale }) => ({ - props: { - ...(await serverSideTranslations(locale, ["common"])), - }, -}); - export default RankUserReplies; diff --git a/website/src/pages/label/label_assistant_reply.tsx b/website/src/pages/label/label_assistant_reply.tsx index 6f005f33..07a6cb1c 100644 --- a/website/src/pages/label/label_assistant_reply.tsx +++ b/website/src/pages/label/label_assistant_reply.tsx @@ -1,10 +1,10 @@ import Head from "next/head"; -import { serverSideTranslations } from "next-i18next/serverSideTranslations"; import { TaskEmptyState } from "src/components/EmptyState"; import { getDashboardLayout } from "src/components/Layout"; import { LoadingScreen } from "src/components/Loading/LoadingScreen"; import { Task } from "src/components/Tasks/Task"; import { useLabelAssistantReplyTask } from "src/hooks/tasks/useLabelingTask"; +export { getDefaultStaticProps as getStaticProps } from "src/lib/default_static_props"; const LabelAssistantReply = () => { const { tasks, isLoading, trigger, reset } = useLabelAssistantReplyTask(); @@ -30,10 +30,4 @@ const LabelAssistantReply = () => { LabelAssistantReply.getLayout = getDashboardLayout; -export const getStaticProps = async ({ locale }) => ({ - props: { - ...(await serverSideTranslations(locale, ["common"])), - }, -}); - export default LabelAssistantReply; diff --git a/website/src/pages/label/label_initial_prompt.tsx b/website/src/pages/label/label_initial_prompt.tsx index a6813499..8735044f 100644 --- a/website/src/pages/label/label_initial_prompt.tsx +++ b/website/src/pages/label/label_initial_prompt.tsx @@ -1,10 +1,10 @@ import Head from "next/head"; -import { serverSideTranslations } from "next-i18next/serverSideTranslations"; import { TaskEmptyState } from "src/components/EmptyState"; import { getDashboardLayout } from "src/components/Layout"; import { LoadingScreen } from "src/components/Loading/LoadingScreen"; import { Task } from "src/components/Tasks/Task"; import { useLabelInitialPromptTask } from "src/hooks/tasks/useLabelingTask"; +export { getDefaultStaticProps as getStaticProps } from "src/lib/default_static_props"; const LabelInitialPrompt = () => { const { tasks, isLoading, trigger, reset } = useLabelInitialPromptTask(); @@ -30,10 +30,4 @@ const LabelInitialPrompt = () => { LabelInitialPrompt.getLayout = getDashboardLayout; -export const getStaticProps = async ({ locale }) => ({ - props: { - ...(await serverSideTranslations(locale, ["common"])), - }, -}); - export default LabelInitialPrompt; diff --git a/website/src/pages/label/label_prompter_reply.tsx b/website/src/pages/label/label_prompter_reply.tsx index f1ba8008..17164e11 100644 --- a/website/src/pages/label/label_prompter_reply.tsx +++ b/website/src/pages/label/label_prompter_reply.tsx @@ -1,10 +1,10 @@ import Head from "next/head"; -import { serverSideTranslations } from "next-i18next/serverSideTranslations"; import { TaskEmptyState } from "src/components/EmptyState"; import { getDashboardLayout } from "src/components/Layout"; import { LoadingScreen } from "src/components/Loading/LoadingScreen"; import { Task } from "src/components/Tasks/Task"; import { useLabelPrompterReplyTask } from "src/hooks/tasks/useLabelingTask"; +export { getDefaultStaticProps as getStaticProps } from "src/lib/default_static_props"; const LabelPrompterReply = () => { const { tasks, isLoading, trigger, reset } = useLabelPrompterReplyTask(); @@ -30,10 +30,4 @@ const LabelPrompterReply = () => { LabelPrompterReply.getLayout = getDashboardLayout; -export const getStaticProps = async ({ locale }) => ({ - props: { - ...(await serverSideTranslations(locale, ["common"])), - }, -}); - export default LabelPrompterReply; diff --git a/website/src/pages/leaderboard.tsx b/website/src/pages/leaderboard.tsx index d6bae8e9..f79dac52 100644 --- a/website/src/pages/leaderboard.tsx +++ b/website/src/pages/leaderboard.tsx @@ -1,8 +1,8 @@ import { Box, Heading, Tab, TabList, TabPanel, TabPanels, Tabs } from "@chakra-ui/react"; import Head from "next/head"; -import { serverSideTranslations } from "next-i18next/serverSideTranslations"; import { getDashboardLayout } from "src/components/Layout"; import { LeaderboardGridCell } from "src/components/LeaderboardGridCell"; +export { getDefaultStaticProps as getStaticProps } from "src/lib/default_static_props"; import { LeaderboardTimeFrame } from "src/types/Leaderboard"; const Leaderboard = () => { @@ -46,10 +46,4 @@ const Leaderboard = () => { Leaderboard.getLayout = getDashboardLayout; -export const getStaticProps = async ({ locale }) => ({ - props: { - ...(await serverSideTranslations(locale, ["common"])), - }, -}); - export default Leaderboard; diff --git a/website/src/pages/messages/index.tsx b/website/src/pages/messages/index.tsx index 40497fd1..3b6e342e 100644 --- a/website/src/pages/messages/index.tsx +++ b/website/src/pages/messages/index.tsx @@ -1,10 +1,10 @@ import { Box, CircularProgress, SimpleGrid, Text, useColorModeValue } from "@chakra-ui/react"; import Head from "next/head"; -import { serverSideTranslations } from "next-i18next/serverSideTranslations"; import { getDashboardLayout } from "src/components/Layout"; import { MessageTable } from "src/components/Messages/MessageTable"; import { get } from "src/lib/api"; import useSWRImmutable from "swr/immutable"; +export { getDefaultStaticProps as getStaticProps } from "src/lib/default_static_props"; const MessagesDashboard = () => { const boxBgColor = useColorModeValue("white", "gray.800"); @@ -55,10 +55,4 @@ const MessagesDashboard = () => { MessagesDashboard.getLayout = getDashboardLayout; -export const getStaticProps = async ({ locale }) => ({ - props: { - ...(await serverSideTranslations(locale, ["common"])), - }, -}); - export default MessagesDashboard; diff --git a/website/src/pages/privacy-policy.tsx b/website/src/pages/privacy-policy.tsx index 2f171483..f84dc1e8 100644 --- a/website/src/pages/privacy-policy.tsx +++ b/website/src/pages/privacy-policy.tsx @@ -1,9 +1,9 @@ import { Box, Heading, Link, Stack, Text, useColorModeValue } from "@chakra-ui/react"; import Head from "next/head"; -import { serverSideTranslations } from "next-i18next/serverSideTranslations"; import { getTransparentHeaderLayout } from "src/components/Layout"; import { PolicyChapterCard } from "src/components/PolicyCards/PolicyChapterCard"; import { PolicySectionCard } from "src/components/PolicyCards/PolicySectionCard"; +export { getDefaultStaticProps as getStaticProps } from "src/lib/default_static_props"; const PrivacyPolicy = () => { const backgroundColor = useColorModeValue("gray.100", "gray.800"); @@ -225,10 +225,4 @@ const PrivacyPolicy = () => { PrivacyPolicy.getLayout = getTransparentHeaderLayout; -export const getStaticProps = async ({ locale }) => ({ - props: { - ...(await serverSideTranslations(locale, ["common"])), - }, -}); - export default PrivacyPolicy; diff --git a/website/src/pages/terms-of-service.tsx b/website/src/pages/terms-of-service.tsx index 3a414292..41269bdf 100644 --- a/website/src/pages/terms-of-service.tsx +++ b/website/src/pages/terms-of-service.tsx @@ -1,9 +1,9 @@ import { Box, Heading, Stack } from "@chakra-ui/react"; import Head from "next/head"; -import { serverSideTranslations } from "next-i18next/serverSideTranslations"; import { getTransparentHeaderLayout } from "src/components/Layout"; import { PolicyChapterCard } from "src/components/PolicyCards/PolicyChapterCard"; import { PolicySectionCard } from "src/components/PolicyCards/PolicySectionCard"; +export { getDefaultStaticProps as getStaticProps } from "src/lib/default_static_props"; const TermsOfService = () => { const TermsData = [ @@ -190,10 +190,4 @@ const TermsOfService = () => { TermsOfService.getLayout = getTransparentHeaderLayout; -export const getStaticProps = async ({ locale }) => ({ - props: { - ...(await serverSideTranslations(locale, ["common"])), - }, -}); - export default TermsOfService;