aboutsummaryrefslogtreecommitdiffhomepage
path: root/app/src/App.js
diff options
context:
space:
mode:
authorNick Coutsos <[email protected]>2022-04-28 20:02:37 -0400
committerNick Coutsos <[email protected]>2022-04-28 20:02:37 -0400
commitc2ffb689657873abf16391b9709ee2c5ef3bc897 (patch)
tree5c6bc2681785d583aef9e8cb67def414ff2585a5 /app/src/App.js
parent1f0054b75f2b945c31ef4f96b67419821a01e4f1 (diff)
downloadkeymap-editor-c2ffb689657873abf16391b9709ee2c5ef3bc897.tar.gz
keymap-editor-c2ffb689657873abf16391b9709ee2c5ef3bc897.zip
Commit keymap changes
Diffstat (limited to 'app/src/App.js')
-rw-r--r--app/src/App.js58
1 files changed, 42 insertions, 16 deletions
diff --git a/app/src/App.js b/app/src/App.js
index 17a0d86..aeff2a0 100644
--- a/app/src/App.js
+++ b/app/src/App.js
@@ -11,6 +11,7 @@ import Spinner from './Common/Spinner';
import Keyboard from './Keyboard/Keyboard'
import GitHubLink from './GitHubLink'
import Loader from './Common/Loader'
+import github from './Pickers/Github/api'
function App() {
const [definitions, setDefinitions] = useState(null)
@@ -19,11 +20,38 @@ function App() {
const [sourceOther, setSourceOther] = useState(null)
const [layout, setLayout] = useState(null)
const [keymap, setKeymap] = useState(null)
- const [editingKeymap, setEditingKeymap] = useState({})
+ const [editingKeymap, setEditingKeymap] = useState(null)
const [saving, setSaving] = useState(false)
- const handleCompile = useMemo(() => {}, [])
- const handleCommitChanges = useMemo(() => {}, [])
+ function handleCompile() {
+ fetch('/keymap', {
+ method: 'POST',
+ headers: {
+ 'Content-Type': 'application/json'
+ },
+ body: JSON.stringify(editingKeymap || keymap)
+ })
+ }
+
+ const handleCommitChanges = useMemo(() => function() {
+ const { repository, branch } = sourceOther.github
+
+ ;(async function () {
+ setSaving(true)
+ await github.commitChanges(repository, branch, layout, editingKeymap)
+ setSaving(false)
+
+ setKeymap(editingKeymap)
+ setEditingKeymap(null)
+ })()
+ }, [
+ layout,
+ editingKeymap,
+ sourceOther,
+ setSaving,
+ setKeymap,
+ setEditingKeymap
+ ])
const handleKeyboardSelected = useMemo(() => function(event) {
const { source, layout, keymap, ...other } = event
@@ -60,7 +88,7 @@ function App() {
}, [setEditingKeymap])
return (
- <div className="App">
+ <>
<Loader load={initialize}>
<KeyboardPicker onSelect={handleKeyboardSelected} />
<div id="actions">
@@ -80,20 +108,18 @@ function App() {
</button>
)}
</div>
- {definitions && (
- <DefinitionsContext.Provider value={definitions}>
- {layout && keymap && (
- <Keyboard
- layout={layout}
- keymap={editingKeymap || keymap}
- onUpdate={handleUpdateKeymap}
- />
- )}
- </DefinitionsContext.Provider>
- )}
+ <DefinitionsContext.Provider value={definitions}>
+ {layout && keymap && (
+ <Keyboard
+ layout={layout}
+ keymap={editingKeymap || keymap}
+ onUpdate={handleUpdateKeymap}
+ />
+ )}
+ </DefinitionsContext.Provider>
</Loader>
<GitHubLink className="github-link" />
- </div>
+ </>
);
}