Skip to content

Commit

Permalink
fix: Multiple button injections (#244)
Browse files Browse the repository at this point in the history
* chore: updates dependencies

* fix: multiple button injections

* fix: public repo check
  • Loading branch information
Anush008 authored Aug 10, 2023
1 parent 7ad0fdf commit 0e06d3e
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 21 deletions.
37 changes: 18 additions & 19 deletions npm-shrinkwrap.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions src/hooks/useGetGitHubPageInfo.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { useEffect, useState } from "react";
import { isGithubPullRequestPage, isGithubRepoPage } from "../utils/urlMatchers";
import { isPublicRepository } from "../utils/fetchGithubAPIData";

interface GitHubPageInfo {
pageUrl: string;
Expand All @@ -11,13 +12,13 @@ export const usGetGitHubPageInfo = () => {
const [GithubPage, setGithubPage] = useState<GitHubPageInfo>({ pageUrl: "", pageTitle: "", type: "unknown" });

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

if (isGithubPullRequestPage(tab.url!)) {
setGithubPage({ pageUrl: tab.url!, pageTitle: tab.title!.split("by")[0].trim(), type: "PR" });
} else if (isGithubRepoPage(tab.url!)) {
} else if (isGithubRepoPage(tab.url!) && (await isPublicRepository(tab.url!))) {
setGithubPage({ pageUrl: tab.url!, pageTitle: "", type: "REPO" });
}
}
Expand Down
7 changes: 7 additions & 0 deletions src/utils/dom-utils/prWatcher.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import domUpdateWatch from "./domUpdateWatcher";

const prEditWatch = (callback: () => void, delayInMs = 0) => {
const observer = new MutationObserver((mutationList: MutationRecord[], observer: MutationObserver) => {
mutationList.forEach(mutation => {
Expand All @@ -8,6 +10,11 @@ const prEditWatch = (callback: () => void, delayInMs = 0) => {
});
});

// Disconnect the observer when the user navigates to a new page
domUpdateWatch(() => {
observer.disconnect();
});

observer.observe(document.body, { attributes: true, subtree: true });
};

Expand Down

0 comments on commit 0e06d3e

Please sign in to comment.