Skip to content

Commit 47882d0

Browse files
committed
refactor: split out to useRepos composable
1 parent 23c90b3 commit 47882d0

File tree

4 files changed

+12
-9
lines changed

4 files changed

+12
-9
lines changed

app/app.vue

+4
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ useSeoMeta({
33
title: 'unsight.dev',
44
description: 'Detect duplicate GitHub issues, areas of concern and more across related repositories',
55
})
6+
7+
const { data: repos } = useRepos()
68
</script>
79

810
<template>
@@ -37,6 +39,8 @@ useSeoMeta({
3739
>
3840
@danielroe.dev
3941
</a>
42+
&middot;
43+
{{ repos.length }} repos
4044
</footer>
4145
</div>
4246
</template>

app/composables/repos.ts

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
export const useRepos = () => useFetch('/api/repos', {
2+
baseURL: useRuntimeConfig().public.remote,
3+
getCachedData: (key, nuxtApp) => nuxtApp.payload.data[key] || nuxtApp.static.data[key],
4+
default: () => [],
5+
})

app/pages/[owner]/[repo]/index.vue

+2-5
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,7 @@
22
import hexRgb from 'hex-rgb'
33
import rgbToHSL from 'rgb-to-hsl'
44
5-
const { data: allowedRepos } = useFetch('/api/repos', {
6-
baseURL: useRuntimeConfig().public.remote,
7-
default: () => [],
8-
})
5+
const { data: allowedRepos } = useRepos()
96
107
const route = useRoute('owner-repo')
118
const selectedRepo = computed(() => route.params.owner && route.params.repo ? `${route.params.owner}/${route.params.repo}` : 'nuxt/nuxt')
@@ -27,7 +24,7 @@ onMounted(async () => {
2724
})
2825
2926
function navigateToRepo(event: Event) {
30-
const [owner, repo] = (event.target as HTMLSelectElement).value.split('/')
27+
const [owner, repo] = (event.target as HTMLSelectElement).value.split('/') as [string, string]
3128
return navigateTo({
3229
name: 'owner-repo',
3330
params: { owner, repo },

app/pages/index.vue

+1-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
<script setup lang="ts">
22
const config = useRuntimeConfig()
33
4-
const { data: allowedRepos, refresh } = useFetch('/api/repos', {
5-
baseURL: config.public.remote,
6-
default: () => [],
7-
})
4+
const { data: allowedRepos, refresh } = useRepos()
85
96
const installationURL = `https://github.com/apps/${config.public.github.appSlug}/installations/new`
107

0 commit comments

Comments
 (0)