Skip to content

Commit

Permalink
Add writer tool component & jsonEditor
Browse files Browse the repository at this point in the history
  • Loading branch information
rbaraffe committed Jul 2, 2020
1 parent a49103a commit e0ad586
Show file tree
Hide file tree
Showing 5 changed files with 139 additions and 0 deletions.
27 changes: 27 additions & 0 deletions components/jsonEditor.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import React from 'react';
import AceEditor from "react-ace";

const JsonEditor = ({value, onValueChange}) => {
return (
<AceEditor
placeholder="Insert your json here"
mode="json"
theme="github"
name="blah2"
fontSize={12}
showPrintMargin={true}
showGutter={true}
onChange={onValueChange}
highlightActiveLine={true}
value={value}
setOptions={{
enableBasicAutocompletion: false,
enableLiveAutocompletion: false,
enableSnippets: false,
showLineNumbers: true,
tabSize: 2,
}}/>
)
}

export default JsonEditor
76 changes: 76 additions & 0 deletions components/writer.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
import React, { useState } from 'react';
import { Button } from 'antd';
import JsonEditor from './jsonEditor.jsx'

const Writer = () => {
const [state, setState] = useState({
jsonEditorValue: `
{
"sheets": [
{
"name":"Test",
"orientation":"OrientationLandscape",
"items": [
{
"mode":"table",
"starting_cell_coordinates":"C05",
"tables": [
{
"orientation":"column",
"cells": [
{
"value":"avril",
"style":{}
},
{
"value":"Mai",
"style":{}
}
]
}
]
}
]
}
]
}`,
});

const SendJson = () => {
fetch('http://localhost:7900/api/v1/write', {
method: 'POST',
headers: {
'Accept': 'application/json',
'Content-Type':'application/json'
},
body: state.jsonEditorValue
})
.then((res) => res.blob())
.then((blob) => {
const url = window.URL.createObjectURL(new Blob([blob]));
const link = document.createElement('a');
link.href = url;
link.setAttribute('download', `jsonToExcel.xlsx`);
document.body.appendChild(link);
link.click();
link.parentNode.removeChild(link);
})
}

return (
<div>
<JsonEditor
value={state.jsonEditorValue}
onValueChange={(e) => setState({ jsonEditorValue: e })}
/>
<Button
type="primary"
value={state.jsonEditorValue}
onClick={() => SendJson()}>
Send Json
</Button>
</div>
)
}

export default Writer;
32 changes: 32 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@
"@ant-design/dark-theme": "^2.0.1",
"@ant-design/icons": "^4.1.0",
"@zeit/next-less": "^1.0.1",
"ace-builds": "^1.4.11",
"antd": "^4.2.4",
"next": "9.3.6",
"prop-types": "^15.7.2",
"react": "16.13.1",
"react-ace": "^9.1.1",
"react-app-rewire-antd-theme": "^1.1.4",
"react-dom": "16.13.1",
"styled-components": "^5.1.0",
Expand Down
2 changes: 2 additions & 0 deletions pages/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Button, Col, Layout, Row, Typography } from 'antd';
import { ArrowDownOutlined } from '@ant-design/icons';
import Navbar from '../components/navbar.jsx';
import Converter from '../components/converter.jsx';
import Writer from '../components/writer.jsx';
import Footer from '../components/footer.jsx';
import PageHead from '../components/_shared/pageHead.jsx';
import '../styles/index.scss';
Expand Down Expand Up @@ -34,6 +35,7 @@ export default function Home() {
</Layout>
<Wave />
<h2 id="tools">Tools</h2>
<Writer />
<Converter />
</Content>
<Footer />
Expand Down

1 comment on commit e0ad586

@vercel
Copy link

@vercel vercel bot commented on e0ad586 Jul 2, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Failed to assign a domain to your deployment due to the following error:

Alias could not get assigned.

(Learn more or visit the non-aliased deployment)

Please sign in to comment.