|
1 | 1 | import { useLocation, useNavigate, useParams } from 'solid-app-router'; |
2 | 2 | import { Icon } from 'solid-heroicons'; |
3 | 3 | import { eye, eyeOff, plus, x } from 'solid-heroicons/outline'; |
4 | | -import { createEffect, createResource, For, Suspense } from 'solid-js'; |
| 4 | +import { createEffect, createResource, For, Show, Suspense } from 'solid-js'; |
5 | 5 | import { createStore, produce } from 'solid-js/store'; |
6 | 6 | import { defaultTabs } from '../../src'; |
7 | 7 | import { API, useAppContext } from '../context'; |
@@ -68,20 +68,21 @@ export const Home = () => { |
68 | 68 | const location = useLocation(); |
69 | 69 |
|
70 | 70 | createEffect(() => { |
71 | | - if (!location.hash && context.token) return; |
72 | | - |
73 | | - const initialTabs = parseHash(location.hash.slice(1), defaultTabs); |
74 | | - |
75 | | - localStorage.setItem( |
76 | | - 'scratchpad', |
77 | | - JSON.stringify({ |
78 | | - files: initialTabs.map((x) => ({ |
79 | | - name: x.name + ((x as any).type ? `.${(x as any).type}` : ''), |
80 | | - content: x.source.split('\n'), |
81 | | - })), |
82 | | - }), |
83 | | - ); |
84 | | - navigate(`/scratchpad`); |
| 71 | + if (location.hash) { |
| 72 | + const initialTabs = parseHash(location.hash.slice(1), defaultTabs); |
| 73 | + localStorage.setItem( |
| 74 | + 'scratchpad', |
| 75 | + JSON.stringify({ |
| 76 | + files: initialTabs.map((x) => ({ |
| 77 | + name: x.name + ((x as any).type ? `.${(x as any).type}` : ''), |
| 78 | + content: x.source.split('\n'), |
| 79 | + })), |
| 80 | + }), |
| 81 | + ); |
| 82 | + navigate(`/scratchpad`); |
| 83 | + } else if (!context.token && !params.user) { |
| 84 | + navigate(`/scratchpad`); |
| 85 | + } |
85 | 86 | }); |
86 | 87 |
|
87 | 88 | const [repls, setRepls] = createStore<Repls>({ total: 0, list: [] }); |
@@ -113,39 +114,41 @@ export const Home = () => { |
113 | 114 | }} |
114 | 115 | /> |
115 | 116 | <div class="m-8"> |
116 | | - <div class="flex flex-col align-middle"> |
117 | | - <button |
118 | | - class="bg-solid-lightgray shadow-md dark:bg-solid-darkLighterBg rounded-xl p-4 text-3xl flex mx-auto" |
119 | | - onClick={async () => { |
120 | | - const result = await fetch(`${API}/repl`, { |
121 | | - method: 'POST', |
122 | | - headers: { |
123 | | - 'authorization': `Bearer ${context.token}`, |
124 | | - 'Content-Type': 'application/json', |
125 | | - }, |
126 | | - body: JSON.stringify({ |
127 | | - title: 'Counter Example', |
128 | | - public: true, |
129 | | - labels: [], |
130 | | - version: '1.0', |
131 | | - files: defaultTabs.map((x) => ({ name: x.name, content: x.source.split('\n') })), |
132 | | - }), |
133 | | - }); |
134 | | - const { id } = await result.json(); |
135 | | - navigate(`/${context.user()?.display}/${id}`); |
136 | | - }} |
137 | | - > |
138 | | - <Icon path={plus} class="w-8" /> Create new REPL |
139 | | - </button> |
140 | | - <p class="text-center text-gray-300 text-sm"> |
141 | | - Or{' '} |
142 | | - <a href="/scratchpad" class="hover:underline"> |
143 | | - open my scratchpad |
144 | | - </a> |
145 | | - </p> |
146 | | - </div> |
| 117 | + <Show when={!params.user}> |
| 118 | + <div class="flex flex-col align-middle mb-16"> |
| 119 | + <button |
| 120 | + class="bg-solid-lightgray shadow-md dark:bg-solid-darkLighterBg rounded-xl p-4 text-3xl flex mx-auto" |
| 121 | + onClick={async () => { |
| 122 | + const result = await fetch(`${API}/repl`, { |
| 123 | + method: 'POST', |
| 124 | + headers: { |
| 125 | + 'authorization': `Bearer ${context.token}`, |
| 126 | + 'Content-Type': 'application/json', |
| 127 | + }, |
| 128 | + body: JSON.stringify({ |
| 129 | + title: 'Counter Example', |
| 130 | + public: true, |
| 131 | + labels: [], |
| 132 | + version: '1.0', |
| 133 | + files: defaultTabs.map((x) => ({ name: x.name, content: x.source.split('\n') })), |
| 134 | + }), |
| 135 | + }); |
| 136 | + const { id } = await result.json(); |
| 137 | + navigate(`/${context.user()?.display}/${id}`); |
| 138 | + }} |
| 139 | + > |
| 140 | + <Icon path={plus} class="w-8" /> Create new REPL |
| 141 | + </button> |
| 142 | + <p class="text-center text-gray-300 text-sm"> |
| 143 | + Or{' '} |
| 144 | + <a href="/scratchpad" class="hover:underline"> |
| 145 | + open my scratchpad |
| 146 | + </a> |
| 147 | + </p> |
| 148 | + </div> |
| 149 | + </Show> |
147 | 150 |
|
148 | | - <h1 class="text-center text-3xl mb-4 mt-16">{params.user || 'My'} Repls</h1> |
| 151 | + <h1 class="text-center text-3xl mb-4">{params.user ? `${params.user}'s` : 'My'} Repls</h1> |
149 | 152 | <table class="w-200 max-w-full mx-auto"> |
150 | 153 | <thead> |
151 | 154 | <tr class="border-b border-neutral-600"> |
|
0 commit comments