From 8ece71bad2b673f66ddcfc5c2506230fa86f6253 Mon Sep 17 00:00:00 2001 From: Mathew Varughese Date: Wed, 13 Jul 2022 12:26:41 -0700 Subject: [PATCH 1/3] update --- components/Document.js | 40 +- components/EditPagePanel.js | 61 +- package-lock.json | 3987 ++--------------------------------- package.json | 2 + pages/_app.js | 13 +- pages/api/create-pr.js | 61 + 6 files changed, 317 insertions(+), 3847 deletions(-) create mode 100644 pages/api/create-pr.js diff --git a/components/Document.js b/components/Document.js index a893528d..cc70c89e 100644 --- a/components/Document.js +++ b/components/Document.js @@ -7,13 +7,49 @@ function EditPage({ source: initialDocument }) { const [doc, setDoc] = React.useState(initialDocument); const { content, config, errors } = useMarkdocCode(doc); + const [docChanged, setDocChanged] = React.useState(false); + + const [prNumber, setPrNumber] = React.useState(null); + + const createPR = async () => { + const filename = window.CURRENT_FILENAME; + + const files = { + [filename]: doc + }; + + console.log(files); + + const body = JSON.stringify({ files }); + + const response = await fetch('/api/create-pr', { + method: 'POST', + headers: { + 'Content-Type': 'application/json' + }, + body + }); + + const prNumber = await response.json(); + setPrNumber(prNumber); + + return prNumber; + }; + return ( <> {Markdoc.renderers.react(content.children, React, { components: config.components })} - - + + { + setDocChanged(true); + setDoc(...args); + }} + errors={errors} + /> ); diff --git a/components/EditPagePanel.js b/components/EditPagePanel.js index 3c65c6cd..000afb16 100644 --- a/components/EditPagePanel.js +++ b/components/EditPagePanel.js @@ -3,7 +3,64 @@ import React from 'react'; const PATTERN = Buffer.from('NDI0Mg==', 'base64').toString(); const WIDTH = 55; -export function EditPagePanel({ children }) { +function CreatePRButton({ createPR }) { + const [prNumber, setPrNumber] = React.useState(null); + const [loading, setLoading] = React.useState(false); + + if (prNumber) { + return ( +
+ Thank you for contributing! View your PR{' '} + here + +
+ ); + } + + return ( +
+ + +
+ ); +} + +export function EditPagePanel({ docChanged, children, createPR }) { const [showEditor, setShowEditor] = React.useState(false); const [mouseOver, setMouseOver] = React.useState(false); const [keystrokes, setCount] = React.useState(0); @@ -71,6 +128,7 @@ export function EditPagePanel({ children }) { + {docChanged && } - - ); - } - return (