Skip to content

Commit bcbbbf2

Browse files
authored
Merge pull request #17 from arist76/feature/api_and_utility
Frontend: api and utility
2 parents ab73a25 + b345b64 commit bcbbbf2

16 files changed

Lines changed: 2865 additions & 563 deletions

File tree

frontend/src/Editor.tsx

Lines changed: 20 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { VsRunAll } from 'solid-icons/vs'
88
import { createMemo, createSignal, onMount, Show } from 'solid-js'
99
import { A } from '@solidjs/router'
1010
import toast, { Toaster } from 'solid-toast'
11-
import { BACKEND_URL, TOKEN } from './urls'
11+
import { API_URL } from './lib/api'
1212
import hljs from 'highlight.js/lib/core'
1313
import 'highlight.js/styles/panda-syntax-dark.css'
1414
import {
@@ -41,21 +41,12 @@ import {
4141
completionKeymap,
4242
} from '@codemirror/autocomplete'
4343
import {
44-
EditorMode,
45-
ImportCSVDirection,
46-
ImportFormat,
47-
ParserParameters,
44+
// EditorMode,
45+
// ImportCSVDirection,
46+
// ImportFormat,
47+
// ParserParameters,
4848
Token,
49-
} from './types'
50-
import {
51-
editorTheme,
52-
highlightStyle,
53-
languageSupport,
54-
mettaLinter,
55-
toJSON,
56-
} from './mettaLanguageSupport'
57-
import { parser } from './parser/parser'
58-
import { Expression, Symbol, Variable } from './parser/parser.terms'
49+
} from './lib/types'
5950

