Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: view on open sauced location #224

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 37 additions & 17 deletions src/constants.ts
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aren't there too many unnecessary changes in this file?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no just added 1 more field , maybe we can remove the bio selector as its not being used now

Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
// OpenSauced constants
export const OPEN_SAUCED_INSIGHTS_DOMAIN = import.meta.env.VITE_OPEN_SAUCED_INSIGHTS_DOMAIN;
export const OPEN_SAUCED_API_ENDPOINT = import.meta.env.VITE_OPEN_SAUCED_API_ENDPOINT;
export const SUPABASE_LOGIN_URL = `https://${import.meta.env.VITE_OPEN_SAUCED_SUPABASE_ID}.supabase.co/auth/v1/authorize?provider=github&redirect_to=https://${OPEN_SAUCED_INSIGHTS_DOMAIN}/`;
export const OPEN_SAUCED_INSIGHTS_DOMAIN = import.meta.env
.VITE_OPEN_SAUCED_INSIGHTS_DOMAIN;
export const OPEN_SAUCED_API_ENDPOINT = import.meta.env
.VITE_OPEN_SAUCED_API_ENDPOINT;
export const SUPABASE_LOGIN_URL = `https://${
import.meta.env.VITE_OPEN_SAUCED_SUPABASE_ID
}.supabase.co/auth/v1/authorize?provider=github&redirect_to=https://${OPEN_SAUCED_INSIGHTS_DOMAIN}/`;


export const SUPABASE_AUTH_COOKIE_NAME = `sb-${import.meta.env.VITE_OPEN_SAUCED_SUPABASE_ID}-auth-token`;
export const SUPABASE_AUTH_COOKIE_NAME = `sb-${
import.meta.env.VITE_OPEN_SAUCED_SUPABASE_ID
}-auth-token`;
export const OPEN_SAUCED_AUTH_TOKEN_KEY = "os-access-token";
export const OPEN_SAUCED_OPTED_LOG_OUT_KEY = "opted-log-out";
export const AI_PR_DESCRIPTION_CONFIG_KEY = "ai-pr-description-config";


