Skip to content

Commit 5675eac

Browse files
refactor: pretty clean and very neat codebase, without shitty monorepo
1 parent e05b6ed commit 5675eac

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

70 files changed

+532
-552
lines changed

β€Ž.gitignoreβ€Ž

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,9 @@ public/.nextra
1212
dist
1313
.direnv
1414
result
15+
16+
.vercel
17+
out
18+
public/robots.txt
19+
public/sitemap.xml
20+
public/sitemap-0.xml
Lines changed: 53 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,12 @@ import { vscodeDark } from "@uiw/codemirror-theme-vscode"
44
import { linter } from '@codemirror/lint';
55
import { json5, json5ParseLinter } from 'codemirror-json5';
66
import { nix } from "@replit/codemirror-lang-nix";
7+
import { StreamLanguage } from "@codemirror/language"
8+
import { toml } from "@codemirror/legacy-modes/mode/toml"
9+
import { yaml } from "@codemirror/lang-yaml";
710
import JSON5 from "json5"
11+
import YAML from "yaml"
12+
import TOML from "smol-toml"
813

914
function json2nix(json, d = 0) {
1015
const lines = [];
@@ -47,24 +52,64 @@ const initialContent = {
4752
shaxzod: ["qudratov", { telegram: "@shakhzodme" }],
4853
}
4954

50-
export default function JSON2Nix() {
55+
export default function JSON2Nix({ type = "json" }) {
5156
const [jsonValue, setJsonValue] = React.useState(JSON.stringify(initialContent, null, 2))
57+
const [tomlValue, setTomlValue] = React.useState(TOML.stringify(initialContent))
58+
const [yamlValue, setYamlValue] = React.useState(YAML.stringify(initialContent))
5259
const [nixValue, setNixValue] = React.useState(json2nix(initialContent))
5360

54-
const onJsonChange = React.useCallback((value) => {
55-
setJsonValue(value)
61+
const onChange = React.useCallback((type) => (value) => {
62+
switch (type) {
63+
case "json":
64+
setJsonValue(value)
65+
break
66+
case "toml":
67+
setTomlValue(value)
68+
break
69+
case "yaml":
70+
setYamlValue(value)
71+
break
72+
}
73+
5674
try {
57-
setNixValue(json2nix(JSON5.parse(value)))
75+
switch (type) {
76+
case "json":
77+
setNixValue(json2nix(JSON5.parse(value)))
78+
break
79+
case "toml":
80+
setNixValue(json2nix(TOML.parse(value)))
81+
break
82+
case "yaml":
83+
setNixValue(json2nix(YAML.parse(value)))
84+
break
85+
}
5886
} catch (e) {
5987
console.error("failed to parse", e)
6088
}
89+
6190
}, [setJsonValue, setNixValue])
6291

6392
return <div>
64-
<div>
65-
<h2>JSON:</h2>
66-
<CodeMirror theme={vscodeDark} value={jsonValue} onChange={onJsonChange} extensions={[json5(), linter(json5ParseLinter())]} />
67-
</div>
93+
{type == "json" && (
94+
<div>
95+
<h2>JSON:</h2>
96+
<CodeMirror theme={vscodeDark} value={jsonValue} onChange={onChange("json")} extensions={[json5(), linter(json5ParseLinter())]} />
97+
</div>
98+
)}
99+
100+
{type == "toml" && (
101+
<div>
102+
<h2>TOML:</h2>
103+
<CodeMirror theme={vscodeDark} value={tomlValue} onChange={onChange("toml")} extensions={[StreamLanguage.define(toml)]} />
104+
</div>
105+
)}
106+
107+
{type == "yaml" && (
108+
<div>
109+
<h2>YAML:</h2>
110+
<CodeMirror theme={vscodeDark} value={yamlValue} onChange={onChange("yaml")} extensions={[yaml()]} />
111+
</div>
112+
)}
68113

69114
<div>
70115
<h2>Nix:</h2>

β€Ždefault-ssg.nixβ€Ž

Lines changed: 0 additions & 55 deletions
This file was deleted.

β€Ždefault-ssr.nixβ€Ž

Lines changed: 0 additions & 90 deletions
This file was deleted.

0 commit comments

Comments
Β (0)