Skip to content

Commit

Permalink
Merge branch 'dev' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
szweibel committed Oct 19, 2023
2 parents fcc0018 + c427c43 commit 2796134
Show file tree
Hide file tree
Showing 7 changed files with 87 additions and 74 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export default function DrawerEditor(props) {
setIsResizing(true);
setLastDownX(e.clientX);
};

const handleMouseup = e => {
setIsResizing(false);
if (document.getElementById('iframe')) {
Expand Down Expand Up @@ -59,7 +59,7 @@ export default function DrawerEditor(props) {
document.body.style.oUserSelect = 'none';
document.body.style.userSelect = 'none';


let offsetRight =
document.body.offsetWidth - (e.clientX - document.body.offsetLeft);
let minWidth = 50;
Expand Down Expand Up @@ -110,10 +110,14 @@ export default function DrawerEditor(props) {
handleOpenClose={handleOpenClose}
runButtonNeeded={true}
{...props} />
// <Jupyter
// handleOpenClose={handleOpenClose}
// runButtonNeeded={false}
// />
)
}
else if (language === 'jupyter') {
return (
<Jupyter
handleOpenClose={handleOpenClose}
runButtonNeeded={false}
/>
)
}
else if (language === 'javascript') {
Expand Down Expand Up @@ -160,10 +164,11 @@ export default function DrawerEditor(props) {
className={'editor-button'}
onClick={handleOpenClose}
style={{
color: "#32c259",
color: "white",
}}
>
<CodeIcon />
Open Code Editor
</Button>
</div>
<Drawer
Expand All @@ -186,37 +191,38 @@ export default function DrawerEditor(props) {
}}

><div
id="dragger"
onMouseDown={event => {
handleMousedown(event);
// setIsResizing(true);
}}
onClick={event => {
event.stopPropagation();
}}
style={{
width: '5px',
cursor: 'ew-resize',
padding: '4px 0 0',
borderTop: '1px solid #ddd',
position: 'absolute',
top: 0,
left: 0,
bottom: 0,
zIndex: '100',
backgroundColor: '#f4f7f9'
}}
/>
{/* <Button
id="dragger"
onMouseDown={event => {
handleMousedown(event);
// setIsResizing(true);
}}
onClick={event => {
event.stopPropagation();
console.log('clicked')
}}
style={{
width: '5px',
cursor: 'ew-resize',
padding: '4px 0 0',
borderTop: '1px solid #ddd',
position: 'absolute',
top: 0,
left: 0,
bottom: 0,
zIndex: '100',
backgroundColor: '#f4f7f9'
}}
/>
<Button
aria-label="open drawer"
className={'editor-button'}
onClick={handleOpenClose}
style={{
color: "#32c259",
color: "white",
}}
>
<CodeIcon />
</Button> */}
<CodeIcon /> Close Code Editor
</Button>
<div className='drawer-editor'>
{whichEditor()}
</div>
Expand Down
4 changes: 2 additions & 2 deletions components/Editor/EditorTopbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export default function EditorTopbar(props) {
return (
<>
<div className="editorTopBarButtonsContainer">
<Button
{/* <Button
color="primary"
aria-label="open drawer"
onClick={props.handleOpenClose}
Expand All @@ -21,7 +21,7 @@ export default function EditorTopbar(props) {
color: "#32c259",
}}
/>
</Button>
</Button> */}
{(!spinnerNeeded && runButtonNeeded) && <Button
onClick={() => {
props.run();
Expand Down
16 changes: 12 additions & 4 deletions components/Editor/PythonEditorComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,15 +105,23 @@ matplotlib.use("module://matplotlib_pyodide.html5_canvas_backend")\n`
namespace.set("print", (s) => {
printList.push(s.toString());
});
namespace.set("input", (s) => {
var response = prompt(s);
return response;
});
// namespace.set("input", (s) => {
// var response = prompt(s);
// return response;
// });
namespace.set("log", (s) => {
console.log(s);
});
await pyodide.runPythonAsync(checkImports(code),
{ globals: namespace });
await pyodide.runPythonAsync(
`
from js import prompt
import builtins
def input(p=""):
return prompt(p)
builtins.input = input
`, { globals: namespace });
return await pyodide.runPythonAsync(code,
{ globals: namespace }
).then(result => {
Expand Down
5 changes: 4 additions & 1 deletion components/Editor/PythonREPLComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export default function PythonREPLComponent() {
from pyodide import to_js
from pyodide.console import PyodideConsole, repr_shorten, BANNER
import __main__
from js import prompt
pyconsole = PyodideConsole(__main__.__dict__)
import builtins
async def await_fut(fut):
Expand All @@ -43,6 +43,9 @@ export default function PythonREPLComponent() {
return to_js([res], depth=1)
def clear_console():
pyconsole.buffer = []
def input(p=""):
return prompt(p)
builtins.input = input
`,
{ globals: namespace }
);
Expand Down
2 changes: 0 additions & 2 deletions components/Hooks/UseWorkshopsCard.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,6 @@ export default function UseWorkshopComponent({ workshop, gitUser, gitRepo, instU
}
}, [coverimage])

console.log(parsedWorkshop)

const workshopLink = '../dynamic/?user=' + gitUser + '&repo=' + gitRepo + '&file=' + workshop.name.split('.')[0] + '&instUser=' + instUser + '&instRepo=' + instRepo;
return (
<>
Expand Down
54 changes: 26 additions & 28 deletions pages/dynamic/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ import Head from 'next/head'
import Header from '../../components/Header'
import matter from 'gray-matter'
import { useEffect, useState, Fragment } from 'react'
import { useRouter } from 'next/router'
import ConvertMarkdown from '../../components/WorkshopPieces/ConvertMarkdown'
import Frontmatter from '../../components/WorkshopPieces/Frontmatter';
import WorkshopHeader from '../../components/WorkshopPieces/WorkshopHeader'
import Footer from '../../components/Footer'
import Container from '@mui/material/Container';
import Skeleton from '@mui/material/Skeleton';
// import DrawerEditor from '../../components/Editor/DrawerEditor'
import DrawerEditorMovable from '../../components/Editor/DrawerEditorMovable'
import DrawerEditorMovable from '../../components/Editor/DrawerEditor'
import { styled } from '@mui/material/styles';
import useUploads from '../../components/Hooks/UseUploads';
import useWorkshop from '../../components/Hooks/UseWorkshop';
Expand Down Expand Up @@ -71,6 +71,8 @@ export default function WorkshopPage({
const [allUploads, setAllUploads] = useState([]);
const uploads = useUploads({ setAllUploads, gitUser, gitRepo, gitFile });

const router = useRouter();

// convert markdown to html and split into pages
const convertContenttoHTML = function (content) {
const htmlifiedContent = ConvertMarkdown(content, uploads, workshopTitle, language, setCode, setEditorOpen, setAskToRun, gitUser, gitRepo, gitFile);
Expand All @@ -82,10 +84,17 @@ export default function WorkshopPage({
return acc;
} else if (curr.type === 'h1') {
allPages.push([curr]);
// this changes from long pages to short ones
} else if (curr.type === 'h2' && currentFile.data.long_pages === 'true') {
}
else if ((curr.type === 'h2' && currentFile.data.long_pages === 'false')
|| (curr.type === 'h2' && currentFile.data.long_pages === undefined)) {
allPages.push([curr]);
} else {
}
// this changes from long pages to short ones
else if (curr.type === 'h2' && currentFile.data.long_pages === 'true') {
// pass
}
// else if (curr.type === 'h2' && currentFile.data.long_pages === 'false')
else {
allPages[allPages.length - 1].push(curr);
}
return acc;
Expand Down Expand Up @@ -120,6 +129,7 @@ export default function WorkshopPage({
setEditing(urlParams.get('edit'));
setInstUser(urlParams.get('instUser'));
setInstRepo(urlParams.get('instRepo'));
setCurrentPage(Number(urlParams.get('page')));
if (gitFile === null) {
setBuiltURL(`https://api.github.com/repos/${gitUser}/${gitRepo}/contents/${gitRepo}.md`)
}
Expand All @@ -145,6 +155,12 @@ export default function WorkshopPage({
}
}, [data])

useEffect(() => {
if (currentPage && pages.length > 0) {
setCurrentContent(pages[currentPage - 1]);
}
}, [currentPage, pages])

useEffect(() => {
if (currentFile != null && content != '') {
const frontMatterContent = Frontmatter(currentFile, setCurrentPage, setCurrentContent,
Expand Down Expand Up @@ -230,8 +246,7 @@ export default function WorkshopPage({
behavior: 'smooth'
});
const valueAsNumber = Number(value);
// CHANGE THIS
// router.push(`/dynamic/${slug[0]}/${slug[1]}/${slug[2]}/?page=${valueAsNumber}`, undefined, { shallow: true, scroll: false });
router.push(`/dynamic/?user=${gitUser}&repo=${gitRepo}&file=${gitFile}&page=${valueAsNumber}&instUser=${instUser}&instRepo=${instRepo}`, undefined, { shallow: true, scroll: false });
setCurrentPage(valueAsNumber);
setCurrentContent(pages[valueAsNumber - 1]);
}
Expand Down Expand Up @@ -268,19 +283,15 @@ export default function WorkshopPage({
props.workshopMode ? 'md' : '100vw'
}
sx={{
// position: 'relative',
// display: 'flex',
// flexDirection: 'column',
// justifyContent: 'flex-end',
marginLeft: {
md: '80px',
},
...(props.workshopMode && {
marginLeft: {
md: '100px',
},
// marginBottom: '250px',
})
}),
flexGrow: 1,
}}
>
<Head>
Expand Down Expand Up @@ -312,20 +323,7 @@ export default function WorkshopPage({
</div>
</div>
</Main>

{/* {language &&
<DrawerEditor
drawerWidth={drawerWidth}
open={editorOpen}
setEditorOpen={setEditorOpen}
text={code}
setText={setCode}
askToRun={askToRun}
setAskToRun={setAskToRun}
language={language}
allUploads={uploads}
/>} */}
{language &&
{language && props.workshopMode &&
<DrawerEditorMovable
drawerWidth={drawerWidth}
open={editorOpen}
Expand All @@ -337,7 +335,7 @@ export default function WorkshopPage({
language={language}
allUploads={uploads}
/>}
{/* {props.workshopMode && <Pagination currentPage={currentPage} pageTitles={pageTitles} handlePageChange={handlePageChange} pages={pages} />} */}
{/* {props.workshopMode && <Pagination currentPage={currentPage} pageTitles={pageTitles} handlePageChange={handlePageChange} pages={pages} />} */}
</Container>
{props.workshopMode &&
<>
Expand Down
10 changes: 5 additions & 5 deletions styles/styles.scss
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ html {
display: flex;
flex-direction: column;
justify-content: flex-end;
// flex-grow: 1;
}

h1,
Expand Down Expand Up @@ -840,13 +841,12 @@ nav.sidenav {

.editor-button-container {
/* on the far right */
position: fixed !important;
right: 0;
position: fixed;
right: 0px;
top: 100px;
margin: 10px;
height: 30px;
z-index: 100;
background-color: #000;
background-color: #24272E;
color: white;
}

.editorTopBarButtonsContainer {
Expand Down

0 comments on commit 2796134

Please sign in to comment.