Skip to content

Commit

Permalink
fix: post-highlight-page-check
Browse files Browse the repository at this point in the history
  • Loading branch information
Anush008 committed Jun 4, 2023
1 parent adcd315 commit 9e0f27b
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 12 deletions.
19 changes: 19 additions & 0 deletions src/hooks/useGithubPRPageCheck.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { useEffect, useState } from "react";
import { isGithubPullRequestPage } from "../utils/urlMatchers";

export const useIsGithubPRPageCheck = () => {
const [isGithubPRPage, setIsGithubPRPage] = useState(false);

useEffect(() => {
chrome.tabs.query({ active: true, currentWindow: true }, tabs => {
if (tabs.length > 0) {
const tab = tabs[0];

setIsGithubPRPage(isGithubPullRequestPage(tab.url!));
}
});
}, []);


return isGithubPRPage;
};
21 changes: 12 additions & 9 deletions src/pages/home.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,12 @@ import { getHighlights } from "../utils/fetchOpenSaucedApiData";
import Help from "./help";
import { OPEN_SAUCED_INSIGHTS_DOMAIN } from "../constants";
import type { Highlight } from "../ts/types";
import { useIsGithubPRPageCheck } from "../hooks/useGithubPRPageCheck";

const Home = () => {
const { user } = useAuth();
const { currentTabIsOpensaucedUser, checkedUser } = useOpensaucedUserCheck();
const isGithubPRPage = useIsGithubPRPageCheck();
const [highlights, setHighlights] = useState<Highlight[]>([]);
const [currentPage, setCurrentPage] = useState(0);

Expand Down Expand Up @@ -173,15 +175,16 @@ const Home = () => {
AI Configuration
</button>

<button
className="flex items-center bg-slate-700 hover:bg-slate-700/70 hover:text-orange text-white gap-2 p-1.5 px-3 w-full rounded-sm font-medium text-sm"
onClick={() => {
goTo(PostOnHighlight);
}}
>
<HiPencil />
Post Highlight
</button>
{isGithubPRPage && (
<button
className="flex items-center bg-slate-700 hover:bg-slate-700/70 hover:text-orange text-white gap-2 p-1.5 px-3 w-full rounded-sm font-medium text-sm"
onClick={() => {
goTo(PostOnHighlight);
}}
>
<HiPencil />
Post Highlight
</button>)}

{currentTabIsOpensaucedUser && (
<button
Expand Down
7 changes: 4 additions & 3 deletions src/pages/posthighlight.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,9 @@ const PostOnHighlight = () => {

return (
<div className="p-4 bg-slate-800">
<Toaster />

<div className="grid grid-cols-1 divide-y divider-y-center-2 min-w-[320px]">
<Toaster />

<header className="flex justify-between">
<div className="flex items-center gap-2">
Expand Down Expand Up @@ -115,15 +116,15 @@ const PostOnHighlight = () => {
disabled={!isSendButtonEnabled}
onClick={() => generateAiDescription()}
>
Summarize
Summarize
</button>

<button
className="inline-block disabled:bg-gray-500 text-black bg-gh-white rounded-md p-2 text-sm font-semibold text-center select-none w-5/12 border hover:shadow-button hover:no-underline"
disabled={!isSendButtonEnabled}
onClick={postHighlight}
>
Post
Post
</button>
</div>
</main>
Expand Down

0 comments on commit 9e0f27b

Please sign in to comment.