Skip to content

Commit

Permalink
fix: post-highlight-page-check (#164)
Browse files Browse the repository at this point in the history
  • Loading branch information
Anush008 committed Jun 4, 2023
1 parent dd67720 commit ed98eb2
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 36 deletions.
4 changes: 2 additions & 2 deletions index.html
Expand Up @@ -2,9 +2,9 @@
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/src/favicon.svg" />
<link rel="icon" type="image/svg+xml" href="/src/assets/opensauced-logo.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Vite App</title>
<title>OpenSauced.ai</title>
</head>
<body>
<div id="root"></div>
Expand Down
22 changes: 0 additions & 22 deletions src/content-scripts.css

This file was deleted.

19 changes: 19 additions & 0 deletions src/hooks/useGithubPRPageCheck.ts
@@ -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
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
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 ed98eb2

Please sign in to comment.