-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
702ea9c
commit a30a17c
Showing
9 changed files
with
137 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import React from "react" | ||
import { marked } from "marked" | ||
|
||
const Markdown = ({ children }) => { | ||
console.log("[Markdown] render") | ||
// remove the most common zerowidth characters from the start of the file | ||
const content = marked.parse(String(children)) | ||
|
||
return <div dangerouslySetInnerHTML={{ __html: content }} /> | ||
} | ||
|
||
export default Markdown |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
@media (min-width: 576px) { | ||
.ModalTutorial .modal-dialog { | ||
max-width: var(--bs-modal-width); | ||
} | ||
} | ||
|
||
@media (min-width: 768px) { | ||
.ModalTutorial .modal-dialog { | ||
max-width: var(--bs-modal-lg); | ||
} | ||
} | ||
|
||
.ModalTutorial iframe { | ||
width: 100% !important; | ||
height: 100% !important; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
import React from "react" | ||
import ModalView from "./ModalView" | ||
import { ModalTutorialView, useBrowserStore, useDataStore } from "../store" | ||
import { Badge, Col, Modal, Row } from "react-bootstrap" | ||
import { useQuery } from "@tanstack/react-query" | ||
import axios from "axios" | ||
import Markdown from "./Markdown" | ||
import "./ModalTutorial.css" | ||
const ModalTutorial = ({ onClose, ...props }) => { | ||
const getTutorialByName = useDataStore((state) => state.getTutorialByName) | ||
const name = useBrowserStore((state) => state.viewId) | ||
const tutorial = getTutorialByName(name) | ||
const url = `${ | ||
process.env.GATSBY_PATH_PREFIX || "" | ||
}/data/tutorials/${name}.json` | ||
const ratio = tutorial | ||
? tutorial.video.thumbnail_height / tutorial.video.thumbnail_width | ||
: 1.0 | ||
|
||
const { status, data } = useQuery({ | ||
queryKey: ["notebooks-", name], | ||
queryFn: () => | ||
axios.get(url).then((res) => { | ||
return res.data | ||
}), | ||
}) | ||
|
||
console.info(`[ModalTutorial] ${name} ${url} ${status}`) | ||
|
||
return ( | ||
<ModalView | ||
className="ModalTutorial" | ||
viewName={ModalTutorialView} | ||
onClose={onClose} | ||
{...props} | ||
> | ||
<Modal.Header | ||
className="align-items-baseline bg-light" | ||
closeButton | ||
style={{ position: "sticky", top: 0, zIndex: 1 }} | ||
> | ||
<Modal.Title id="contained-modal-title-vcenter"> | ||
<Badge>Tutorial</Badge> | ||
<br /> | ||
{tutorial?.title} | ||
</Modal.Title> | ||
</Modal.Header> | ||
<Modal.Body className="container"> | ||
<Row> | ||
<Col> | ||
<figure | ||
className="m-0 w-100 position-relative" | ||
style={{ | ||
paddingTop: `${ratio * 100}%`, | ||
}} | ||
> | ||
{status === "success" && ( | ||
<div | ||
className="position-absolute top-0 w-100 h-100" | ||
dangerouslySetInnerHTML={{ __html: data?.video?.html }} | ||
/> | ||
)} | ||
</figure> | ||
<p>In this tutorial:</p> | ||
<ol> | ||
{tutorial?.tableOfContents.items.map((d, i) => ( | ||
<li key={i}>{d.title}</li> | ||
))} | ||
</ol> | ||
</Col> | ||
<Col> | ||
{status === "error" && <div>Error fetching data</div>} | ||
{status === "loading" && <div>Loading...</div>} | ||
{status === "success" && <Markdown>{data.body}</Markdown>} | ||
</Col> | ||
</Row> | ||
</Modal.Body> | ||
</ModalView> | ||
) | ||
} | ||
export default ModalTutorial |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters