diff --git a/pages/feed/[id].tsx b/pages/feed/[id].tsx index de73215e8c..204e5c226c 100644 --- a/pages/feed/[id].tsx +++ b/pages/feed/[id].tsx @@ -10,8 +10,9 @@ export const getServerSideProps = async (context: HighlightSSRPropsContext) => { export type HighlightSSRPropsContext = GetServerSidePropsContext<{ id: string }>; -export async function handleHighlightSSR({ params }: GetServerSidePropsContext<{ id: string }>) { +export async function handleHighlightSSR({ req, params }: GetServerSidePropsContext<{ id: string }>) { const { id } = params!; + const { referer } = req.headers; async function fetchHighlight() { const req = await fetch(`${process.env.NEXT_PUBLIC_API_URL}/user/highlights/${id}`, { @@ -30,6 +31,9 @@ export async function handleHighlightSSR({ params }: GetServerSidePropsContext<{ const highlight = await fetchHighlight(); return { - props: { highlight }, + props: { + highlight, + referer: referer ?? null, + }, }; } diff --git a/pages/feed/index.tsx b/pages/feed/index.tsx index b501a5b5e1..8976577c4d 100644 --- a/pages/feed/index.tsx +++ b/pages/feed/index.tsx @@ -1,9 +1,11 @@ +/* eslint-disable prettier/prettier */ import { useEffect, useState, useRef } from "react"; import { useRouter } from "next/router"; import Link from "next/link"; import formatDistanceToNowStrict from "date-fns/formatDistanceToNowStrict"; import clsx from "clsx"; +import { AiOutlineClose } from "react-icons/ai"; import TopContributorsPanel from "components/molecules/TopContributorsPanel/top-contributors-panel"; import useSupabaseAuth from "lib/hooks/useSupabaseAuth"; import { useFetchAllHighlights } from "lib/hooks/useFetchAllHighlights"; @@ -19,6 +21,7 @@ import SEO from "layouts/SEO/SEO"; import { Dialog, DialogCloseButton, DialogContent } from "components/molecules/Dialog/dialog"; import Avatar from "components/atoms/Avatar/avatar"; +import Button from "components/atoms/Button/button"; import { Tabs, TabsContent, TabsList, TabsTrigger } from "components/atoms/Tabs/tabs"; import ContributorHighlightCard from "components/molecules/ContributorHighlight/contributor-highlight-card"; import HighlightInputForm from "components/molecules/HighlightInput/highlight-input-form"; @@ -37,6 +40,7 @@ type highlightReposType = { repoName: string; repoIcon: string; full_name: strin interface HighlightSSRProps { highlight: DbHighlight | null; + referer: string; } const Feeds: WithPageLayout = (props: HighlightSSRProps) => { @@ -91,7 +95,6 @@ const Feeds: WithPageLayout = (props: HighlightSSRProps) => { useEffect(() => { if (singleHighlight && !openSingleHighlight) { - router.push(`/feed/${props.highlight?.id}`); setOpenSingleHighlight(true); } }, [singleHighlight]); @@ -155,9 +158,13 @@ const Feeds: WithPageLayout = (props: HighlightSSRProps) => { { - if (!open) { - setOpenSingleHighlight(false); - router.push("/feed"); + if (openSingleHighlight && !open) { + if (props.referer !== null && !props.referer.includes("/feed")) { + router.back(); + } else { + setOpenSingleHighlight(false); + router.replace("/feed"); + } } }} > @@ -179,7 +186,18 @@ const Feeds: WithPageLayout = (props: HighlightSSRProps) => { addSuffix: true, })} - router.push("/feed")} /> + {props.referer !== null && !props.referer.includes("/feed") ? ( + + ) : ( + router.replace("/feed")} /> + )}