Skip to content

Commit 084a551

Browse files
committed
feat: use router to store repo state
1 parent 292f076 commit 084a551

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

app/app.vue

+9-5
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
<script setup lang="ts">
22
import hexRgb from 'hex-rgb'
33
4-
import { allowedRepos } from '#shared/repos'
4+
import { allowedRepos, isAllowedRepo } from '#shared/repos'
55
6-
const repo = ref('nuxt/nuxt')
6+
const route = useRoute()
7+
const selectedRepo = computed(() => {
8+
const query = route.query.repo as string | undefined
9+
return query && isAllowedRepo(query) ? query : 'nuxt/nuxt'
10+
})
711
8-
const { data: clusters, refresh, status } = useFetch(() => `/api/clusters/${repo.value}`, {
12+
const { data: clusters, refresh, status } = useFetch(() => `/api/clusters/${selectedRepo.value}`, {
913
server: false,
1014
immediate: import.meta.client && !('startViewTransition' in document),
1115
default: () => [],
@@ -54,7 +58,7 @@ async function updateSearch() {}
5458
</p>
5559
</nav>
5660
<p class="flex gap-2 items-center">
57-
{{ repo }}
61+
{{ selectedRepo }}
5862
<button
5963
class="rounded-full w-7 h-7 flex items-center justify-center border-solid border border-gray-700 bg-transparent color-gray-400 hover:color-gray-200 active:color-white focus:color-gray-200 hover:border-gray-400 active:border-white focus:border-gray-400 transition-colors flex-shrink-0"
6064
:class="{ 'animate-spin opacity-50 pointer-events-none': status === 'pending' || status === 'idle' }"
@@ -87,8 +91,8 @@ async function updateSearch() {}
8791
placeholder="repository"
8892
> -->
8993
<select
90-
v-model="repo"
9194
class="pl-8 bg-transparent pr-2 py-2 color-white border-0 w-full"
95+
@change="(event) => navigateTo({ query: { repo: (event.target as HTMLSelectElement).value } })"
9296
>
9397
<option
9498
v-for="repo in allowedRepos"

0 commit comments

Comments
 (0)