mirror of
https://github.com/FranP-code/create-better-t-stack.git
synced 2025-10-12 23:52:15 +00:00
add nuxt and expo with orpc
This commit is contained in:
64
apps/cli/templates/examples/ai/web/nuxt/app/pages/ai.vue
Normal file
64
apps/cli/templates/examples/ai/web/nuxt/app/pages/ai.vue
Normal file
@@ -0,0 +1,64 @@
|
||||
<script setup lang="ts">
|
||||
import { ref, watch, nextTick } from 'vue'
|
||||
import { useChat } from '@ai-sdk/vue'
|
||||
|
||||
const config = useRuntimeConfig()
|
||||
const serverUrl = config.public.serverURL
|
||||
|
||||
const { messages, input, handleSubmit } = useChat({
|
||||
api: `${serverUrl}/ai`,
|
||||
})
|
||||
|
||||
const messagesEndRef = ref<null | HTMLDivElement>(null)
|
||||
|
||||
watch(messages, async () => {
|
||||
await nextTick()
|
||||
messagesEndRef.value?.scrollIntoView({ behavior: 'smooth' })
|
||||
})
|
||||
|
||||
// Helper: Concatenate all text parts for a message
|
||||
function getMessageText(message: any) {
|
||||
return message.parts
|
||||
.filter((part: any) => part.type === 'text')
|
||||
.map((part: any) => part.text)
|
||||
.join('')
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="grid grid-rows-[1fr_auto] overflow-hidden w-full mx-auto p-4">
|
||||
<div class="overflow-y-auto space-y-4 pb-4">
|
||||
<div v-if="messages.length === 0" class="text-center text-muted-foreground mt-8">
|
||||
Ask me anything to get started!
|
||||
</div>
|
||||
<div
|
||||
v-for="message in messages"
|
||||
:key="message.id"
|
||||
:class="[
|
||||
'p-3 rounded-lg',
|
||||
message.role === 'user' ? 'bg-primary/10 ml-8' : 'bg-secondary/20 mr-8'
|
||||
]"
|
||||
>
|
||||
<p class="text-sm font-semibold mb-1">
|
||||
{{ message.role === 'user' ? 'You' : 'AI Assistant' }}
|
||||
</p>
|
||||
<div class="whitespace-pre-wrap">{{ getMessageText(message) }}</div>
|
||||
</div>
|
||||
<div ref="messagesEndRef" />
|
||||
</div>
|
||||
|
||||
<form @submit.prevent="handleSubmit" class="w-full flex items-center space-x-2 pt-2 border-t">
|
||||
<UInput
|
||||
name="prompt"
|
||||
v-model="input"
|
||||
placeholder="Type your message..."
|
||||
class="flex-1"
|
||||
autocomplete="off"
|
||||
autofocus
|
||||
/>
|
||||
<UButton type="submit" color="primary" size="md" square>
|
||||
<UIcon name="i-lucide-send" class="w-5 h-5" />
|
||||
</UButton>
|
||||
</form>
|
||||
</div>
|
||||
</template>
|
||||
108
apps/cli/templates/examples/todo/web/nuxt/app/pages/todos.vue
Normal file
108
apps/cli/templates/examples/todo/web/nuxt/app/pages/todos.vue
Normal file
@@ -0,0 +1,108 @@
|
||||
<script setup lang="ts">
|
||||
import { ref } from 'vue'
|
||||
import { useQuery, useMutation, useQueryClient } from '@tanstack/vue-query'
|
||||
|
||||
const { $orpc } = useNuxtApp()
|
||||
|
||||
const newTodoText = ref('')
|
||||
const queryClient = useQueryClient()
|
||||
|
||||
const todos = useQuery($orpc.todo.getAll.queryOptions())
|
||||
|
||||
const createMutation = useMutation($orpc.todo.create.mutationOptions({
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries()
|
||||
newTodoText.value = ''
|
||||
}
|
||||
}))
|
||||
|
||||
const toggleMutation = useMutation($orpc.todo.toggle.mutationOptions({
|
||||
onSuccess: () => queryClient.invalidateQueries()
|
||||
}))
|
||||
|
||||
const deleteMutation = useMutation($orpc.todo.delete.mutationOptions({
|
||||
onSuccess: () => queryClient.invalidateQueries()
|
||||
}))
|
||||
|
||||
function handleAddTodo() {
|
||||
if (newTodoText.value.trim()) {
|
||||
createMutation.mutate({ text: newTodoText.value })
|
||||
}
|
||||
}
|
||||
|
||||
function handleToggleTodo(id: number, completed: boolean) {
|
||||
toggleMutation.mutate({ id, completed: !completed })
|
||||
}
|
||||
|
||||
function handleDeleteTodo(id: number) {
|
||||
deleteMutation.mutate({ id })
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="mx-auto w-full max-w-md py-10">
|
||||
<UCard>
|
||||
<template #header>
|
||||
<div>
|
||||
<div class="text-xl font-bold">Todo List</div>
|
||||
<div class="text-muted text-sm">Manage your tasks efficiently</div>
|
||||
</div>
|
||||
</template>
|
||||
<form @submit.prevent="handleAddTodo" class="mb-6 flex items-center gap-2">
|
||||
<UInput
|
||||
v-model="newTodoText"
|
||||
placeholder="Add a new task..."
|
||||
autocomplete="off"
|
||||
class="w-full"
|
||||
/>
|
||||
<UButton
|
||||
type="submit"
|
||||
icon="i-lucide-plus"
|
||||
>
|
||||
Add
|
||||
</UButton>
|
||||
</form>
|
||||
|
||||
<div v-if="todos.status.value === 'pending'" class="flex justify-center py-4">
|
||||
<UIcon name="i-lucide-loader-2" class="animate-spin w-6 h-6" />
|
||||
</div>
|
||||
<p v-else-if="todos.status.value === 'error'" class="py-4 text-center text-red-500">
|
||||
Error: {{ todos.error.value?.message || 'Failed to load todos' }}
|
||||
</p>
|
||||
<p v-else-if="todos.data.value?.length === 0" class="py-4 text-center">
|
||||
No todos yet. Add one above!
|
||||
</p>
|
||||
<ul v-else class="space-y-2">
|
||||
<li
|
||||
v-for="todo in todos.data.value"
|
||||
:key="todo.id"
|
||||
class="flex items-center justify-between rounded-md border p-2"
|
||||
>
|
||||
<div class="flex items-center gap-2">
|
||||
<UCheckbox
|
||||
:model-value="todo.completed"
|
||||
@update:model-value="() => handleToggleTodo(todo.id, todo.completed)"
|
||||
:id="`todo-${todo.id}`"
|
||||
/>
|
||||
<label
|
||||
:for="`todo-${todo.id}`"
|
||||
:class="{ 'line-through text-muted': todo.completed }"
|
||||
class="cursor-pointer"
|
||||
>
|
||||
{{ todo.text }}
|
||||
</label>
|
||||
</div>
|
||||
<UButton
|
||||
color="neutral"
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
square
|
||||
@click="handleDeleteTodo(todo.id)"
|
||||
aria-label="Delete todo"
|
||||
icon="i-lucide-trash-2"
|
||||
/>
|
||||
</li>
|
||||
</ul>
|
||||
</UCard>
|
||||
</div>
|
||||
</template>
|
||||
Reference in New Issue
Block a user