From 776addc5b0060c745b6e82a92c85b7f37f1026df Mon Sep 17 00:00:00 2001 From: Danny Wahl Date: Fri, 23 Feb 2024 08:45:14 -0700 Subject: [PATCH] make markdown editable --- isp-site/src/routes/mdui.jsx | 49 +++++++++++++++++------- isp-site/src/strings/mdui.js | 12 ++++++ isp-site/src/variables/markdownSample.md | 3 ++ 3 files changed, 50 insertions(+), 14 deletions(-) diff --git a/isp-site/src/routes/mdui.jsx b/isp-site/src/routes/mdui.jsx index e8e75732..41ff6569 100644 --- a/isp-site/src/routes/mdui.jsx +++ b/isp-site/src/routes/mdui.jsx @@ -18,6 +18,7 @@ import { Table, Checkbox, Grid, + Alert, } from "@instructure/ui"; import { useParams } from "react-router-dom"; import { getStrings, getLang } from "utils/langs"; @@ -35,26 +36,39 @@ export default function MDUI() { const l = getLang(useParams().language); const s = getStrings(strings, l); const md = markdownSample; + let init = true; - const [content, setContent] = useState(s.loading); + const [content, setContent] = useState(`${s.loading}`); - useEffect(() => { - fetch(md) - .then((response) => { - if (response.ok) return response.text(); - return Promise.reject(s.fetch_fail); - }) - .then((text) => { - setContent(text); - }) - .catch((error) => console.error(error)); - }, [md, s.fetch_fail]); + useEffect( + (text) => { + if (init) { + init = false; + const getMD = async () => { + await fetch(md) + .then((response) => { + if (response.ok) return response.text(); + return Promise.reject(s.fetch_fail); + }) + .then((text) => { + setContent(text); + }) + .catch((error) => console.error(error)); + }; + getMD(); + return; + } + setContent(text); + }, + [md, init, s.fetch_fail], + ); return ( <> + + {s.try_editor} + { - this.setState({ value }); + setContent(value); }} /> diff --git a/isp-site/src/strings/mdui.js b/isp-site/src/strings/mdui.js index 79cf1513..b9b79f71 100644 --- a/isp-site/src/strings/mdui.js +++ b/isp-site/src/strings/mdui.js @@ -17,5 +17,17 @@ const strings = { PT_BR: "Fonte de Markdown", DE: "Markdown-Quelle", }, + try_editor: { + EN: "Try editing the markdown below.", + ES_LA: "Intenta editar el markdown abajo.", + PT_BR: "Tente editar o markdown abaixo.", + DE: "Versuche den Markdown unten zu bearbeiten.", + }, + close: { + EN: "Close", + ES_LA: "Cerrar", + PT_BR: "Fechar", + DE: "Schließen", + }, }; export default strings; diff --git a/isp-site/src/variables/markdownSample.md b/isp-site/src/variables/markdownSample.md index 3bf8c130..fa7a5a47 100644 --- a/isp-site/src/variables/markdownSample.md +++ b/isp-site/src/variables/markdownSample.md @@ -2,6 +2,8 @@ This page is rendered from [github-flavored markdown](https://docs.github.com/en/get-started/writing-on-github/getting-started-with-writing-and-formatting-on-github/basic-writing-and-formatting-syntax) and passing the content through [react-markdown](https://github.com/remarkjs/react-markdown) to [Instructure UI](https://instructure.design/). The result is accessible, well styled, and modular content created simply with markdown. +
+ ## Tables ### Normal table @@ -19,6 +21,7 @@ This page is rendered from [github-flavored markdown](https://docs.github.com/en | `git diff` | Show file differences that **haven't been** staged | ### Table with columnar alignment + | Left-aligned | Center-aligned | Right-aligned | | :--- | :---: | ---: | | git status | git status | git status |