Skip to content

Commit

Permalink
chore: lint the files
Browse files Browse the repository at this point in the history
  • Loading branch information
a0m0rajab committed Nov 8, 2023
1 parent bc00fa7 commit 7524d5a
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import { insertTextAtCursor } from "../../../utils/ai-utils/cursorPositionInsert
import { getAIDescriptionConfig } from "../../../utils/ai-utils/descriptionconfig";
import { getAuthToken, isLoggedIn, optLogIn } from "../../../utils/checkAuthentication";

export const DescriptionGeneratorButton = (number: Number) => {
export const DescriptionGeneratorButton = (number: number) => {
const descriptionGeneratorButton = createHtmlElement("a", {
id: "ai-description-button-"+number,
id: `ai-description-button-${number}`,
innerHTML: `<span id="ai-description-gen" class="toolbar-item btn-octicon">
<img class="octicon octicon-heading" height="16px" width="16px" id="ai-description-button-logo" src=${chrome.runtime.getURL(openSaucedLogoIcon)}>
</span>
Expand All @@ -21,7 +21,7 @@ export const DescriptionGeneratorButton = (number: Number) => {
};

const handleSubmit = async (event: Event) => {
const button = event?.currentTarget as HTMLElement;
const button = event.currentTarget as HTMLElement;
const logo = button.querySelector("#ai-description-button-logo");


Expand All @@ -30,27 +30,23 @@ const handleSubmit = async (event: Event) => {
return void optLogIn();
}

if (!logo || !button) {
return;
}

const descriptionConfig = await getAIDescriptionConfig();

if (!descriptionConfig) {
return;
}

logo.classList.toggle("animate-spin");
logo?.classList.toggle("animate-spin");
button.classList.toggle("pointer-events-none");


const { protocol, hostname, pathname } = window.location;
const descriptionStream = await getAiDescription(`${protocol}//${hostname}${pathname}`);
logo.classList.toggle("animate-spin");

logo?.classList.toggle("animate-spin");
button.classList.toggle("pointer-events-none");

const textArea = button.closest(".Box.CommentBox")?.querySelector("textArea") as HTMLTextAreaElement;
const textArea = button.closest(".Box.CommentBox")?.querySelector("textArea");

insertTextAtCursor(textArea, descriptionStream);
} catch (error: unknown) {
Expand Down
2 changes: 1 addition & 1 deletion src/content-scripts/github.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const processGithubPage = async () => {
prReviewWatch(injectChangeSuggestorButton, 500);
} else if (isGithubPullRequestPage(window.location.href)) {
prEditWatch(injectDescriptionGeneratorButton, 500);
void injectDescriptionGeneratorButton();
void injectDescriptionGeneratorButton();
void injectAddPRToHighlightsButton();
} else if (isGithubProfilePage(window.location.href)) {
const username = getGithubUsername(window.location.href);
Expand Down
5 changes: 3 additions & 2 deletions src/utils/dom-utils/addDescriptionGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,10 @@ const injectDescriptionGeneratorButton = async () => {
const actionBars = document.getElementsByClassName(prActionsClassName);
const actionBarsArray = Array.from(actionBars);

actionBarsArray.forEach((actionBar,index) => {
if (!actionBar.querySelector("#ai-description-button-"+index)) {
actionBarsArray.forEach((actionBar, index) => {
if (!actionBar.querySelector(`#ai-description-button-${index}`)) {
const addGeneratorButton = DescriptionGeneratorButton(index);

actionBar.insertBefore(addGeneratorButton, actionBar.firstChild);
}
});
Expand Down

0 comments on commit 7524d5a

Please sign in to comment.