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

Popout changes #7

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 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
10 changes: 10 additions & 0 deletions src/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,13 @@ chrome.tabs.onUpdated.addListener((tabId, changeInfo, tab) => {
chrome.action.setPopup({ tabId, popup: "popup_disabled.html" });
};
});

chrome.runtime.onInstalled.addListener(function (object) {
Copy link
Owner

Choose a reason for hiding this comment

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

Can this be a page on this repository instead? Chrome and firefox both review URLs used in here, and I think they may not be happy with this one :)

Copy link
Owner

Choose a reason for hiding this comment

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

Google Docs is definitely better than notion! However, can you copy the contents into a markdown file in this repository (as part of this PR), and link to that instead?

let externalUrl = "https://docs.google.com/document/d/e/2PACX-1vTGWZQmI-GhKJ2GP0c4wAGhVf5bMPDdbXzNJnYGOYKbxjCNSRxtAEvvmlHafs6oln44MFCH8aW_6uIC/pub";

if (object.reason === chrome.runtime.OnInstalledReason.INSTALL) {
chrome.tabs.create({ url: externalUrl }, function (tab) {

});
}
});
94 changes: 75 additions & 19 deletions src/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@ import GitUrlParse from 'git-url-parse';

import { useState } from 'react';

import { Button, Box, Text, Popover, Heading, ThemeProvider, TextInput } from '@primer/components';
import { CopyIcon } from '@primer/octicons-react';
import { Button, Box, Text, Popover, Heading, ThemeProvider, TextInput, SelectMenu, DropdownMenu, DropdownButton } from '@primer/components';

import { CopyIcon, TabExternalIcon } from '@primer/octicons-react';

import { AVAILABLE_APPS, generateRegularUrl } from './generator';
import { getPref, setPref } from './prefs';

