|
1 | 1 | <script setup lang="ts"> |
2 | | -const { data, error } = await useAsyncData(async () => { |
3 | | - const raw = await fetch(`/filePathMap`) |
4 | | - const response = await raw.json() |
5 | | - return response |
6 | | -}) |
| 2 | +import type { ExpressionItem, ExpressionsMapResponse } from '~~/shared/types' |
| 3 | +
|
| 4 | +const { data, status, error } = useFetch<ExpressionsMapResponse>('/expressionsMap') |
| 5 | +
|
| 6 | +function handleLaunchEditor(path: string, item: ExpressionItem) { |
| 7 | + $fetch('/launchEditor', { |
| 8 | + query: { |
| 9 | + path: `${path}:${item.line}:${item.column}`, |
| 10 | + }, |
| 11 | + }) |
| 12 | +} |
7 | 13 | </script> |
8 | 14 |
|
9 | 15 | <template> |
10 | | - <Suspense> |
11 | | - <template #default> |
12 | | - <div v-if="error" class="text-red-500"> |
13 | | - {{ data }} |
14 | | - {{ error }} |
| 16 | + <div class="w-screen p-8"> |
| 17 | + <div class="flex items-center justify-between flex-wrap gap-4"> |
| 18 | + <div> |
| 19 | + <a class="text-3xl font-[300] cursor-pointer" href="https://github.com/unplugin/unplugin-turbo-console" target="_blank"> |
| 20 | + Unplugin<span class="text-green-500"> Turbo Console</span> Inspector |
| 21 | + </a> |
| 22 | + |
| 23 | + <a |
| 24 | + :href="`https://github.com/unplugin/unplugin-turbo-console/releases/tag/v${data?.version}`" target="_blank" |
| 25 | + class="-translate-y-[16px] font-mono text-[16px] text-gray-400 inline-block" |
| 26 | + > |
| 27 | + v{{ data?.version }} |
| 28 | + </a> |
| 29 | + </div> |
| 30 | + |
| 31 | + <HeaderInfo /> |
| 32 | + </div> |
| 33 | + |
| 34 | + <div v-if="status === 'pending'" class="flex h-full justify-center"> |
| 35 | + <div class="flex flex-col items-center gap-2"> |
| 36 | + <Icon name="uil:spinner" class="text-2xl animate-spin" /> |
| 37 | + <span class="text-gray-500 dark:text-gray-400">Loading...</span> |
| 38 | + </div> |
| 39 | + </div> |
| 40 | + |
| 41 | + <div v-else-if="status === 'error'"> |
| 42 | + <div class="text-red-500 dark:text-red-400 p-4 rounded-lg bg-red-50 dark:bg-red-900/20 w-full"> |
| 43 | + <div class="flex items-center gap-2 mb-2"> |
| 44 | + <Icon name="uil:exclamation-triangle" class="text-xl" /> |
| 45 | + <span class="font-medium">Error</span> |
| 46 | + {{ error }} |
| 47 | + </div> |
| 48 | + </div> |
| 49 | + </div> |
| 50 | + |
| 51 | + <div v-else-if="status === 'success'"> |
| 52 | + <div v-for="(items, key) in data?.expressionsMap" :key="key"> |
| 53 | + <ui-collapsible :file-name="(key as string)"> |
| 54 | + <template #content> |
| 55 | + <div v-for="item in items.expressions" :key="item.code" @click="handleLaunchEditor(items.filePath, item)"> |
| 56 | + <shiki :code="`console.${item.method}(${item.code})`" /> |
| 57 | + </div> |
| 58 | + </template> |
| 59 | + </ui-collapsible> |
15 | 60 | </div> |
16 | | - </template> |
17 | | - <template #fallback> |
18 | | - Loading... |
19 | | - </template> |
20 | | - </Suspense> |
| 61 | + </div> |
| 62 | + </div> |
21 | 63 | </template> |
0 commit comments