Skip to content

Commit 8ea09fe

Browse files
feat: leverage Nuxt's auto imports
1 parent a6594e2 commit 8ea09fe

File tree

6 files changed

+34
-22
lines changed

6 files changed

+34
-22
lines changed

.clinerules

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -74,21 +74,44 @@ This is a Nuxt 3 + Supabase project using TypeScript
7474
- ProjectWithTags: Extended project with nested tags
7575
- Database: Complete Supabase schema type
7676

77-
### Using Supabase in Components
77+
### Auto-imports in Nuxt
7878

79-
1. Import types:
79+
1. Components are auto-imported:
80+
81+
```vue
82+
<template>
83+
<!-- No import needed for components -->
84+
<ProjectsList />
85+
<FeaturedProjects />
86+
<HomeHero />
87+
</template>
88+
```
89+
90+
2. Composables and Vue utilities are auto-imported:
8091

8192
```typescript
93+
// Only need to import types - everything else is auto-imported
8294
import type { Project, Database } from '~/types/supabase'
95+
96+
// These are auto-imported by Nuxt:
97+
// - ref()
98+
// - computed()
99+
// - useSupabaseClient()
100+
// - useLazyAsyncData()
101+
// - definePageMeta()
102+
// and many more...
103+
104+
const searchQuery = ref('') // no import needed
105+
const client = useSupabaseClient<Database>() // no import needed
83106
```
84107

85-
2. Type the Supabase client:
108+
3. Using Supabase client with auto-imports:
86109

87110
```typescript
111+
// Type-safe Supabase client
88112
const client = useSupabaseClient<Database>()
89-
```
90113

91-
3. Use with useLazyAsyncData:
114+
// Async data fetching
92115

93116
```typescript
94117
const { data, pending, error } = await useLazyAsyncData<Project[]>('key', async () => {
@@ -100,7 +123,9 @@ This is a Nuxt 3 + Supabase project using TypeScript
100123
})
101124
```
102125

103-
4. Handle nested relationships:
126+
Note: Ignore Vetur errors about top-level await - this is supported in Nuxt 3.
127+
128+
4. Handling nested relationships:
104129

105130
```typescript
106131
// Example: Fetching projects with tags
@@ -119,6 +144,8 @@ This is a Nuxt 3 + Supabase project using TypeScript
119144

120145
### Best Practices
121146

147+
- Leverage Nuxt's auto-imports to keep components clean
148+
- Only import types explicitly - let Nuxt handle the rest
122149
- Transform data after fetching to match frontend needs
123150
- Use type predicates for filtering:
124151

app.vue

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,3 @@
77
<SiteFooter />
88
</div>
99
</template>
10-
11-
<script setup>
12-
// Import components
13-
import SiteHeader from '~/components/SiteHeader.vue'
14-
import SiteFooter from '~/components/SiteFooter.vue'
15-
</script>

components/FeaturedProjects.vue

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434

3535
<script setup lang="ts">
3636
import type { Project, Database } from '~/types/supabase'
37+
3738
const { data: projects, pending, error } = await useLazyAsyncData<Project[]>('projects', async () => {
3839
const client = useSupabaseClient<Database>()
3940
const { data, error } = await client

components/ProjectsList.vue

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,6 @@
105105
</template>
106106

107107
<script setup lang="ts">
108-
import { ref, computed } from '#imports'
109108
import type { Project, ProjectWithTags, Tag, Database } from '~/types/supabase'
110109
111110
const searchQuery = ref('')

pages/index.vue

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,3 @@
55
<GetInvolved />
66
</div>
77
</template>
8-
9-
<script setup>
10-
// Import components
11-
import HomeHero from '~/components/HomeHero.vue'
12-
import FeaturedProjects from '~/components/FeaturedProjects.vue'
13-
import GetInvolved from '~/components/GetInvolved.vue'
14-
</script>

pages/projects.vue

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@
55
</template>
66

77
<script setup lang="ts">
8-
// Page component for /projects route
98
definePageMeta({
10-
layout: 'default',
119
title: 'Projects - Code for Philly'
1210
})
1311
</script>

0 commit comments

Comments
 (0)