|
| 1 | +import React, { useState } from "react"; |
| 2 | +import { Modal, Container, Row, Col, Nav, Tab } from "react-bootstrap"; |
| 3 | +import Introduction from "src/docs/en/Introduction.md"; |
| 4 | +import Tasks from "src/docs/en/Tasks.md"; |
| 5 | +import AutoTagging from "src/docs/en/AutoTagging.md"; |
| 6 | +import JSONSpec from "src/docs/en/JSONSpec.md"; |
| 7 | +import Configuration from "src/docs/en/Configuration.md"; |
| 8 | +import Interface from "src/docs/en/Interface.md"; |
| 9 | +import Galleries from "src/docs/en/Galleries.md"; |
| 10 | +import Scraping from "src/docs/en/Scraping.md"; |
| 11 | +import Contributing from "src/docs/en/Contributing.md"; |
| 12 | +import SceneFilenameParser from "src/docs/en/SceneFilenameParser.md"; |
| 13 | +import Help from "src/docs/en/Help.md"; |
| 14 | +import { Page } from "./Page"; |
| 15 | + |
| 16 | +interface IManualProps { |
| 17 | + show: boolean; |
| 18 | + onClose: () => void; |
| 19 | +} |
| 20 | + |
| 21 | +export const Manual: React.FC<IManualProps> = ({ show, onClose }) => { |
| 22 | + const content = [ |
| 23 | + { |
| 24 | + key: "Introduction.md", |
| 25 | + title: "Introduction", |
| 26 | + content: Introduction, |
| 27 | + }, |
| 28 | + { |
| 29 | + key: "Configuration.md", |
| 30 | + title: "Configuration", |
| 31 | + content: Configuration, |
| 32 | + }, |
| 33 | + { |
| 34 | + key: "Interface.md", |
| 35 | + title: "Interface", |
| 36 | + content: Interface, |
| 37 | + }, |
| 38 | + { |
| 39 | + key: "Tasks.md", |
| 40 | + title: "Tasks", |
| 41 | + content: Tasks, |
| 42 | + }, |
| 43 | + { |
| 44 | + key: "AutoTagging.md", |
| 45 | + title: "Auto Tagging", |
| 46 | + content: AutoTagging, |
| 47 | + className: "indent-1", |
| 48 | + }, |
| 49 | + { |
| 50 | + key: "SceneFilenameParser.md", |
| 51 | + title: "Scene Filename Parser", |
| 52 | + content: SceneFilenameParser, |
| 53 | + className: "indent-1", |
| 54 | + }, |
| 55 | + { |
| 56 | + key: "JSONSpec.md", |
| 57 | + title: "JSON Specification", |
| 58 | + content: JSONSpec, |
| 59 | + className: "indent-1", |
| 60 | + }, |
| 61 | + { |
| 62 | + key: "Galleries.md", |
| 63 | + title: "Image Galleries", |
| 64 | + content: Galleries, |
| 65 | + }, |
| 66 | + { |
| 67 | + key: "Scraping.md", |
| 68 | + title: "Metadata Scraping", |
| 69 | + content: Scraping, |
| 70 | + }, |
| 71 | + { |
| 72 | + key: "Contributing.md", |
| 73 | + title: "Contributing", |
| 74 | + content: Contributing, |
| 75 | + }, |
| 76 | + { |
| 77 | + key: "Help.md", |
| 78 | + title: "Further Help", |
| 79 | + content: Help, |
| 80 | + }, |
| 81 | + ]; |
| 82 | + |
| 83 | + const [activeTab, setActiveTab] = useState(content[0].key); |
| 84 | + |
| 85 | + // links to other manual pages are specified as "/help/page.md" |
| 86 | + // intercept clicks to these pages and set the tab accordingly |
| 87 | + function interceptLinkClick( |
| 88 | + event: React.MouseEvent<HTMLDivElement, MouseEvent> |
| 89 | + ) { |
| 90 | + if (event.target instanceof HTMLAnchorElement) { |
| 91 | + const href = (event.target as HTMLAnchorElement).getAttribute("href"); |
| 92 | + if (href && href.startsWith("/help")) { |
| 93 | + const newKey = (event.target as HTMLAnchorElement).pathname.substring( |
| 94 | + "/help/".length |
| 95 | + ); |
| 96 | + setActiveTab(newKey); |
| 97 | + event.preventDefault(); |
| 98 | + } |
| 99 | + } |
| 100 | + } |
| 101 | + |
| 102 | + return ( |
| 103 | + <Modal |
| 104 | + show={show} |
| 105 | + onHide={onClose} |
| 106 | + dialogClassName="modal-dialog-scrollable manual modal-xl" |
| 107 | + > |
| 108 | + <Modal.Header closeButton> |
| 109 | + <Modal.Title>Help</Modal.Title> |
| 110 | + </Modal.Header> |
| 111 | + <Modal.Body> |
| 112 | + <Container className="manual-container"> |
| 113 | + <Tab.Container |
| 114 | + activeKey={activeTab} |
| 115 | + onSelect={(k) => setActiveTab(k)} |
| 116 | + id="manual-tabs" |
| 117 | + > |
| 118 | + <Row> |
| 119 | + <Col lg={3} className="mb-3 mb-lg-0"> |
| 120 | + <Nav variant="pills" className="flex-column"> |
| 121 | + {content.map((c) => { |
| 122 | + return ( |
| 123 | + <Nav.Item> |
| 124 | + <Nav.Link className={c.className} eventKey={c.key}> |
| 125 | + {c.title} |
| 126 | + </Nav.Link> |
| 127 | + </Nav.Item> |
| 128 | + ); |
| 129 | + })} |
| 130 | + <hr className="d-sm-none" /> |
| 131 | + </Nav> |
| 132 | + </Col> |
| 133 | + <Col lg={9} className="manual-content"> |
| 134 | + <Tab.Content> |
| 135 | + {content.map((c) => { |
| 136 | + return ( |
| 137 | + <Tab.Pane eventKey={c.key} onClick={interceptLinkClick}> |
| 138 | + <Page page={c.content} /> |
| 139 | + </Tab.Pane> |
| 140 | + ); |
| 141 | + })} |
| 142 | + </Tab.Content> |
| 143 | + </Col> |
| 144 | + </Row> |
| 145 | + </Tab.Container> |
| 146 | + </Container> |
| 147 | + </Modal.Body> |
| 148 | + </Modal> |
| 149 | + ); |
| 150 | +}; |
0 commit comments