-
Notifications
You must be signed in to change notification settings - Fork 6
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
base: main
Are you sure you want to change the base?
Changes from 1 commit
3ea48ce
f696fff
b7282b3
dbe6c23
8c0ef71
71a6224
3da0c0e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,8 +6,9 @@ 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'; | ||
|
@@ -25,11 +26,27 @@ function copyGeneratedUrl(hubUrl, app) { | |
}); | ||
} | ||
|
||
function openGeneratedUrl(hubUrl, app) { | ||
const query = { active: true, currentWindow: true }; | ||
chrome.tabs.query(query, function (tabs) { | ||
const activeTab = tabs[0]; | ||
if (activeTab) { | ||
const parts = GitUrlParse(activeTab.url); | ||
const repoUrl = `${parts.protocol}://${parts.source}/${parts.full_name}`; | ||
const my_url = generateRegularUrl(hubUrl, repoUrl, parts.ref, app, parts.name + '/' + parts.filepath); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. variables should be camelCase, so There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I also see that this is mostly duplicating the code in
|
||
navigator.clipboard.writeText(my_url); | ||
chrome.tabs.create({ url: my_url }); | ||
} | ||
}); | ||
} | ||
|
||
function Form() { | ||
const [hubUrl, setHubUrl] = useState(getPref('hub-url', '')); | ||
const [app, setApp] = useState(getPref('app', 'classic')); | ||
const [isValidHubUrl, setIsValidHubUrl] = useState(false); | ||
const [finishedCopying, setFinishedCopying] = useState(false); | ||
const [isDropdownOpen, setDropdownOpen] = useState(false); | ||
|
||
|
||
useEffect(() => { | ||
try { | ||
|
@@ -49,27 +66,81 @@ function Form() { | |
setPref('app', app); | ||
}, [app]) | ||
|
||
const menuItems = Object.entries(AVAILABLE_APPS).map(([name, value]) => ({ | ||
text: value.title, | ||
key: name | ||
})); | ||
|
||
const handleMenuChange = (item) => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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").style.height="190px"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd prefer we use something like CSS classes here, rather than directly setting CSS properties in JS. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If this becomes small after moving these to a css class toggle, this function can also be inline. |
||
document.getElementById("popoutBody").style.height="190px"; | ||
setDropdownOpen(false); | ||
} else { | ||
document.getElementById("root").style.height="340px"; | ||
document.getElementById("popoutBody").style.height="340px"; | ||
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}> | ||
<Heading sx={{ fontSize: 2, mb: 1, mt: 3 }}>Open in</Heading> | ||
{/* <select className="form-select mb-1" onChange={(ev) => setApp(ev.target.value)} value={app}> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should this be deleted? |
||
{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> | ||
</select> */} | ||
|
||
<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={() => { | ||
openGeneratedUrl(hubUrl, app); | ||
}}> | ||
<TabExternalIcon /> Open in tab | ||
</Button> | ||
|
||
<Button disabled={!isValidHubUrl || finishedCopying} | ||
style={{ flexGrow: 1, backgroundColor: '#52c786', opacity: ((!isValidHubUrl || finishedCopying)?0.6:1), marginTop: '8px' }} | ||
// sx={{ mt: 2, bg: "MediumSeaGreen" }} | ||
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> | ||
|
||
</div> | ||
|
||
</Box> | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,10 @@ | ||
<html> | ||
<html style="height: fit-content;"> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should be a CSS class. |
||
<head> | ||
<title>NBGitPuller</title> | ||
</head> | ||
<body> | ||
<div id="root" style="width:320px; height:200px;"></div> | ||
<body id="popoutBody"> | ||
<div id="root" style="width:370px; height:190px;"></div> | ||
<!-- <div id="root" style="width:320px; height:200px;"></div> --> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's remove these too? |
||
<script src="bundle.js"></script> | ||
</body> | ||
</html> |
There was a problem hiding this comment.
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 :)
There was a problem hiding this comment.
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?