6051
const extensionToImportFormat = (file: File): ImportFormat | undefined => {
6152
const extension = file.name.split('.')[1]
@@ -100,7 +91,7 @@ const App: Component = () => {
10091
const [editorOutput, setEditorOutput] = createSignal('')
10192
const [editorView, setEditorView] = createSignal<EditorView>()
10293
const [editorMode, setEditorMode] = createSignal<EditorMode>(
103-
EditorMode.DEFAULT
94+
"EditorMode.DEFAULT"
10495
)
10596

10697
const [activeImportFile, setActiveImportFile] = createSignal<File>()
@@ -122,7 +113,7 @@ const App: Component = () => {
122113

123114
// CSV-specific import parameters
124115
const [importCSVDirection, setImportCSVDirection] =
125-
createSignal<ImportCSVDirection>(ImportCSVDirection.CELL_LABELED)
116+
createSignal<ImportCSVDirection>("ImportCSVDirection.CELL_LABELED")
126117
const [importCSVDelimiter, setImportCSVDelimiter] =
127118
createSignal<string>('\u002C')
128119

@@ -136,8 +127,8 @@ const App: Component = () => {
136127
const editorState = EditorState.create({
137128
doc: editorContent(),
138129
extensions: [
139-
editorTheme,
140-
languageSupport,
130+
// editorTheme,
131+
// languageSupport,
141132
highlightActiveLineGutter(),
142133
history(),
143134
foldGutter(),
@@ -147,10 +138,10 @@ const App: Component = () => {
147138
bracketMatching(),
148139
closeBrackets(),
149140
highlightActiveLine(),
150-
syntaxHighlighting(highlightStyle),
141+
syntaxHighlighting("highlightStyle"),
151142
EditorView.lineWrapping,
152143
autocompletion(),
153-
mettaLinter,
144+
// mettaLinter,
154145
keymap.of([
155146
...closeBracketsKeymap,
156147
...defaultKeymap,
@@ -236,7 +227,7 @@ const App: Component = () => {
236227

237228
importFileModal.close()
238229
}
239-
230+
let TOKEN = false;
240231
if (TOKEN) {
241232
loadSpace(TOKEN)
242233
setEditorMode(EditorMode.EDIT)
@@ -351,7 +342,7 @@ const App: Component = () => {
351342

352343
try {
353344
const resp = await fetch(
354-
`${BACKEND_URL}/translations/${fileFormat}?${parameters.toString()}`,
345+
`${API_URL}/translations/${fileFormat}?${parameters.toString()}`,
355346
{
356347
method: 'POST',
357348
headers: {},
@@ -368,7 +359,7 @@ const App: Component = () => {
368359
}
369360

370361
// switch to import mode to allow modification of import parameters
371-
setEditorMode(EditorMode.IMPORT)
362+
setEditorMode("EditorMode.IMPORT")
372363

373364
// insert translated MeTTa code at cursor location
374365
view.dispatch(
@@ -462,7 +453,7 @@ const App: Component = () => {
462453
*/
463454
const loadSpace = async (token: string): Promise<void> => {
464455
try {
465-
const resp = await fetch(`${BACKEND_URL}/token`, {
456+
const resp = await fetch(`${API_URL}/token`, {
466457
method: 'GET',
467458
headers: {
468459
'Content-Type': 'application/json',
@@ -523,7 +514,7 @@ const App: Component = () => {
523514
const content = editorContent()
524515

525516
await fetch(
526-
`${BACKEND_URL}/spaces${token()?.namespace}${selectedNamespace()}`,
517+
`${API_URL}/spaces${token()?.namespace}${selectedNamespace()}`,
527518
{
528519
method: 'PUT',
529520
headers: {
@@ -539,7 +530,7 @@ const App: Component = () => {
539530

540531
const read = async (token?: Token) => {
541532
const resp = await fetch(
542-
`${BACKEND_URL}/spaces${token?.namespace}${selectedNamespace()}`,
533+
`${API_URL}/spaces${token?.namespace}${selectedNamespace()}`,
543534
{
544535
method: 'GET',
545536
headers: {
@@ -572,7 +563,7 @@ const App: Component = () => {
572563
}
573564

574565
const transform = async () => {
575-
const resp = await fetch(`${BACKEND_URL}/spaces`, {
566+
const resp = await fetch(`${API_URL}/spaces`, {
576567
method: 'POST',
577568
headers: {
578569
'Content-Type': 'application/json',
@@ -714,7 +705,7 @@ const App: Component = () => {
714705
</Show>
715706
</div>
716707
<Show
717-
when={editorMode() === EditorMode.IMPORT}
708+
when={editorMode() === "EditorMode.IMPORT"}
718709
fallback={<div></div>}
719710
>
720711
<div >

frontend/src/Tokens.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import type { Component, JSX, ResourceFetcherInfo } from 'solid-js'
22
import { createResource, createSignal, For, onMount, Show } from 'solid-js'
33
import { A } from '@solidjs/router'
4-
import { BACKEND_URL } from './urls'
4+
import { API_URL } from './lib/api'
55
import { AiOutlineCopy, AiOutlineGithub } from 'solid-icons/ai'
66
import toast, { Toaster } from 'solid-toast'
7-
import { Token } from './types'
7+
import { Token } from './lib/types'
88

99
enum SortableColumns {
1010
TIMESTAMP,
@@ -27,7 +27,7 @@ const fetchTokens = async (
2727
}
2828

2929
try {
30-
const resp = await fetch(`${BACKEND_URL}/tokens`, {
30+
const resp = await fetch(`${API_URL}/tokens`, {
3131
method: 'GET',
3232
headers: {
3333
'Content-Type': 'application/json',
@@ -77,7 +77,7 @@ const createToken = async (
7777
parent: 0,
7878
}
7979

80-
const resp = await fetch(`${BACKEND_URL}/tokens`, {
80+
const resp = await fetch(`${API_URL}/tokens`, {
8181
method: 'POST',
8282
headers: { 'Content-Type': 'application/json', Authorization: root },
8383
body: JSON.stringify(newToken),
@@ -95,7 +95,7 @@ const refreshCodes = async (
9595
}
9696

9797
const promises = tokens.map((t) =>
98-
fetch(`${BACKEND_URL}/tokens/${t.id}`, {
98+
fetch(`${API_URL}/tokens/${t.id}`, {
9999
method: 'POST',
100100
headers: {
101101
'Content-Type': 'application/json',
@@ -115,7 +115,7 @@ const deleteTokens = async (
115115
return
116116
}
117117

118-
await fetch(`${BACKEND_URL}/tokens`, {
118+
await fetch(`${API_URL}/tokens`, {
119119
method: 'DELETE',
120120
headers: { 'Content-Type': 'application/json', Authorization: root },
121121
body: JSON.stringify(tokens.map((t) => t.id)),

0 commit comments

Comments
 (0)