Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: move create highlight form to dialog popup #1481

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
3 changes: 3 additions & 0 deletions pages/feed/highlights/new.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import Feed from "../../feed";

export default Feed;
58 changes: 54 additions & 4 deletions pages/feed/index.tsx
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -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 };
Expand All @@ -46,6 +47,7 @@ interface HighlightSSRProps {
const Feeds: WithPageLayout<HighlightSSRProps> = (props: HighlightSSRProps) => {
const { user } = useSupabaseAuth();
const { data: repos } = useFetchHighlightRepos();
const router = useRouter();

const { data: featuredHighlights } = useFetchFeaturedHighlights();

Expand All @@ -58,9 +60,13 @@ const Feeds: WithPageLayout<HighlightSSRProps> = (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<boolean>(isCreateHighlight);
const [activeTab, setActiveTab] = useState<activeTabType>("home");
const [repoList, setRepoList] = useState<highlightReposType[]>(repoTofilterList(repos as highlightReposType[]));
const [hydrated, setHydrated] = useState(false);
Expand Down Expand Up @@ -99,8 +105,25 @@ const Feeds: WithPageLayout<HighlightSSRProps> = (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)
Expand Down Expand Up @@ -246,11 +269,16 @@ const Feeds: WithPageLayout<HighlightSSRProps> = (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`}
/>
</div>

<HighlightInputForm refreshCallback={mutate} />
<button
className="flex items-center w-full h-10 px-4 text-sm font-normal border rounded-lg cursor-text text-light-slate-9"
onClick={() => setOpenCreateHighlight(true)}
>
Post a highlight to show your work!
</button>
</div>
)}
<TabsContent value="home">
Expand Down Expand Up @@ -304,6 +332,28 @@ const Feeds: WithPageLayout<HighlightSSRProps> = (props: HighlightSSRProps) => {
)}
<NewsletterForm />
</div>

{isCreateHighlight && (
<Dialog
open={openCreateHighlight}
onOpenChange={(open) => {
if (!open) {
setOpenCreateHighlight(false);
router.replace("/feed");
} else {
setOpenCreateHighlight(true);
router.replace("/feed/highlights/new");
}
}}
>
<DialogContent className="sm:max-w-[80%] w-full sm:max-h-screen ">
<div className="space-y-5 w-96">
<Title level={3}>What&apos;s new!</Title>
<HighlightInputForm />
</div>
</DialogContent>
</Dialog>
)}
</div>
</>
);
Expand Down