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

feat: Invite to OpenSauced #20

Merged
merged 31 commits into from
Apr 21, 2023
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
9f73529
refactor: Moved matchers to a separate dir
Anush008 Apr 18, 2023
a833452
chore: Updated getOpenSaucedUser() to return a bool
Anush008 Apr 18, 2023
8269c6f
refactor: Moved injectViewOnOpenSauced to utils
Anush008 Apr 18, 2023
96c19b3
feat: Invite to OS(WIP)
Anush008 Apr 18, 2023
913a3e0
chore: Removed unused listener
Anush008 Apr 18, 2023
74bdbb7
chore: Fomatting
Anush008 Apr 18, 2023
46e2393
chore: Fomatting
Anush008 Apr 18, 2023
2f93509
chore: Added social icons span
Anush008 Apr 18, 2023
c9fef90
chore: Removed explicit book return and err handling
Anush008 Apr 19, 2023
a1bfa7b
Update src/components/InviteToOpenSauced/InviteToOpenSaucedModal.ts
Anush008 Apr 19, 2023
67efb60
chore: Top level await for getOpenSaucedUser()
Anush008 Apr 19, 2023
c7c72ef
chores: Aggregated matchers, updated file-names
Anush008 Apr 19, 2023
0350a97
chore: createHtmlElement() with added typings
Anush008 Apr 19, 2023
40a45ee
chore: Updated elements to use the new createHtmlElement()
Anush008 Apr 19, 2023
9c138ae
refactor: restructured utilities
Anush008 Apr 19, 2023
ddba946
chore: remove config imports for now
Anush008 Apr 19, 2023
817a4a5
chore: Improved typing in createHtmlElement() and formatting
Anush008 Apr 19, 2023
6ac449b
chore: Added conditional rendering of social share icons
Anush008 Apr 19, 2023
c96682a
Merge branch 'main' into invite-to-opensauced
Anush008 Apr 20, 2023
e792985
chore: updated injector functions for empty bio
Anush008 Apr 20, 2023
275bba3
chore: Updated button-text sizing
Anush008 Apr 20, 2023
3b06d3c
chore: Updated LinkedIn share button href
Anush008 Apr 20, 2023
9612f4e
chore: updated null checks
Anush008 Apr 20, 2023
6d0c1e6
chore: Updated inviteToOS button colors
Anush008 Apr 20, 2023
4d566a5
chore: Update LinkedIn username matcher and modal sizing
Anush008 Apr 20, 2023
4ebfe46
Apply copy suggestions from code review
bdougie Apr 20, 2023
f1f8128
Apply injectViewOnOS rename suggestions from code review
bdougie Apr 20, 2023
9e156f1
refactor: renamedViewOnOpenSauced()
Anush008 Apr 21, 2023
6066c99
refactor: updated matcher file name and imports
Anush008 Apr 21, 2023
7a91203
refactor: Moved the modal display trigger to the component definition
Anush008 Apr 21, 2023
b303f2b
chore: update matchers filename to urlMatchers
Anush008 Apr 21, 2023
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
21 changes: 21 additions & 0 deletions src/components/InviteToOpenSauced/InviteToOpenSaucedButton.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import logoIcon from "../../assets/opensauced-icon.svg";
import "../../index.css";

export const InviteToOpenSaucedButton = () => {
const inviteToOpenSaucedButton = document.createElement("a");
Object.assign(inviteToOpenSaucedButton, {
Anush008 marked this conversation as resolved.
Show resolved Hide resolved
className:
"inline-block mt-4 mb-1 text-white rounded-md p-2 no-underline text-md font-semibold text-center select-none w-full border border-solid cursor-pointer border-orange hover:shadow-button hover:no-underline",
innerHTML: `
<img
class="mx-2 inline-block align-top"
src="${chrome.runtime.getURL(logoIcon)}"
alt="OpenSauced Logo"
width="20"
height="20"
/>
<span>Invite to OpenSauced</span>
`,
});
return inviteToOpenSaucedButton;
};
46 changes: 46 additions & 0 deletions src/components/InviteToOpenSauced/InviteToOpenSaucedModal.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import "../../index.css";

interface Socials {
emailAddress?: string;
twitterUsername?: string;
linkedInUsername?: string;
}

export const InviteToOpenSaucedModal = (
username: string,
{ emailAddress, twitterUsername, linkedInUsername }: Socials = {}
) => {
//TODO: Conditionally render social icons
const socialIcons = `<span class="flex flex-nowrap space-x-3"> <a href="https://github.com/bdougie">
<img src="https://images.weserv.nl/?url=cdn4.iconfinder.com/data/icons/miu-flat-social/60/mail-512.png&h=60&w=60&fit=cover&mask=circle" alt="Email">
Anush008 marked this conversation as resolved.
Show resolved Hide resolved
</a>
<a href="https://github.com/bdougie">
nickytonline marked this conversation as resolved.
Show resolved Hide resolved
<img src="https://images.weserv.nl/?url=cdn4.iconfinder.com/data/icons/social-media-icons-the-circle-set/48/twitter_circle-512.png&h=60&w=60&fit=cover&mask=circle" alt="Twitter">
</a>
<a href="https://github.com/bdougie">
<img src="https://images.weserv.nl/?url=cdn1.iconfinder.com/data/icons/logotypes/32/circle-linkedin-512.png&h=60&w=60&fit=cover&mask=circle" alt="LinkedIn">
</a>
</span>`;

const inviteToOpenSaucedModal = document.createElement("div");
Object.assign(inviteToOpenSaucedModal, {
className:
"fixed h-full w-full z-50 bg-gray-600 bg-opacity-50 overflow-y-auto inset-0 ",
style: "display: none;",
id: "invite-modal",
innerHTML: `<div
class="min-w-[30%] relative top-60 mx-auto p-4 border w-96 rounded-md shadow-button border-solid border-orange bg-slate-800"
>
<div class="mt-2 text-left">
<h3 class="text-2xl leading-6 font-bold">Invite to OpenSauced!</h3>
<div class="mt-2">
<p class="text-sm">
Use the social icons below to invite ${username} to OpenSauced.
</p>
</div>
${socialIcons}
</div>
</div>`,
});
return inviteToOpenSaucedModal;
};
32 changes: 9 additions & 23 deletions src/content-scripts/profileScreen.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,11 @@
import { getGithubUsername } from "../utils/getDetailsFromGithubUrl";
import { getGithubUsername } from "../utils/matchers";
import { getOpenSaucedUser } from "../utils/fetchOpenSaucedApiData";
import { ViewOnOpenSaucedButton } from "../components/ViewOnOpenSaucedButton/ViewOnOpenSaucedButton";