function copyGeneratedUrl(hubUrl, app) {
function copyGeneratedUrl(hubUrl, app, open) {
ranashreyas marked this conversation as resolved.
Show resolved Hide resolved
const query = { active: true, currentWindow: true };
chrome.tabs.query(query, function (tabs) {
const activeTab = tabs[0];
Expand All @@ -21,6 +22,9 @@ function copyGeneratedUrl(hubUrl, app) {
const repoUrl = `${parts.protocol}://${parts.source}/${parts.full_name}`;
const url = generateRegularUrl(hubUrl, repoUrl, parts.ref, app, parts.name + '/' + parts.filepath);
navigator.clipboard.writeText(url);
if (open) {
chrome.tabs.create({url: url});
}
}
});
}
Expand All @@ -30,6 +34,8 @@ function Form() {
const [app, setApp] = useState(getPref('app', 'classic'));
const [isValidHubUrl, setIsValidHubUrl] = useState(false);
const [finishedCopying, setFinishedCopying] = useState(false);
const [isDropdownOpen, setDropdownOpen] = useState(false);


useEffect(() => {
try {
Expand All @@ -49,27 +55,77 @@ function Form() {
setPref('app', app);
}, [app])

const menuItems = Object.entries(AVAILABLE_APPS).map(([name, value]) => ({
text: value.title,
key: name
}));

const handleMenuChange = (item) => {
Copy link
Owner

Choose a reason for hiding this comment

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

Given this is so small, I think this can just be inline.

if (item) {
setApp(item.key);
}
};

const changeOpenState = (item) => {
if(isDropdownOpen == true){
document.getElementById("root").className = "normal";
ranashreyas marked this conversation as resolved.
Show resolved Hide resolved
document.getElementById("popoutBody").className = "normal";
setDropdownOpen(false);
} else {
document.getElementById("root").className = "expanded";
document.getElementById("popoutBody").className = "expanded";
setDropdownOpen(true);
}

};

return <Box display="flex" flexDirection="column">
{/* https://datahub.berkeley.edu */}
ranashreyas marked this conversation as resolved.
Show resolved Hide resolved
<Heading sx={{ fontSize: 2, mb: 1 }}>JupyterHub URL</Heading>

<TextInput value={hubUrl} onChange={(ev) => setHubUrl(ev.target.value)} placeholder="https://myjupyterhub.org" aria-label="JupyterHub URL" />
<TextInput
value={hubUrl}
onChange = {
(ev) => setHubUrl(ev.target.value)
}
placeholder="https://myjupyterhub.org"
aria-label="JupyterHub URL"
sx={{ pt: 0.5, pb: 0.5 }}
/>

<Text color="danger.fg" sx={{ visibility: isValidHubUrl ? "hidden" : "visible" }}>Enter a valid URL</Text>

<Heading sx={{ fontSize: 2, mb: 1, mt: 2 }}>Open in</Heading>
<select className="form-select mb-1" onChange={(ev) => setApp(ev.target.value)} value={app}>
{Object.entries(AVAILABLE_APPS).map(([name, value]) => {
return <option key={name} value={name}>{value.title}</option>
})};
</select>

<Button disabled={!isValidHubUrl || finishedCopying} sx={{ mt: 2 }} onClick={() => {
copyGeneratedUrl(hubUrl, app);
// Flash a 'Copied!' message for 3 seconds after copying
setFinishedCopying(true);
setTimeout(() => setFinishedCopying(false), 3 * 1000)
}}>
<CopyIcon /> {finishedCopying ? "Copied!" : "Copy nbgitpuller link"}
</Button>
<Heading sx={{ fontSize: 2, mb: 1, mt: 3 }}>Open in</Heading>

<DropdownMenu
ranashreyas marked this conversation as resolved.
Show resolved Hide resolved
items={menuItems}
onChange={handleMenuChange}
placeholder={AVAILABLE_APPS[app].title} // Display the value of 'name' or a placeholder
open={isDropdownOpen}
onOpenChange={changeOpenState}
/>

<div style={{ display: 'flex', gap: '8px', justifyContent: 'center' }}>
ranashreyas marked this conversation as resolved.
Show resolved Hide resolved

<Button disabled={!isValidHubUrl || finishedCopying} sx={{ mt: 2}} onClick={() => {
copyGeneratedUrl(hubUrl, app, true);
}}>
<TabExternalIcon /> Open in tab
</Button>

<Button disabled={!isValidHubUrl || finishedCopying}
style={{ flexGrow: 1, backgroundColor: '#52c786', opacity: ((!isValidHubUrl || finishedCopying)?0.6:1), marginTop: '8px' }}
ranashreyas marked this conversation as resolved.
Show resolved Hide resolved
onClick={() => {
copyGeneratedUrl(hubUrl, app, false);
// Flash a 'Copied!' message for 3 seconds after copying
setFinishedCopying(true);
setTimeout(() => setFinishedCopying(false), 3 * 1000)
}}>
<CopyIcon /> {finishedCopying ? "Copied!" : "Copy nbgitpuller link"}
</Button>

</div>

</Box>
}

Expand Down
22 changes: 20 additions & 2 deletions src/popup.html
Original file line number Diff line number Diff line change
@@ -1,9 +1,27 @@
<html>
<head>
<title>NBGitPuller</title>
<style>
html {
height: fit-content;
}

#root {
width:370px;
height:190px;
}

.normal{
height: 190px;
}

.expanded {
height: 340px;
}
</style>
</head>
<body>
<div id="root" style="width:320px; height:200px;"></div>
<body id="popoutBody" class="normal">
<div id="root" class="normal"></div>
<script src="bundle.js"></script>
</body>
</html>
22 changes: 20 additions & 2 deletions src/popup_disabled.html
Original file line number Diff line number Diff line change
@@ -1,9 +1,27 @@
<html>
<html style="height: fit-content;">
<head>
<title>NBGitPuller</title>
<style>
html {
height: fit-content;
}

#root {
width:370px;
height:190px;
}

.normal{
height: "190px";
}

.expanded {
height: "340px";
}
</style>
</head>
<body>
<div id="root" style="width:320px; height:200px;">
<div id="root">
This extension is disabled for this page.
Please navigate to a GitHub URL to use this extension.
</div>
Expand Down