From b001d07f726e6dba58846a648f3aacca8170a6db Mon Sep 17 00:00:00 2001 From: Sunday Ogbonna Date: Fri, 4 Aug 2023 01:43:47 +0100 Subject: [PATCH] feat: move create highlight to dialog popup --- .../HighlightInput/highlight-input-form.tsx | 2 +- pages/feed/highlights/new.tsx | 3 + pages/feed/index.tsx | 58 +++++++++++++++++-- 3 files changed, 58 insertions(+), 5 deletions(-) create mode 100644 pages/feed/highlights/new.tsx diff --git a/components/molecules/HighlightInput/highlight-input-form.tsx b/components/molecules/HighlightInput/highlight-input-form.tsx index e42eccf10b..e29788a06b 100644 --- a/components/molecules/HighlightInput/highlight-input-form.tsx +++ b/components/molecules/HighlightInput/highlight-input-form.tsx @@ -27,7 +27,7 @@ interface HighlightInputFormProps { } const HighlightInputForm = ({ refreshCallback }: HighlightInputFormProps): JSX.Element => { - const [isDivFocused, setIsDivFocused] = useState(false); + const [isDivFocused, setIsDivFocused] = useState(true); const [isSummaryButtonDisabled, setIsSummaryButtonDisabled] = useState(false); const [isFormOpenMobile, setIsFormOpenMobile] = useState(false); const [loading, setLoading] = useState(false); diff --git a/pages/feed/highlights/new.tsx b/pages/feed/highlights/new.tsx new file mode 100644 index 0000000000..eff3f840f8 --- /dev/null +++ b/pages/feed/highlights/new.tsx @@ -0,0 +1,3 @@ +import Feed from "../../feed"; + +export default Feed; diff --git a/pages/feed/index.tsx b/pages/feed/index.tsx index 8976577c4d..e4443c2287 100644 --- a/pages/feed/index.tsx +++ b/pages/feed/index.tsx @@ -1,5 +1,5 @@ /* eslint-disable prettier/prettier */ -import { useEffect, useState, useRef } from "react"; +import { useEffect, useState, useRef, useMemo } from "react"; import { useRouter } from "next/router"; import Link from "next/link"; import formatDistanceToNowStrict from "date-fns/formatDistanceToNowStrict"; @@ -34,6 +34,7 @@ import NewsletterForm from "components/molecules/NewsletterForm/newsletter-form" import UserCard, { MetaObj } from "components/atoms/UserCard/user-card"; import FeaturedHighlightsPanel from "components/molecules/FeaturedHighlightsPanel/featured-highlights-panel"; import AnnouncementCard from "components/molecules/AnnouncementCard/announcement-card"; +import Title from "components/atoms/Typography/title"; type activeTabType = "home" | "following"; type highlightReposType = { repoName: string; repoIcon: string; full_name: string }; @@ -46,6 +47,7 @@ interface HighlightSSRProps { const Feeds: WithPageLayout = (props: HighlightSSRProps) => { const { user } = useSupabaseAuth(); const { data: repos } = useFetchHighlightRepos(); + const router = useRouter(); const { data: featuredHighlights } = useFetchFeaturedHighlights(); @@ -58,9 +60,13 @@ const Feeds: WithPageLayout = (props: HighlightSSRProps) => { return filtersArray; }; - const router = useRouter(); + const isCreateHighlight = useMemo(() => { + return router.pathname === "/feed/highlights/new"; + }, [router.pathname]); + const [openSingleHighlight, setOpenSingleHighlight] = useState(false); const [selectedRepo, setSelectedRepo] = useState(""); + const [openCreateHighlight, setOpenCreateHighlight] = useState(isCreateHighlight); const [activeTab, setActiveTab] = useState("home"); const [repoList, setRepoList] = useState(repoTofilterList(repos as highlightReposType[])); const [hydrated, setHydrated] = useState(false); @@ -99,8 +105,25 @@ const Feeds: WithPageLayout = (props: HighlightSSRProps) => { } }, [singleHighlight]); + useEffect(() => { + if (!openCreateHighlight) { + router.replace("/feed"); + setOpenCreateHighlight(false); + } else { + setOpenCreateHighlight(true); + router.replace("/feed/highlights/new"); + } + }, [isCreateHighlight, openCreateHighlight]); + useEffect(() => { setHydrated(true); + if (props.highlight && !openSingleHighlight) { + setOpenSingleHighlight(true); + } + + if (isCreateHighlight) { + setOpenCreateHighlight(true); + } }, []); if (!hydrated) @@ -246,11 +269,16 @@ const Feeds: WithPageLayout = (props: HighlightSSRProps) => { alt="user profile avatar" isCircle size="sm" - avatarURL={`https://www.github.com/${user?.user_metadata.user_name}.png?size=300`} + avatarURL={`https://www.github.com/${user?.user_metadata.user_name}.png?size=100`} /> - + )} @@ -304,6 +332,28 @@ const Feeds: WithPageLayout = (props: HighlightSSRProps) => { )} + + {isCreateHighlight && ( + { + if (!open) { + setOpenCreateHighlight(false); + router.replace("/feed"); + } else { + setOpenCreateHighlight(true); + router.replace("/feed/highlights/new"); + } + }} + > + +
+ What's new! + +
+
+
+ )} );