Skip to content

Commit 74c9905

Browse files
committed
hide options when not viewing local
1 parent 6e46261 commit 74c9905

File tree

5 files changed

+123
-115
lines changed

5 files changed

+123
-115
lines changed

package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060
"@babel/standalone": "^7.18.7",
6161
"@solid-primitives/media": "^2.0.0",
6262
"@solid-primitives/scheduled": "^1.0.0",
63-
"babel-preset-solid": "1.4.5",
63+
"babel-preset-solid": "1.4.6",
6464
"dedent": "^0.7.0",
6565
"jszip": "^3.10.0",
6666
"monaco-editor-textmate": "^3.0.0",
@@ -70,7 +70,7 @@
7070
"rollup": "^2.75.7",
7171
"solid-dismiss": "^1.2.1",
7272
"solid-heroicons": "^2.0.3",
73-
"solid-js": "1.4.5",
73+
"solid-js": "1.4.6",
7474
"y-webrtc": "^10.2.3",
7575
"yjs": "^13.5.39"
7676
}

playground/context.tsx

+5-6
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ interface AppContextType {
66
token: string;
77
user: Resource<{ display: string; avatar: string } | undefined>;
88
tabs: Accessor<Tab[] | undefined>;
9-
setTabs: (x: Accessor<Tab[] | undefined>) => void;
9+
setTabs: (x: Accessor<Tab[] | undefined> | undefined) => void;
1010
dark: Accessor<boolean>;
1111
toggleDark: () => void;
1212
}
@@ -40,8 +40,7 @@ export const AppContextProvider: ParentComponent = (props) => {
4040
const [dark, setDark] = createSignal(isDarkTheme());
4141
document.body.classList.toggle('dark', dark());
4242

43-
let [hasTabs, setHasTabs] = createSignal(false);
44-
let tabs: Accessor<Tab[] | undefined>;
43+
let [tabsGetter, setTabs] = createSignal<Accessor<Tab[] | undefined>>();
4544
return (
4645
<AppContext.Provider
4746
value={{
@@ -54,12 +53,12 @@ export const AppContextProvider: ParentComponent = (props) => {
5453
},
5554
user,
5655
tabs() {
57-
if (!hasTabs()) return undefined;
56+
const tabs = tabsGetter();
57+
if (!tabs) return undefined;
5858
return tabs();
5959
},
6060
setTabs(x) {
61-
tabs = x;
62-
setHasTabs(true);
61+
setTabs(() => x);
6362
},
6463
dark,
6564
toggleDark() {

playground/pages/edit.tsx

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import tsWorker from 'monaco-editor/esm/vs/language/typescript/ts.worker?worker'
33
import cssWorker from 'monaco-editor/esm/vs/language/css/css.worker?worker';
44
import CompilerWorker from '../../src/workers/compiler?worker';
55
import FormatterWorker from '../../src/workers/formatter?worker';
6-
import { batch, createResource, createSignal, lazy, Show, Suspense } from 'solid-js';
6+
import { batch, createResource, createSignal, lazy, onCleanup, Show, Suspense } from 'solid-js';
77
import { useMatch, useNavigate, useParams } from 'solid-app-router';
88
import { API, useAppContext } from '../context';
99
import { debounce } from '@solid-primitives/scheduled';
@@ -63,6 +63,7 @@ export const Edit = (props: { horizontal: boolean }) => {
6363
const [tabs, trueSetTabs] = createSignal<InternalTab[]>([]);
6464
const setTabs = (tabs: (Tab | InternalTab)[]) => trueSetTabs(mapTabs(tabs));
6565
context.setTabs(tabs);
66+
onCleanup(() => context.setTabs(undefined));
6667

6768
const [current, setCurrent] = createSignal<string | undefined>(undefined, { equals: false });
6869
const [resource, { mutate }] = createResource<APIRepl, { repl: string; scratchpad: boolean }>(

playground/pages/home.tsx

+49-43
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ export const Home = () => {
109109
<Header
110110
share={async () => {
111111
const url = new URL(document.location.origin);
112-
url.pathname = context.user.latest!.display;
112+
url.pathname = params.user || context.user.latest!.display;
113113
return url.toString();
114114
}}
115115
/>
@@ -151,8 +151,10 @@ export const Home = () => {
151151
<thead>
152152
<tr class="border-b border-neutral-600 font-medium">
153153
<th class="pb-2 w-6/10 text-left">Title</th>
154-
<th class="pb-2 w-32 text-left">Edited</th>
155-
<th class="pb-2 w-20 text-right">Options</th>
154+
<th class="pb-2 w-32 text-left last:text-right">Edited</th>
155+
<Show when={!params.user}>
156+
<th class="pb-2 w-20 text-right">Options</th>
157+
</Show>
156158
</tr>
157159
</thead>
158160
<tbody>
@@ -184,47 +186,51 @@ export const Home = () => {
184186
<td>
185187
<a href={`${params.user || context.user()?.display}/${repl.id}`}>{repl.title}</a>
186188
</td>
187-
<td>{timeAgo(Date.now() - new Date(repl.updated_at || repl.created_at).getTime())}</td>
188-
<td class="text-right">
189-
<Icon
190-
path={repl.public ? eye : eyeOff}
191-
class="w-6 inline m-2 ml-0 cursor-pointer"
192-
onClick={async () => {
193-
fetch(`${API}/repl/${repl.id}`, {
194-
method: 'PUT',
195-
headers: {
196-
'authorization': `Bearer ${context.token}`,
197-
'Content-Type': 'application/json',
198-
},
199-
body: JSON.stringify({
200-
...repl,
201-
public: !repl.public,
202-
}),
203-
});
204-
setRepls(
205-
produce((x) => {
206-
x!.list[i()].public = !repl.public;
207-
}),
208-
);
209-
}}
210-
/>
211-
<Icon
212-
path={x}
213-
class="w-6 inline m-2 mr-0 text-red-700 cursor-pointer"
214-
onClick={async () => {
215-
fetch(`${API}/repl/${repl.id}`, {
216-
method: 'DELETE',
217-
headers: {
218-
authorization: `Bearer ${context.token}`,
219-
},
220-
});
221-
setRepls({
222-
total: repls.total - 1,
223-
list: repls.list.filter((x) => x.id !== repl.id),
224-
});
225-
}}
226-
/>
189+
<td class="last:text-right">
190+
{timeAgo(Date.now() - new Date(repl.updated_at || repl.created_at).getTime())}
227191
</td>
192+
<Show when={!params.user}>
193+
<td class="text-right">
194+
<Icon
195+
path={repl.public ? eye : eyeOff}
196+
class="w-6 inline m-2 ml-0 cursor-pointer"
197+
onClick={async () => {
198+
fetch(`${API}/repl/${repl.id}`, {
199+
method: 'PUT',
200+
headers: {
201+
'authorization': `Bearer ${context.token}`,
202+
'Content-Type': 'application/json',
203+
},
204+
body: JSON.stringify({
205+
...repl,
206+
public: !repl.public,
207+
}),
208+
});
209+
setRepls(
210+
produce((x) => {
211+
x!.list[i()].public = !repl.public;
212+
}),
213+
);
214+
}}
215+
/>
216+
<Icon
217+
path={x}
218+
class="w-6 inline m-2 mr-0 text-red-700 cursor-pointer"
219+
onClick={async () => {
220+
fetch(`${API}/repl/${repl.id}`, {
221+
method: 'DELETE',
222+
headers: {
223+
authorization: `Bearer ${context.token}`,
224+
},
225+
});
226+
setRepls({
227+
total: repls.total - 1,
228+
list: repls.list.filter((x) => x.id !== repl.id),
229+
});
230+
}}
231+
/>
232+
</td>
233+
</Show>
228234
</tr>
229235
)}
230236
</For>

0 commit comments

Comments
 (0)