mirror of
https://github.com/lukevella/rallly.git
synced 2025-05-20 20:36:19 +02:00
🎨 Get urlId during ssr (#521)
This commit is contained in:
parent
ce3e5540db
commit
4ee3d7cc8b
2 changed files with 22 additions and 11 deletions
|
@ -1,6 +1,5 @@
|
||||||
import { GetServerSideProps } from "next";
|
import { GetServerSideProps } from "next";
|
||||||
import Head from "next/head";
|
import Head from "next/head";
|
||||||
import { useRouter } from "next/router";
|
|
||||||
import { useTranslation } from "next-i18next";
|
import { useTranslation } from "next-i18next";
|
||||||
|
|
||||||
import FullPageLoader from "@/components/full-page-loader";
|
import FullPageLoader from "@/components/full-page-loader";
|
||||||
|
@ -16,10 +15,8 @@ import { AdminControls } from "../../components/admin-control";
|
||||||
import ModalProvider from "../../components/modal/modal-provider";
|
import ModalProvider from "../../components/modal/modal-provider";
|
||||||
import { NextPageWithLayout } from "../../types";
|
import { NextPageWithLayout } from "../../types";
|
||||||
|
|
||||||
const Page: NextPageWithLayout = () => {
|
const Page: NextPageWithLayout<{ urlId: string }> = ({ urlId }) => {
|
||||||
const { query } = useRouter();
|
|
||||||
const { t } = useTranslation("app");
|
const { t } = useTranslation("app");
|
||||||
const urlId = query.urlId as string;
|
|
||||||
|
|
||||||
const pollQuery = trpcNext.poll.getByAdminUrlId.useQuery({ urlId });
|
const pollQuery = trpcNext.poll.getByAdminUrlId.useQuery({ urlId });
|
||||||
|
|
||||||
|
@ -53,7 +50,16 @@ const Page: NextPageWithLayout = () => {
|
||||||
Page.getLayout = getStandardLayout;
|
Page.getLayout = getStandardLayout;
|
||||||
|
|
||||||
export const getServerSideProps: GetServerSideProps = withSessionSsr(
|
export const getServerSideProps: GetServerSideProps = withSessionSsr(
|
||||||
withPageTranslations(["common", "app", "errors"]),
|
[
|
||||||
|
withPageTranslations(["common", "app", "errors"]),
|
||||||
|
async (ctx) => {
|
||||||
|
return {
|
||||||
|
props: {
|
||||||
|
urlId: ctx.query.urlId as string,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
},
|
||||||
|
],
|
||||||
{
|
{
|
||||||
onPrefetch: async (ssg, ctx) => {
|
onPrefetch: async (ssg, ctx) => {
|
||||||
await ssg.poll.getByAdminUrlId.fetch({
|
await ssg.poll.getByAdminUrlId.fetch({
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
import { GetServerSideProps } from "next";
|
import { GetServerSideProps } from "next";
|
||||||
import Head from "next/head";
|
import Head from "next/head";
|
||||||
import Link from "next/link";
|
import Link from "next/link";
|
||||||
import { useRouter } from "next/router";
|
|
||||||
import { useTranslation } from "next-i18next";
|
import { useTranslation } from "next-i18next";
|
||||||
|
|
||||||
import { ParticipantsProvider } from "@/components/participants-provider";
|
import { ParticipantsProvider } from "@/components/participants-provider";
|
||||||
|
@ -16,10 +15,7 @@ import StandardLayout from "../../components/layouts/standard-layout";
|
||||||
import ModalProvider from "../../components/modal/modal-provider";
|
import ModalProvider from "../../components/modal/modal-provider";
|
||||||
import { NextPageWithLayout } from "../../types";
|
import { NextPageWithLayout } from "../../types";
|
||||||
|
|
||||||
const Page: NextPageWithLayout = () => {
|
const Page: NextPageWithLayout<{ urlId: string }> = ({ urlId }) => {
|
||||||
const { query } = useRouter();
|
|
||||||
const urlId = query.urlId as string;
|
|
||||||
|
|
||||||
const pollQuery = trpcNext.poll.getByParticipantUrlId.useQuery({ urlId });
|
const pollQuery = trpcNext.poll.getByParticipantUrlId.useQuery({ urlId });
|
||||||
|
|
||||||
const { user } = useUser();
|
const { user } = useUser();
|
||||||
|
@ -62,7 +58,16 @@ Page.getLayout = function getLayout(page) {
|
||||||
};
|
};
|
||||||
|
|
||||||
export const getServerSideProps: GetServerSideProps = withSessionSsr(
|
export const getServerSideProps: GetServerSideProps = withSessionSsr(
|
||||||
withPageTranslations(["common", "app", "errors"]),
|
[
|
||||||
|
withPageTranslations(["common", "app", "errors"]),
|
||||||
|
async (ctx) => {
|
||||||
|
return {
|
||||||
|
props: {
|
||||||
|
urlId: ctx.query.urlId as string,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
},
|
||||||
|
],
|
||||||
{
|
{
|
||||||
onPrefetch: async (ssg, ctx) => {
|
onPrefetch: async (ssg, ctx) => {
|
||||||
await ssg.poll.getByParticipantUrlId.fetch({
|
await ssg.poll.getByParticipantUrlId.fetch({
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue