Skip to content

Commit 79f68e9

Browse files
committed
more tweaks
1 parent b0423ca commit 79f68e9

File tree

3 files changed

+33
-9
lines changed

3 files changed

+33
-9
lines changed

playground/context.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ interface AppContextType {
88
const AppContext = createContext<AppContextType>();
99

1010
// const API = "http://localhost:8787";
11-
export const API = 'https://api.solidjs.com';
11+
export const API = '/api';
1212

1313
export const AppContextProvider: ParentComponent = (props) => {
1414
const [token, setToken] = createSignal(localStorage.getItem('token') || '');

playground/pages/home.tsx

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
import { useRouteData } from 'solid-app-router';
1+
import { useNavigate, useRouteData } from 'solid-app-router';
22
import { Icon } from 'solid-heroicons';
33
import { eye, eyeOff, plus, x } from 'solid-heroicons/outline';
44
import { createResource, For } from 'solid-js';
5+
import { defaultTabs } from '../../src';
56
import { API, useAppContext } from '../context';
67

78
interface Repls {
@@ -22,6 +23,7 @@ interface Repls {
2223
export const Home = () => {
2324
const user = useRouteData();
2425
const context = useAppContext()!;
26+
const navigate = useNavigate();
2527

2628
const [repls] = createResource(
2729
() => user || context.user()?.display,
@@ -34,13 +36,26 @@ export const Home = () => {
3436

3537
return (
3638
<div class="bg-brand-other h-full m-8">
37-
<button class="bg-solid-lightgray shadow-md dark:bg-solid-darkLighterBg rounded-xl p-4 text-3xl flex mx-auto" onClick={
38-
() => {
39-
fetch(`${API}/repls`, {
40-
method: "POST",
41-
})
42-
}
43-
}>
39+
<button
40+
class="bg-solid-lightgray shadow-md dark:bg-solid-darkLighterBg rounded-xl p-4 text-3xl flex mx-auto"
41+
onClick={async () => {
42+
const result = await fetch(`${API}/repl`, {
43+
method: 'POST',
44+
headers: {
45+
authorization: `Bearer ${context.token}`,
46+
},
47+
body: JSON.stringify({
48+
title: 'Counter Example',
49+
public: true,
50+
labels: [],
51+
version: '1.0',
52+
files: defaultTabs.map((x) => ({ name: `${x.name}.${x.type}`, content: x.source.split('\n') })),
53+
}),
54+
});
55+
const { id } = await result.json();
56+
navigate(`/${context.user()?.display}/${id}`);
57+
}}
58+
>
4459
<Icon path={plus} class="w-8" /> Create new REPL
4560
</button>
4661

vite.config.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,13 @@ export default defineConfig((env) => ({
1717
},
1818
},
1919
},
20+
server: {
21+
proxy: {
22+
'/api': {
23+
target: 'https://api.solidjs.com',
24+
changeOrigin: true,
25+
rewrite: (path) => path.replace(/^\/api/, ''),
26+
},
27+
},
28+
},
2029
}));

0 commit comments

Comments
 (0)