function injectViewOnOpenSaucedButton() {
const username = getGithubUsername(window.location.href);
if (!username) {
return;
}

const openSaucedUser = getOpenSaucedUser(username);
if (!openSaucedUser) {
return;
}

const viewOnOpenSaucedButton = ViewOnOpenSaucedButton(username);

const userBio = document.querySelector(".p-note.user-profile-bio");
if (!userBio) {
return;
}
userBio.appendChild(viewOnOpenSaucedButton);
import injectViewOnOpenSauced from "../utils/viewOnOpenSauced";
import injectInviteToOpenSauced from "../utils/inviteToOpenSauced";

const username = getGithubUsername(window.location.href);
if (username != null) {
const openSaucedUser = await getOpenSaucedUser(username);
if (openSaucedUser) injectViewOnOpenSauced(username);
else injectInviteToOpenSauced(username);
}

injectViewOnOpenSaucedButton();
24 changes: 16 additions & 8 deletions src/utils/fetchOpenSaucedApiData.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
export const getOpenSaucedUser = async (username: string) => {
const response = await fetch(
`https://api.opensauced.pizza/v1/users/${username}`
);
if (response.status !== 200) {
return null;
}
return await response.json();
};
try {
const response = await fetch(`https://api.opensauced.pizza/v1/users/${username}`);
return response.status === 200;
} catch (error) {
return false;
}
};









5 changes: 0 additions & 5 deletions src/utils/getDetailsFromGithubUrl.ts

This file was deleted.

40 changes: 40 additions & 0 deletions src/utils/inviteToOpenSauced.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
//import {USER_BIO_SELECTOR} from "../config.json";
import { InviteToOpenSaucedButton } from "../components/InviteToOpenSauced/InviteToOpenSaucedButton";
import { InviteToOpenSaucedModal } from "../components/InviteToOpenSauced/InviteToOpenSaucedModal";
import { getTwitterUsername } from "./matchers";
Anush008 marked this conversation as resolved.
Show resolved Hide resolved
import { getLinkedInUsername } from "./matchers";

const injectViewOnOS = (username: string) => {
const emailAddress: string | undefined = (
document.querySelector(`a[href^="mailto:"]`) as HTMLAnchorElement
)?.href.substr(7);
const twitterUrl: string | undefined = (
document.querySelector(`a[href*="twitter.com"]`) as HTMLAnchorElement
)?.href;
const linkedInUrl: string | undefined = (
document.querySelector(`a[href*="linkedin.com"]`) as HTMLAnchorElement
)?.href;
console.log(linkedInUrl);
if (!(emailAddress || twitterUrl || linkedInUrl)) return;

const twitterUsername = twitterUrl && getTwitterUsername(twitterUrl);
const linkedInUsername = linkedInUrl && getLinkedInUsername(linkedInUrl);
const inviteToOpenSaucedButton = InviteToOpenSaucedButton();
const inviteToOpenSaucedModal = InviteToOpenSaucedModal(username, {
emailAddress,
twitterUsername,
linkedInUsername,
});

inviteToOpenSaucedButton.onclick = () => {
inviteToOpenSaucedModal.style.display = "block";
};

const userBio = document.querySelector(".p-note.user-profile-bio");
if (!userBio) return;

userBio.appendChild(inviteToOpenSaucedButton);
document.body.appendChild(inviteToOpenSaucedModal);
};

export default injectViewOnOS;
18 changes: 18 additions & 0 deletions src/utils/matchers.ts
diivi marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
export const getGithubUsername = (url: string) => {
const match = url.match(/github\.com\/([^/]+)/);
return match && match[1];
};

export const getLinkedInUsername = (url: string) => {
const match = url.match(
/https:\/\/www\.linkedin\.com\/in\/(?<username>[a-zA-Z0-9]{3,100})\/?/
);
return match ? match[1] : undefined;
};

export const getTwitterUsername = (url: string) => {
const match = url.match(
/(?:https?:\/\/)?(?:www\.)?twitter\.com\/(?:#!\/)?@?([^\/\?\s]*)/
);
return match ? match[1] : undefined;
};
12 changes: 12 additions & 0 deletions src/utils/viewOnOpenSauced.ts
Anush008 marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { ViewOnOpenSaucedButton } from "../components/ViewOnOpenSaucedButton/ViewOnOpenSaucedButton";

const injectViewOnOpenSauced = (username: string) => {
const viewOnOpenSaucedButton = ViewOnOpenSaucedButton(username);

const userBio = document.querySelector(".p-note.user-profile-bio");
if (!userBio) return;

userBio.appendChild(viewOnOpenSaucedButton);
};

export default injectViewOnOpenSauced;