export const OPEN_SAUCED_USERS_ENDPOINT = `${OPEN_SAUCED_API_ENDPOINT}/users`;
export const OPEN_SAUCED_REPOS_ENDPOINT = `${OPEN_SAUCED_API_ENDPOINT}/repos`;
export const OPEN_SAUCED_SESSION_ENDPOINT = `${OPEN_SAUCED_API_ENDPOINT}/auth/session`;
Expand All @@ -24,21 +28,37 @@ export const OPEN_SAUCED_HIGHLIGHTS_LIST_ENDPOINT = `${OPEN_SAUCED_API_ENDPOINT}
export const OPEN_SAUCED_EMOJIS_ENDPOINT = `${OPEN_SAUCED_API_ENDPOINT}/emojis`;

// GitHub constants/selectors
export const GITHUB_PROFILE_MENU_SELECTOR = ".p-nickname.vcard-username.d-block";
export const GITHUB_PROFILE_EDIT_MENU_SELECTOR = "button.js-profile-editable-edit-button";
export const GITHUB_PROFILE_USER_PROFILE_BIO_SELECTOR = ".p-note.user-profile-bio.mb-3.js-user-profile-bio.f4";
export const GITHUB_PR_COMMENT_HEADER_SELECTOR = "timeline-comment-header clearfix d-flex";
export const GITHUB_NEW_PR_COMMENT_EDITOR_SELECTOR = "flex-nowrap d-none d-md-inline-block mr-md-0 mr-3";
export const GITHUB_PR_COMMENT_EDITOR_SELECTOR = "flex-nowrap d-inline-block mr-3";
export const GITHUB_REVIEW_SUGGESTION_SELECTOR = "js-suggestion-button-placeholder";
export const GITHUB_PROFILE_MENU_SELECTOR =
".p-nickname.vcard-username.d-block";
export const GITHUB_PROFILE_EDIT_MENU_SELECTOR =
"button.js-profile-editable-edit-button";
export const GITHUB_PROFILE_USER_PROFILE_BIO_SELECTOR =
".p-note user-profile-bio mb-3 js-user-profile-bio f4";
export const GITHUB_PROFILE_USER_PROFILE_EDITABLE_AREA_SELECTOR =
"js-profile-editable-area d-flex flex-column d-md-block";
export const GITHUB_PR_COMMENT_HEADER_SELECTOR =
"timeline-comment-header clearfix d-flex";
export const GITHUB_NEW_PR_COMMENT_EDITOR_SELECTOR =
"flex-nowrap d-none d-md-inline-block mr-md-0 mr-3";
export const GITHUB_PR_COMMENT_EDITOR_SELECTOR =
"flex-nowrap d-inline-block mr-3";
export const GITHUB_REVIEW_SUGGESTION_SELECTOR =
"js-suggestion-button-placeholder";
export const GITHUB_REPO_ACTIONS_SELECTOR = ".pagehead-actions";
export const GITHUB_PR_COMMENT_TEXT_AREA_SELECTOR = "pull_request[body]";
export const GITHUB_PR_SUGGESTION_TEXT_AREA_SELECTOR = "[name='comment[body]']";
export const GITHUB_PR_BASE_BRANCH_SELECTOR = "css-truncate css-truncate-target";
export const GITHUB_PR_BASE_BRANCH_SELECTOR =
"css-truncate css-truncate-target";

// External Links
export const EXTERNAL_RESOURCES = [
{ link: "https://docs.opensauced.pizza/chrome-extension/introduction-to-the-chrome-extension/", key: "Docs" },
{ link: "https://github.com/open-sauced/ai/issues", key: "Issues" },
{ link: "https://github.com/orgs/open-sauced/discussions", key: "Discussions" },
{
link: "https://docs.opensauced.pizza/chrome-extension/introduction-to-the-chrome-extension/",
key: "Docs",
},
{ link: "https://github.com/open-sauced/ai/issues", key: "Issues" },
{
link: "https://github.com/orgs/open-sauced/discussions",
key: "Discussions",
},
];
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ import { createHtmlElement } from "../../../utils/createHtmlElement";
import { OPEN_SAUCED_INSIGHTS_DOMAIN } from "../../../constants";

export const ViewOnOpenSaucedButton = (username: string) => {
const viewOnOpenSaucedButton = createHtmlElement("a", {
id: "view-on-opensauced-button",
href: `https://${OPEN_SAUCED_INSIGHTS_DOMAIN}/user/${username}/contributions`,
className:
"inline-block mt-4 text-black bg-gh-white dark:bg-gh-gray dark:text-white rounded-md p-2 text-sm font-semibold text-center select-none w-full border hover:shadow-button hover:no-underline",
target: "_blank",
rel: "noopener noreferrer",
innerHTML: `
const viewOnOpenSaucedButton = createHtmlElement("a", {
id: "view-on-opensauced-button",
href: `https://${OPEN_SAUCED_INSIGHTS_DOMAIN}/user/${username}/contributions`,
className:
"inline-block my-4 text-black bg-gh-white dark:bg-gh-gray dark:text-white rounded-md p-2 text-sm font-semibold text-center select-none w-full border hover:shadow-button hover:no-underline",
target: "_blank",
rel: "noopener noreferrer",
innerHTML: `
<img
class="mx-2 inline-block align-top"
src="${chrome.runtime.getURL(logoIcon)}"
Expand All @@ -21,7 +21,7 @@ export const ViewOnOpenSaucedButton = (username: string) => {
/>
<span>View On OpenSauced</span>
`,
});
});

return viewOnOpenSaucedButton;
return viewOnOpenSaucedButton;
};
25 changes: 14 additions & 11 deletions src/utils/dom-utils/viewOnOpenSauced.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,24 @@
import {
GITHUB_PROFILE_USER_PROFILE_BIO_SELECTOR,
GITHUB_PROFILE_EDIT_MENU_SELECTOR,
GITHUB_PROFILE_USER_PROFILE_EDITABLE_AREA_SELECTOR,
GITHUB_PROFILE_EDIT_MENU_SELECTOR,
} from "../../constants";
import { ViewOnOpenSaucedButton } from "../../content-scripts/components/ViewOnOpenSaucedButton/ViewOnOpenSaucedButton";

const injectViewOnOpenSaucedButton = (username: string) => {
if (document.getElementById("view-on-opensauced-button")) {
return;
}
if (document.getElementById("view-on-opensauced-button")) {
return;
}

const viewOnOpenSaucedButton = ViewOnOpenSaucedButton(username);
const viewOnOpenSaucedButton = ViewOnOpenSaucedButton(username);

const userBio = document.querySelector(
`${GITHUB_PROFILE_USER_PROFILE_BIO_SELECTOR}, ${GITHUB_PROFILE_EDIT_MENU_SELECTOR}`,
);

userBio?.append(viewOnOpenSaucedButton);
const userBio = document.querySelector(
`${GITHUB_PROFILE_USER_PROFILE_EDITABLE_AREA_SELECTOR}
, ${GITHUB_PROFILE_EDIT_MENU_SELECTOR}`
);
const user = document.getElementsByClassName(
"js-profile-editable-area d-flex flex-column d-md-block"
);
user[0]?.parentNode.insertBefore(viewOnOpenSaucedButton, user[0]);
};

export default injectViewOnOpenSaucedButton;