Skip to content

Commit e20e6af

Browse files
committed
update for new api
1 parent 07a6c6b commit e20e6af

File tree

4 files changed

+176
-180
lines changed

4 files changed

+176
-180
lines changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
"rollup-plugin-import-css": "^3.0.3",
4747
"rollup-plugin-windicss": "^1.8.7",
4848
"typescript": "^4.7.4",
49-
"vite": "^3.0.4",
49+
"vite": "^3.0.7",
5050
"vite-plugin-solid": "^2.3.0",
5151
"vite-plugin-windicss": "^1.8.7",
5252
"windicss": "^3.5.6",
@@ -65,7 +65,7 @@
6565
"monaco-textmate": "^3.0.1",
6666
"onigasm": "^2.2.5",
6767
"prettier": "^2.7.1",
68-
"rollup": "^2.77.2",
68+
"rollup": "^2.78.0",
6969
"solid-dismiss": "^1.2.1",
7070
"solid-heroicons": "^2.0.3",
7171
"solid-js": "1.4.8"

playground/pages/edit.tsx

Lines changed: 10 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { API, useAppContext } from '../context';
1010
import { debounce } from '@solid-primitives/scheduled';
1111
import { defaultTabs } from '../../src';
1212
import type { Tab } from 'solid-repl';
13-
import type { APIRepl, ReplFile } from './home';
13+
import type { APIRepl } from './home';
1414
import { Header } from '../components/header';
1515
import { compressToURL } from '@amoutonbrady/lz-string';
1616

@@ -92,7 +92,7 @@ export const Edit = (props: { horizontal: boolean }) => {
9292
output = {
9393
files: defaultTabs.map((x) => ({
9494
name: x.name,
95-
content: x.source.split('\n'),
95+
content: x.source,
9696
})),
9797
} as APIRepl;
9898
localStorage.setItem('scratchpad', JSON.stringify(output));
@@ -102,21 +102,13 @@ export const Edit = (props: { horizontal: boolean }) => {
102102
} else {
103103
output = await fetch(`${API}/repl/${repl}`, {
104104
headers: { authorization: context.token ? `Bearer ${context.token}` : '' },
105-
})
106-
.then((r) => r.json())
107-
.then((r) => ({
108-
...r,
109-
files: r.files.map((x: ReplFile) => ({
110-
name: x.name + ((x as any).type ? `.${(x as any).type}` : ''),
111-
content: typeof x.content == 'string' ? (x.content as string).split('\n') : x.content,
112-
})),
113-
}));
105+
}).then((r) => r.json());
114106
}
115107

116108
batch(() => {
117109
setTabs(
118110
output.files.map((x) => {
119-
return { name: x.name, source: x.content.join('\n') };
111+
return { name: x.name, source: x.content };
120112
}),
121113
);
122114
setCurrent(output.files[0].name);
@@ -128,29 +120,21 @@ export const Edit = (props: { horizontal: boolean }) => {
128120

129121
const updateRepl = debounce(
130122
() => {
123+
const files = tabs().map((x) => ({ name: x.name, content: x.source }));
124+
131125
if (readonly()) {
132-
localStorage.setItem(
133-
'scratchpad',
134-
JSON.stringify({
135-
files: tabs()!.map((x) => ({
136-
name: x.name,
137-
content: x.source.split('\n'),
138-
})),
139-
}),
140-
);
126+
localStorage.setItem('scratchpad', JSON.stringify({ files }));
141127
disableFetch = true;
142128
navigate('/scratchpad');
143129
return;
130+
} else if (scratchpad()) {
131+
localStorage.setItem('scratchpad', JSON.stringify({ files }));
144132
}
145133

146134
const repl = resource.latest;
147135
if (!repl) return;
148136

149-
const files = tabs().map((x) => ({ name: x.name, content: x.source.split('\n') }));
150-
151-
if (scratchpad()) {
152-
localStorage.setItem('scratchpad', JSON.stringify({ files }));
153-
} else if (context.token && context.user()?.display == params.user) {
137+
if (context.token && context.user()?.display == params.user) {
154138
fetch(`${API}/repl/${params.repl}`, {
155139
method: 'PUT',
156140
headers: {

playground/pages/home.tsx

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ function parseHash<T>(hash: string, fallback: T): T {
1919

2020
export interface ReplFile {
2121
name: string;
22-
content: string[];
22+
content: string;
2323
}
2424
export interface APIRepl {
2525
id: string;
@@ -52,8 +52,8 @@ export const Home = () => {
5252
'scratchpad',
5353
JSON.stringify({
5454
files: initialTabs.map((x) => ({
55-
name: x.name + ((x as any).type ? `.${(x as any).type}` : ''),
56-
content: x.source.split('\n'),
55+
name: x.name,
56+
content: x.source,
5757
})),
5858
}),
5959
);
@@ -110,9 +110,13 @@ export const Home = () => {
110110
public: true,
111111
labels: [],
112112
version: '1.0',
113-
files: defaultTabs.map((x) => ({ name: x.name, content: x.source.split('\n') })),
113+
files: defaultTabs.map((x) => ({ name: x.name, content: x.source })),
114114
}),
115115
});
116+
if (!result.ok) {
117+
alert('Failed to create repl');
118+
throw new Error(result.statusText);
119+
}
116120
const { id } = await result.json();
117121
navigate(`/${context.user()?.display}/${id}`);
118122
}}

0 commit comments

Comments
 (0)