-
-
Notifications
You must be signed in to change notification settings - Fork 187
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Code Editor For Local Configurations (#8)
- Loading branch information
Showing
22 changed files
with
389 additions
and
169 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
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
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,77 @@ | ||
import React, { useEffect, useState, useRef } from "react" | ||
import AceEditor from "react-ace" | ||
import "ace-builds/src-noconflict/mode-json" | ||
import "one-theme-ace/one-dark" | ||
import { useSettings } from "@/context/settings" | ||
|
||
const Editor = () => { | ||
const editor = useRef(null) | ||
const [hasError, setError] = useState(false) | ||
const { settings, setSettings } = useSettings() | ||
|
||
useEffect(() => { | ||
editor.current.editor.session.foldAll( | ||
1, | ||
editor.current.editor.session.doc.getAllLines().length | ||
) | ||
}, []) | ||
|
||
function onChange(changes) { | ||
try { | ||
JSON.parse(changes) | ||
setError(false) | ||
} catch (e) { | ||
setError(true) | ||
} | ||
} | ||
|
||
const handleSave = () => { | ||
const val = editor.current.editor.getValue() | ||
try { | ||
const data = JSON.parse(val) | ||
setSettings(data) | ||
setError(false) | ||
} catch (e) { | ||
setError(true) | ||
} | ||
} | ||
|
||
return ( | ||
<> | ||
<div className="relative w-full mt-2"> | ||
<AceEditor | ||
defaultValue={JSON.stringify(settings, null, "\t")} | ||
mode="json" | ||
onChange={onChange} | ||
name="json-editor" | ||
theme="one_dark" | ||
showPrintMargin={false} | ||
style={{ | ||
width: "100%" | ||
}} | ||
setOptions={{ | ||
showLineNumbers: true, | ||
tabSize: 2, | ||
useWorker: false | ||
}} | ||
ref={editor} | ||
/> | ||
</div> | ||
<div className="absolute z-50 align-middle bottom-3 right-3"> | ||
<div className="flex flex-row"> | ||
{hasError ? ( | ||
<p className="py-2 mr-1 text-red">Invalid JSON</p> | ||
) : ( | ||
<button | ||
className="p-2 border text-blue border-blue hover:text-white" | ||
onClick={handleSave}> | ||
Save | ||
</button> | ||
)} | ||
</div> | ||
</div> | ||
</> | ||
) | ||
} | ||
|
||
export default Editor |
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
Oops, something went wrong.
81078db
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
start-page – ./
start-page-excalith.vercel.app
start-page-git-main-excalith.vercel.app
excalith-start-page.vercel.app