remove unnecessary SWR hooks
This commit is contained in:
@@ -4,38 +4,27 @@ import Head from "next/head";
|
||||
import { useRouter } from "next/router";
|
||||
import Event from "@models/Event";
|
||||
import EventApi from "@api/eventApi";
|
||||
import useFetchEvents from "@hooks/useFetchEvents";
|
||||
import EventPageView from "@views/EventPage/EventPageView";
|
||||
import PageWrapper from "@views/common/PageWrapper";
|
||||
import LoadingView from "@views/common/LoadingView";
|
||||
import NotFoundPage from "@pages/404";
|
||||
|
||||
interface InitialProps {
|
||||
initialEvent: Event;
|
||||
event: Event;
|
||||
}
|
||||
|
||||
const EventPage: NextPage<InitialProps> = ({ initialEvent }) => {
|
||||
const EventPage: NextPage<InitialProps> = ({ event }) => {
|
||||
const router = useRouter();
|
||||
const { id } = router.query;
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
const { data, error } = useFetchEvents({ initialData: initialEvent, id: id as string });
|
||||
|
||||
if (router.isFallback) return <LoadingView />;
|
||||
|
||||
if (!data) {
|
||||
return (
|
||||
<NotFoundPage />
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<>
|
||||
<Head>
|
||||
<link rel="canonical" href={`${process.env.NEXT_PUBLIC_SITE_URL}/events/${id}`} />
|
||||
</Head>
|
||||
<PageWrapper>
|
||||
<EventPageView event={data as Event} />
|
||||
<EventPageView event={event} />
|
||||
</PageWrapper>
|
||||
</>
|
||||
);
|
||||
@@ -58,16 +47,17 @@ export const getStaticPaths: GetStaticPaths = async () => {
|
||||
export const getStaticProps: GetStaticProps<InitialProps> = async ({ params }) => {
|
||||
const { id } = params;
|
||||
let notFound = false;
|
||||
let initialEvent: Event;
|
||||
let event: Event;
|
||||
try {
|
||||
initialEvent = await EventApi.getEvent(Number(id));
|
||||
event = await EventApi.getEvent(Number(id));
|
||||
} catch (err) {
|
||||
notFound = true;
|
||||
}
|
||||
return {
|
||||
props: {
|
||||
initialEvent,
|
||||
event,
|
||||
},
|
||||
revalidate: 30, // Required for deleting hidden pages
|
||||
notFound,
|
||||
};
|
||||
};
|
||||
|
||||
+7
-17
@@ -4,38 +4,27 @@ import Head from "next/head";
|
||||
import { useRouter } from "next/router";
|
||||
import Post from "@models/Feed";
|
||||
import FeedApi from "@api/feedApi";
|
||||
import useFetchFeed from "@hooks/useFetchFeed";
|
||||
import FeedPageView from "@views/FeedPage/FeedPageView";
|
||||
import PageWrapper from "@views/common/PageWrapper";
|
||||
import LoadingView from "@views/common/LoadingView";
|
||||
import NotFoundPage from "@pages/404";
|
||||
|
||||
interface InitialProps {
|
||||
initialPost: Post;
|
||||
post: Post;
|
||||
}
|
||||
|
||||
const FeedPage: NextPage<InitialProps> = ({ initialPost }) => {
|
||||
const FeedPage: NextPage<InitialProps> = ({ post }) => {
|
||||
const router = useRouter();
|
||||
const { id } = router.query;
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
const { data, error } = useFetchFeed({ initialData: initialPost, id: id as string });
|
||||
|
||||
if (router.isFallback) return <LoadingView />;
|
||||
|
||||
if (!data) {
|
||||
return (
|
||||
<NotFoundPage />
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<>
|
||||
<Head>
|
||||
<link rel="canonical" href={`${process.env.NEXT_PUBLIC_SITE_URL}/feed/${id}`} />
|
||||
</Head>
|
||||
<PageWrapper>
|
||||
<FeedPageView post={data} />
|
||||
<FeedPageView post={post} />
|
||||
</PageWrapper>
|
||||
</>
|
||||
);
|
||||
@@ -58,17 +47,18 @@ export const getStaticPaths: GetStaticPaths = async () => {
|
||||
export const getStaticProps: GetStaticProps<InitialProps> = async ({ params }) => {
|
||||
const { id } = params;
|
||||
let notFound = false;
|
||||
let initialPost: Post;
|
||||
let post: Post;
|
||||
try {
|
||||
initialPost = await FeedApi.getPost(Number(id));
|
||||
post = await FeedApi.getPost(Number(id));
|
||||
} catch (err) {
|
||||
notFound = true;
|
||||
}
|
||||
|
||||
return {
|
||||
props: {
|
||||
initialPost,
|
||||
post,
|
||||
},
|
||||
revalidate: 30, // Required for deleting hidden pages
|
||||
notFound,
|
||||
};
|
||||
};
|
||||
|
||||
@@ -47,7 +47,7 @@ export const getStaticProps: GetStaticProps<InitialProps> = async () => {
|
||||
initialEvents,
|
||||
initialFeed,
|
||||
},
|
||||
revalidate: 10,
|
||||
revalidate: 30,
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
+1
-1
@@ -47,7 +47,7 @@ export const getStaticProps: GetStaticProps<InitialProps> = async () => {
|
||||
initialEvents,
|
||||
initialFeed,
|
||||
},
|
||||
revalidate: 10,
|
||||
revalidate: 30,
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
@@ -39,7 +39,7 @@ export const getStaticProps: GetStaticProps<InitialProps> = async () => {
|
||||
initialEvents,
|
||||
initialFeed,
|
||||
},
|
||||
revalidate: 10,
|
||||
revalidate: 30,
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
@@ -97,6 +97,7 @@ export const getStaticProps: GetStaticProps<InitialProps> = async ({ params }) =
|
||||
props: {
|
||||
initialForm,
|
||||
},
|
||||
revalidate: 30, // Required for deleting hidden pages
|
||||
notFound,
|
||||
};
|
||||
};
|
||||
|
||||
@@ -32,7 +32,7 @@ export const getStaticProps: GetStaticProps<InitialProps> = async () => {
|
||||
props: {
|
||||
initialJobAds,
|
||||
},
|
||||
revalidate: 10,
|
||||
revalidate: 30,
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user