From c1008e5f94f82cc87f9f3691bdd8d664b6a6f684 Mon Sep 17 00:00:00 2001 From: Brian Douglas Date: Tue, 13 Jun 2023 23:45:04 +0100 Subject: [PATCH 1/6] fix: update email invite message --- .../components/InviteToOpenSauced/InviteToOpenSaucedModal.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/content-scripts/components/InviteToOpenSauced/InviteToOpenSaucedModal.ts b/src/content-scripts/components/InviteToOpenSauced/InviteToOpenSaucedModal.ts index ca8a3117..e8272d67 100644 --- a/src/content-scripts/components/InviteToOpenSauced/InviteToOpenSaucedModal.ts +++ b/src/content-scripts/components/InviteToOpenSauced/InviteToOpenSaucedModal.ts @@ -18,7 +18,7 @@ export const InviteToOpenSaucedModal = ( ) => { const emailBody = typeof emailAddress === "string" && - `Hey ${username}. I'm using OpenSauced to keep track of my contributions and discover new projects. Check it out at https://opensauced.pizza/`; + `Hey ${username}. I'm using OpenSauced to keep track of my contributions and discover new projects. Try connecting your GitHub to https://opensauced.pizza/`; const emailHref = typeof emailAddress === "string" && `mailto:${emailAddress}?subject=${encodeURIComponent( From 6289d5917944b3e70401231969bb790b3c7f09c6 Mon Sep 17 00:00:00 2001 From: Brian Douglas Date: Tue, 13 Jun 2023 22:46:33 +0000 Subject: [PATCH 2/6] chore(patch): release 1.6.1-beta.1 on beta channel [skip ci] MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## [1.6.1-beta.1](https://github.com/open-sauced/ai/compare/v1.6.0...v1.6.1-beta.1) (2023-06-13) ### 🐛 Bug Fixes * update email invite message ([c1008e5](https://github.com/open-sauced/ai/commit/c1008e5f94f82cc87f9f3691bdd8d664b6a6f684)) --- CHANGELOG.md | 7 +++++++ npm-shrinkwrap.json | 4 ++-- package.json | 2 +- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cb4b5e6d..bbcd0503 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,13 @@ > All notable changes to this project will be documented in this file +## [1.6.1-beta.1](https://github.com/open-sauced/ai/compare/v1.6.0...v1.6.1-beta.1) (2023-06-13) + + +### 🐛 Bug Fixes + +* update email invite message ([c1008e5](https://github.com/open-sauced/ai/commit/c1008e5f94f82cc87f9f3691bdd8d664b6a6f684)) + ## [1.6.0](https://github.com/open-sauced/ai/compare/v1.5.0...v1.6.0) (2023-06-13) diff --git a/npm-shrinkwrap.json b/npm-shrinkwrap.json index 40034439..1e157122 100644 --- a/npm-shrinkwrap.json +++ b/npm-shrinkwrap.json @@ -1,12 +1,12 @@ { "name": "opensauced-browser-extension", - "version": "1.6.0", + "version": "1.6.1-beta.1", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "opensauced-browser-extension", - "version": "1.6.0", + "version": "1.6.1-beta.1", "dependencies": { "date-fns": "^2.30.0", "gpt-tokenizer": "^1.0.5", diff --git a/package.json b/package.json index ba8373ae..1c44f0c0 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "opensauced-browser-extension", "private": true, - "version": "1.6.0", + "version": "1.6.1-beta.1", "files": [ "dist" ], From 4901f7b322b87e27ed755be598c2975d6329f067 Mon Sep 17 00:00:00 2001 From: Punyam Singh <89277920+punyamsingh@users.noreply.github.com> Date: Thu, 15 Jun 2023 03:19:22 +0530 Subject: [PATCH 3/6] feat: Added Contributed Repos to profile page (#181) Co-authored-by: Brian Douglas Co-authored-by: Divyansh Singh --- src/popup/pages/profile.tsx | 9 ++++++--- src/utils/getContributedRepos.ts | 19 +++++++++++++++++++ 2 files changed, 25 insertions(+), 3 deletions(-) create mode 100644 src/utils/getContributedRepos.ts diff --git a/src/popup/pages/profile.tsx b/src/popup/pages/profile.tsx index dc8b8dfc..2c0a80e7 100644 --- a/src/popup/pages/profile.tsx +++ b/src/popup/pages/profile.tsx @@ -8,6 +8,7 @@ import { getUserData, getUserPRData, getUserHighlightsData } from "../../utils/f import { emojify } from "node-emoji"; import { goBack, goTo } from "react-chrome-extension-router"; import { getRelativeDays } from "../../utils/dateUtils"; +import { countUniqueRepos, PRResponse } from "../../utils/getContributedRepos"; import { getUserPRVelocity } from "../../utils/getUserPRVelocity"; import { BiExit } from "react-icons/bi"; import Start from "./start"; @@ -35,7 +36,7 @@ type InterestIconKeys = keyof typeof interestIcon; export const Profile = ({ username }: { username: string }) => { const [user, setUser] = useState(null); - const [userPR, setUserPR] = useState(null); + const [userPR, setUserPR] = useState(null); const [userHighlights, setUserHighlights] = useState(null); const [userPRVelocity, setUserPRVelocity] = useState(0); @@ -82,7 +83,7 @@ export const Profile = ({ username }: { username: string }) => { }} > - Log Out + Log Out @@ -178,7 +179,9 @@ export const Profile = ({ username }: { username: string }) => {

Contributed Repos

-

-

+

+ {countUniqueRepos(userPR)} +

diff --git a/src/utils/getContributedRepos.ts b/src/utils/getContributedRepos.ts new file mode 100644 index 00000000..48913ca6 --- /dev/null +++ b/src/utils/getContributedRepos.ts @@ -0,0 +1,19 @@ +export interface PRResponse { + data: { + full_name: string; + }[] + meta: { + itemCount: number; + }; +} + +export const countUniqueRepos = (response: PRResponse | null):number => { + if (!response?.data) { + return 0; + } + + const { data } = response; + const uniqueRepos = new Set(data.map(obj => obj.full_name)); + + return uniqueRepos.size; +}; From ab8fb1660e5c209c31fcd260922564eafb81db4d Mon Sep 17 00:00:00 2001 From: Punyam Singh <89277920+punyamsingh@users.noreply.github.com> Date: Wed, 14 Jun 2023 21:51:00 +0000 Subject: [PATCH 4/6] chore(minor): release 1.7.0-beta.1 on beta channel [skip ci] MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## [1.7.0-beta.1](https://github.com/open-sauced/ai/compare/v1.6.1-beta.1...v1.7.0-beta.1) (2023-06-14) ### 🍕 Features * Added Contributed Repos to profile page ([#181](https://github.com/open-sauced/ai/issues/181)) ([4901f7b](https://github.com/open-sauced/ai/commit/4901f7b322b87e27ed755be598c2975d6329f067)) --- CHANGELOG.md | 7 +++++++ npm-shrinkwrap.json | 4 ++-- package.json | 2 +- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bbcd0503..30b79417 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,13 @@ > All notable changes to this project will be documented in this file +## [1.7.0-beta.1](https://github.com/open-sauced/ai/compare/v1.6.1-beta.1...v1.7.0-beta.1) (2023-06-14) + + +### 🍕 Features + +* Added Contributed Repos to profile page ([#181](https://github.com/open-sauced/ai/issues/181)) ([4901f7b](https://github.com/open-sauced/ai/commit/4901f7b322b87e27ed755be598c2975d6329f067)) + ## [1.6.1-beta.1](https://github.com/open-sauced/ai/compare/v1.6.0...v1.6.1-beta.1) (2023-06-13) diff --git a/npm-shrinkwrap.json b/npm-shrinkwrap.json index 1e157122..d1a81a86 100644 --- a/npm-shrinkwrap.json +++ b/npm-shrinkwrap.json @@ -1,12 +1,12 @@ { "name": "opensauced-browser-extension", - "version": "1.6.1-beta.1", + "version": "1.7.0-beta.1", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "opensauced-browser-extension", - "version": "1.6.1-beta.1", + "version": "1.7.0-beta.1", "dependencies": { "date-fns": "^2.30.0", "gpt-tokenizer": "^1.0.5", diff --git a/package.json b/package.json index 1c44f0c0..6123a7d1 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "opensauced-browser-extension", "private": true, - "version": "1.6.1-beta.1", + "version": "1.7.0-beta.1", "files": [ "dist" ], From ef5243921ced600cec4ed0270c76ecdf9885ab0b Mon Sep 17 00:00:00 2001 From: Anush Date: Thu, 15 Jun 2023 00:35:11 -0700 Subject: [PATCH 5/6] feat: AI PR review menu (#174) * feat: code-test-refactor-explanation menu * refactor: pr description config page * chore: restructure AICodeReview * fix: discussions URL * fix: dependency vulnerability * fix: multiple processing of PR page * refactor: Move AI utilities to ai-utils dir * chore: use new endpoints * chore: Added optional trailing slash PR page regex * Update src/content-scripts/components/AICodeReview/AICodeReviewButton.ts Co-authored-by: Divyansh Singh --------- Co-authored-by: Divyansh Singh --- npm-shrinkwrap.json | 7 +- src/constants.ts | 2 + .../AICodeRefactor/ChangeSuggestorButton.ts | 88 ----------- .../AICodeReview/AICodeReviewButton.ts | 49 ++++++ .../AICodeReview/AICodeReviewMenu.ts | 148 ++++++++++++++++++ .../DescriptionGeneratorButton.ts | 6 +- src/hooks/useRefs.ts | 11 -- src/popup/pages/aiprdescription.tsx | 22 +-- .../configurationReducer.ts | 0 .../cursorPositionInsert.ts | 0 .../descriptionconfig.ts | 0 src/utils/ai-utils/openai.ts | 144 +++++++++++++++++ src/utils/aiprdescription/openai.ts | 77 --------- src/utils/dom-utils/changeSuggestorButton.ts | 4 +- src/utils/fetchGithubAPIData.ts | 2 +- src/utils/urlMatchers.ts | 2 +- src/worker/background.ts | 2 +- 17 files changed, 357 insertions(+), 207 deletions(-) delete mode 100644 src/content-scripts/components/AICodeRefactor/ChangeSuggestorButton.ts create mode 100644 src/content-scripts/components/AICodeReview/AICodeReviewButton.ts create mode 100644 src/content-scripts/components/AICodeReview/AICodeReviewMenu.ts delete mode 100644 src/hooks/useRefs.ts rename src/utils/{aiprdescription => ai-utils}/configurationReducer.ts (100%) rename src/utils/{aiprdescription => ai-utils}/cursorPositionInsert.ts (100%) rename src/utils/{aiprdescription => ai-utils}/descriptionconfig.ts (100%) create mode 100644 src/utils/ai-utils/openai.ts delete mode 100644 src/utils/aiprdescription/openai.ts diff --git a/npm-shrinkwrap.json b/npm-shrinkwrap.json index d1a81a86..5805cc40 100644 --- a/npm-shrinkwrap.json +++ b/npm-shrinkwrap.json @@ -6600,11 +6600,10 @@ } }, "node_modules/vite": { - "version": "2.9.15", - "resolved": "https://registry.npmjs.org/vite/-/vite-2.9.15.tgz", - "integrity": "sha512-fzMt2jK4vQ3yK56te3Kqpkaeq9DkcZfBbzHwYpobasvgYmP2SoAr6Aic05CsB4CzCZbsDv4sujX3pkEGhLabVQ==", + "version": "2.9.16", + "resolved": "https://registry.npmjs.org/vite/-/vite-2.9.16.tgz", + "integrity": "sha512-X+6q8KPyeuBvTQV8AVSnKDvXoBMnTx8zxh54sOwmmuOdxkjMmEJXH2UEchA+vTMps1xw9vL64uwJOWryULg7nA==", "dev": true, - "license": "MIT", "dependencies": { "esbuild": "^0.14.27", "postcss": "^8.4.13", diff --git a/src/constants.ts b/src/constants.ts index 5f8aefa7..c493c81c 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -17,6 +17,8 @@ export const OPEN_SAUCED_USER_INSIGHTS_ENDPOINT = `${OPEN_SAUCED_API_ENDPOINT}/u export const OPEN_SAUCED_AI_PR_DESCRIPTION_ENDPOINT = `${OPEN_SAUCED_API_ENDPOINT}/prs/description/generate`; export const OPEN_SAUCED_USER_HIGHLIGHTS_ENDPOINT = `${OPEN_SAUCED_API_ENDPOINT}/user/highlights`; export const OPEN_SAUCED_AI_CODE_REFACTOR_ENDPOINT = `${OPEN_SAUCED_API_ENDPOINT}/prs/suggestion/generate`; +export const OPEN_SAUCED_AI_CODE_EXPLANATION_ENDPOINT = `${OPEN_SAUCED_API_ENDPOINT}/prs/explanation/generate`; +export const OPEN_SAUCED_AI_CODE_TEST_ENDPOINT = `${OPEN_SAUCED_API_ENDPOINT}/prs/test/generate`; export const OPEN_SAUCED_HIGHLIGHTS_ENDPOINT = `${OPEN_SAUCED_API_ENDPOINT}/highlights/list`; // GitHub constants/selectors diff --git a/src/content-scripts/components/AICodeRefactor/ChangeSuggestorButton.ts b/src/content-scripts/components/AICodeRefactor/ChangeSuggestorButton.ts deleted file mode 100644 index fa6f1c58..00000000 --- a/src/content-scripts/components/AICodeRefactor/ChangeSuggestorButton.ts +++ /dev/null @@ -1,88 +0,0 @@ -import { createHtmlElement } from "../../../utils/createHtmlElement"; -import openSaucedLogoIcon from "../../../assets/opensauced-icon.svg"; -import { GITHUB_PR_SUGGESTION_TEXT_AREA_SELECTOR, SUPABASE_LOGIN_URL } from "../../../constants"; -import { generateCodeSuggestion } from "../../../utils/aiprdescription/openai"; -import { isOutOfContextBounds } from "../../../utils/fetchGithubAPIData"; -import { insertTextAtCursor } from "../../../utils/aiprdescription/cursorPositionInsert"; -import { getAIDescriptionConfig } from "../../../utils/aiprdescription/descriptionconfig"; -import { getAuthToken, isLoggedIn } from "../../../utils/checkAuthentication"; - -export const ChangeSuggestorButton = (commentNode: HTMLElement) => { - const changeSuggestorButton = createHtmlElement("a", { - innerHTML: ` - - - Get Refactor Suggestions`, - onclick: async () => handleSubmit(commentNode), - id: "os-ai-change-gen", - }); - - return changeSuggestorButton; -}; - -const handleSubmit = async (commentNode: HTMLElement) => { - const logo = document.getElementById("ai-description-button-logo"); - const button = document.getElementById("os-ai-change-gen"); - - try { - if (!(await isLoggedIn())) { - return window.open(SUPABASE_LOGIN_URL, "_blank"); - } - - if (!logo || !button) { - return; - } - - const descriptionConfig = await getAIDescriptionConfig(); - - if (!descriptionConfig) { - return; - } - - logo.classList.toggle("animate-spin"); - button.classList.toggle("pointer-events-none"); - - const selectedLines = document.querySelectorAll(".code-review.selected-line"); - let selectedCode = Array.from(selectedLines).map(line => line.textContent) - .join("\n"); - - // find input with name="position" and get its value - if (!selectedCode) { - const positionElement = (commentNode.querySelector("input[name=position]")!); - const position = positionElement.getAttribute("value")!; - - const codeDiv = document.querySelector(`[data-line-number="${position}"]`)?.nextSibling?.nextSibling as HTMLElement; - - selectedCode = codeDiv.getElementsByClassName("blob-code-inner")[0].textContent!; - } - if (isOutOfContextBounds([selectedCode, [] ], descriptionConfig.config.maxInputLength)) { - logo.classList.toggle("animate-spin"); - return alert(`Max input length exceeded. Try reducing the number of selected lines to refactor.`); - } - const token = await getAuthToken(); - const suggestionStream = await generateCodeSuggestion( - token, - descriptionConfig.config.language, - descriptionConfig.config.length, - descriptionConfig.config.temperature / 10, - selectedCode, - ); - - logo.classList.toggle("animate-spin"); - button.classList.toggle("pointer-events-none"); - if (!suggestionStream) { - return console.error("No description was generated!"); - } - const textArea = commentNode.querySelector(GITHUB_PR_SUGGESTION_TEXT_AREA_SELECTOR)!; - - insertTextAtCursor(textArea as HTMLTextAreaElement, suggestionStream); - } catch (error: unknown) { - logo?.classList.toggle("animate-spin"); - button?.classList.toggle("pointer-events-none"); - - if (error instanceof Error) { - console.error("Description generation error:", error.message); - } - } -}; - diff --git a/src/content-scripts/components/AICodeReview/AICodeReviewButton.ts b/src/content-scripts/components/AICodeReview/AICodeReviewButton.ts new file mode 100644 index 00000000..273ed1f0 --- /dev/null +++ b/src/content-scripts/components/AICodeReview/AICodeReviewButton.ts @@ -0,0 +1,49 @@ +import { createHtmlElement } from "../../../utils/createHtmlElement"; +import openSaucedLogoIcon from "../../../assets/opensauced-icon.svg"; +import { generateCodeExplanation, generateCodeSuggestion, generateCodeTest } from "../../../utils/ai-utils/openai"; +import { + AICodeReviewMenu, + AICodeReviewMenuItem, +} from "./AICodeReviewMenu"; + + +export const AICodeReviewButton = (commentNode: HTMLElement) => { + const changeSuggestorButton = createHtmlElement("a", { + innerHTML: ` + + `, + onclick: (event: MouseEvent) => { + event.stopPropagation(); + menu.classList.toggle("hidden"); + }, + id: "os-ai-change-gen", + }); + + const refactorCode = AICodeReviewMenuItem( + "Refactor Code", + "Generate a code refactor", + generateCodeSuggestion, + commentNode, + ); + const testCode = AICodeReviewMenuItem( + "Test Code", + "Generate a test for the code", + generateCodeTest, + commentNode, + ); + const explainCode = AICodeReviewMenuItem( + "Explain Code", + "Generate an explanation for the code", + generateCodeExplanation, + commentNode, + ); + + const menu = AICodeReviewMenu([refactorCode, testCode, explainCode]); + + changeSuggestorButton.append(menu); + return changeSuggestorButton; +}; + + diff --git a/src/content-scripts/components/AICodeReview/AICodeReviewMenu.ts b/src/content-scripts/components/AICodeReview/AICodeReviewMenu.ts new file mode 100644 index 00000000..c5d76ddf --- /dev/null +++ b/src/content-scripts/components/AICodeReview/AICodeReviewMenu.ts @@ -0,0 +1,148 @@ +import { + SUPABASE_LOGIN_URL, + GITHUB_PR_SUGGESTION_TEXT_AREA_SELECTOR, +} from "../../../constants"; +import { insertTextAtCursor } from "../../../utils/ai-utils/cursorPositionInsert"; +import { + DescriptionConfig, + getAIDescriptionConfig, +} from "../../../utils/ai-utils/descriptionconfig"; +import { getAuthToken, isLoggedIn } from "../../../utils/checkAuthentication"; +import { createHtmlElement } from "../../../utils/createHtmlElement"; +import { isOutOfContextBounds } from "../../../utils/fetchGithubAPIData"; + +type SuggestionGenerator = ( + token: string, + code: string, + config: DescriptionConfig +) => Promise; + +export const AICodeReviewMenu = (items: HTMLLIElement[]) => { + const menu = createHtmlElement("div", { + className: "SelectMenu js-slash-command-menu hidden mt-6", + innerHTML: `
+
+
+ + OpenSauced.ai +
+
AI
+ + Give feedback + +
+
+
    +
+
+
`, + }); + + menu.querySelector("ul")?.append(...items); + + document.addEventListener("click", event => { + if (event.target instanceof HTMLElement) { + menu.classList.add("hidden"); + } + }); + return menu; +}; + +export const AICodeReviewMenuItem = (title: string, description: string, suggestionGenerator: SuggestionGenerator, commentNode: HTMLElement) => { + const menuItem = createHtmlElement("li", { + className: "SelectMenu-item d-block slash-command-menu-item", + role: "option", + onclick: () => { + void handleSubmit(suggestionGenerator, commentNode); + }, + innerHTML: `
${title}
+ ${description}`, + }); + + return menuItem; +}; + +const handleSubmit = async ( + suggestionGenerator: SuggestionGenerator, + commentNode: HTMLElement, +) => { + const logo = commentNode.querySelector("#ai-description-button-logo"); + const button = commentNode.querySelector("#os-ai-change-gen"); + + try { + if (!(await isLoggedIn())) { + return window.open(SUPABASE_LOGIN_URL, "_blank"); + } + + if (!logo || !button) { + return; + } + + const descriptionConfig = await getAIDescriptionConfig(); + + if (!descriptionConfig) { + return; + } + + logo.classList.toggle("animate-spin"); + button.classList.toggle("pointer-events-none"); + + const selectedLines = document.querySelectorAll( + ".code-review.selected-line", + ); + let selectedCode = Array.from(selectedLines) + .map(line => line.textContent) + .join("\n"); + + // find input with name="position" and get its value + if (!selectedCode) { + const positionElement = commentNode.querySelector( + "input[name=position]", + )!; + const position = positionElement.getAttribute("value")!; + + const codeDiv = document.querySelector(`[data-line-number="${position}"]`) + ?.nextSibling?.nextSibling as HTMLElement; + + selectedCode = + codeDiv.getElementsByClassName("blob-code-inner")[0].textContent!; + } + if ( + isOutOfContextBounds( + [selectedCode, [] ], + descriptionConfig.config.maxInputLength, + ) + ) { + logo.classList.toggle("animate-spin"); + return alert( + `Max input length exceeded. Try reducing the number of selected lines to refactor.`, + ); + } + const token = await getAuthToken(); + const suggestionStream = await suggestionGenerator( + token, + selectedCode, + descriptionConfig, + ); + + logo.classList.toggle("animate-spin"); + button.classList.toggle("pointer-events-none"); + if (!suggestionStream) { + return console.error("No description was generated!"); + } + const textArea = commentNode.querySelector( + GITHUB_PR_SUGGESTION_TEXT_AREA_SELECTOR, + )!; + + insertTextAtCursor(textArea as HTMLTextAreaElement, suggestionStream); + } catch (error: unknown) { + logo?.classList.toggle("animate-spin"); + button?.classList.toggle("pointer-events-none"); + + if (error instanceof Error) { + console.error("Description generation error:", error.message); + } + } +}; diff --git a/src/content-scripts/components/GenerateAIDescription/DescriptionGeneratorButton.ts b/src/content-scripts/components/GenerateAIDescription/DescriptionGeneratorButton.ts index 6c54d5a4..f5374fca 100644 --- a/src/content-scripts/components/GenerateAIDescription/DescriptionGeneratorButton.ts +++ b/src/content-scripts/components/GenerateAIDescription/DescriptionGeneratorButton.ts @@ -2,10 +2,10 @@ import { createHtmlElement } from "../../../utils/createHtmlElement"; import openSaucedLogoIcon from "../../../assets/opensauced-icon.svg"; import { getPullRequestAPIURL } from "../../../utils/urlMatchers"; import { getDescriptionContext, isOutOfContextBounds } from "../../../utils/fetchGithubAPIData"; -import { generateDescription } from "../../../utils/aiprdescription/openai"; +import { generateDescription } from "../../../utils/ai-utils/openai"; import { GITHUB_PR_COMMENT_TEXT_AREA_SELECTOR, SUPABASE_LOGIN_URL } from "../../../constants"; -import { insertTextAtCursor } from "../../../utils/aiprdescription/cursorPositionInsert"; -import { getAIDescriptionConfig } from "../../../utils/aiprdescription/descriptionconfig"; +import { insertTextAtCursor } from "../../../utils/ai-utils/cursorPositionInsert"; +import { getAIDescriptionConfig } from "../../../utils/ai-utils/descriptionconfig"; import { getAuthToken, isLoggedIn } from "../../../utils/checkAuthentication"; export const DescriptionGeneratorButton = () => { diff --git a/src/hooks/useRefs.ts b/src/hooks/useRefs.ts deleted file mode 100644 index f5a287c2..00000000 --- a/src/hooks/useRefs.ts +++ /dev/null @@ -1,11 +0,0 @@ -import { useRef } from "react"; - -export const useRefs = () => { - const refs = useRef>({}); - - const setRefFromKey = (key: string) => (element: HTMLElement | null) => { - refs.current[key] = element; - }; - - return { refs: refs.current, setRefFromKey }; -}; diff --git a/src/popup/pages/aiprdescription.tsx b/src/popup/pages/aiprdescription.tsx index cf2e0dbc..5e82d402 100644 --- a/src/popup/pages/aiprdescription.tsx +++ b/src/popup/pages/aiprdescription.tsx @@ -10,14 +10,12 @@ import { DescriptionLanguage, setAIDescriptionConfig, getDefaultDescriptionConfig, -} from "../../utils/aiprdescription/descriptionconfig"; -import { useRefs } from "../../hooks/useRefs"; -import { configurationReducer } from "../../utils/aiprdescription/configurationReducer"; +} from "../../utils/ai-utils/descriptionconfig"; +import { configurationReducer } from "../../utils/ai-utils/configurationReducer"; import { goBack } from "react-chrome-extension-router"; const AIPRDescription = () => { const [config, dispatch] = useReducer(configurationReducer, getDefaultDescriptionConfig()); - const { refs, setRefFromKey } = useRefs(); const tones: DescriptionTone[] = ["exciting", "persuasive", "informative", "humorous", "formal"]; const sources: DescriptionSource[] = ["diff", "commitMessage", "both"]; @@ -36,14 +34,7 @@ const AIPRDescription = () => { const handleFormSubmit = (e: React.FormEvent) => { e.preventDefault(); - const length = parseInt(refs.length?.getAttribute("value") ?? "0"); - const temperature = Number(Number(refs.temperature?.getAttribute("value") ?? "0")); - const maxInputLength = parseInt(refs.maxInputLength?.getAttribute("value") ?? "0"); - const language = (refs.language as HTMLSelectElement).value as DescriptionLanguage; - const source = (refs.source as HTMLSelectElement).value as DescriptionSource; - const tone = (refs.tone as HTMLSelectElement).value as DescriptionTone; - - void setAIDescriptionConfig({ config: { length, temperature, maxInputLength, language, source, tone } }); + void setAIDescriptionConfig(config); toast.success("Configuration updated!"); }; @@ -75,7 +66,6 @@ const AIPRDescription = () => {
@@ -94,7 +84,6 @@ const AIPRDescription = () => {

{

{

{

Description Language

{

Description Source