-
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.
42 add an upload button to the UI (#64)
* frontend looks good, pending correct upload functionality * add upload string for issue * test upload function * remove effect import * redirect client and remove bad react import * remove bad url prop * attempt DS resolutions for JS-0417 * add comment to satisfy DS * make header a link to / * use href instead * make const not function * Trigger CICD * add comment * remove usage files * add a status to the submit button
- Loading branch information
1 parent
665a829
commit 6e4a08d
Showing
8 changed files
with
1,327 additions
and
2,933 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
Large diffs are not rendered by default.
Oops, something went wrong.
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 was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,34 +1,31 @@ | ||
import React, { useEffect } from 'react'; | ||
import React from 'react'; | ||
import { Helmet } from 'react-helmet'; | ||
import { BrowserRouter as Router, Route, Routes } from 'react-router-dom'; | ||
import { loadUsage } from './usage'; | ||
import Upload from './upload'; | ||
import Footer from './footer'; | ||
import Paste from './paste'; | ||
|
||
const SITE_NAME = process.env.REACT_APP_SITE_NAME; | ||
|
||
function App() { | ||
useEffect(() => { | ||
loadUsage(); | ||
}, []); | ||
|
||
return ( | ||
<Router> | ||
<Helmet> | ||
<title>{SITE_NAME}</title> | ||
</Helmet> | ||
<div id="container"> | ||
<div id="header"> | ||
// Primary page, it loads the upload or paste function based on the URL | ||
const App = () => ( | ||
<Router> | ||
<Helmet> | ||
<title>{SITE_NAME}</title> | ||
</Helmet> | ||
<div id="container"> | ||
<div id="header"> | ||
<a href="/" style={{ textDecoration: 'none', color: 'inherit' }}> | ||
<h1 id="site_name">{SITE_NAME}</h1> | ||
</div> | ||
<Routes> | ||
<Route path="/:uuid" element={<Paste />} /> | ||
<Route path="/" element={<div id="usage">Loading...</div>} /> | ||
</Routes> | ||
<Footer /> | ||
</a> | ||
</div> | ||
</Router> | ||
); | ||
}; | ||
<Routes> | ||
<Route path="/:uuid" element={<Paste />} /> | ||
<Route path="/" element={<Upload />} /> | ||
</Routes> | ||
<Footer /> | ||
</div> | ||
</Router> | ||
); | ||
|
||
export default App; | ||
export default App; |
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,53 @@ | ||
import { useState, useCallback } from 'react'; | ||
import axios from 'axios'; | ||
|
||
// Upload function that creates a text box for user input then uploads that content as a blob with markdown mimetype to the API. It redirects the user to the uploaded blob after the API returns a URL | ||
const Upload = () => { | ||
const [content, setContent] = useState(''); | ||
const [isUploading, setIsUploading] = useState(false); | ||
|
||
const handleChange = useCallback((e) => { | ||
setContent(e.target.value); | ||
}, []); | ||
|
||
const upload = useCallback(async (e) => { | ||
e.preventDefault(); | ||
setIsUploading(true); | ||
try { | ||
// Create a Blob with the markdown content and the correct MIME type | ||
const blob = new Blob([content], { type: 'text/markdown' }); | ||
|
||
// Send the blob directly with the correct Content-Type header | ||
const response = await axios.put('/api/upload', blob, { | ||
headers: { | ||
'Content-Type': 'text/markdown', | ||
}, | ||
}); | ||
|
||
// Redirect to the URL returned by the API | ||
window.location.href = response.data; | ||
} catch (error) { | ||
console.error('Error uploading file:', error); | ||
setIsUploading(false); // Re-enable button if there's an error | ||
} | ||
}, [content]); | ||
|
||
return ( | ||
<div id="uploadBlock"> | ||
<form onSubmit={upload}> | ||
<textarea | ||
className="textarea" | ||
value={content} | ||
onChange={handleChange} | ||
placeholder="Enter your markdown content here..." | ||
rows={Math.max(10, content.split('\n').length)} | ||
/> | ||
<button type="submit" disabled={isUploading}> | ||
{isUploading ? 'Uploading...' : 'Upload'} | ||
</button> | ||
</form> | ||
</div> | ||
); | ||
}; | ||
|
||
export default Upload; |
This file was deleted.
Oops, something went wrong.