Compare commits

..

7 Commits

10 changed files with 111 additions and 19 deletions

3
.gitignore vendored
View File

@@ -22,3 +22,6 @@ logs
.env .env
.env.* .env.*
!.env.example !.env.example
# Local DB
.db

View File

@@ -59,6 +59,12 @@ button:active {
transform: translateY(1px); transform: translateY(1px);
} }
#__nuxt {
display: flex;
width: 100%;
height: 100%;
}
#app { #app {
display: flex; display: flex;
width: 100%; width: 100%;

View File

@@ -10,7 +10,8 @@ const props = defineProps<{
<template> <template>
<main id="error-page"> <main id="error-page">
<h1>{{ props.error.name }}</h1> <h1 v-if="props.error.statusCode === 404">404</h1>
<h1 v-else>Error!</h1>
<p>{{ props.error.message }}</p> <p>{{ props.error.message }}</p>
<pre v-if="props.error.stack"> <pre v-if="props.error.stack">
<code>{{ props.error.stack }}</code> <code>{{ props.error.stack }}</code>

View File

@@ -1,7 +1,15 @@
<script setup lang="ts">
const { $trpc } = useNuxtApp();
const { data: contacts } = await $trpc.contactList.useQuery();
</script>
<template> <template>
<div id="app"> <div id="app">
<div id="sidebar"> <div id="sidebar">
<h1>Nuxt Contacts</h1> <h1>
<NuxtLink to="/about">Nuxt Contacts</NuxtLink>
</h1>
<div> <div>
<form id="search-form" role="search"> <form id="search-form" role="search">
<input <input
@@ -22,7 +30,14 @@
</form> </form>
</div> </div>
<nav> <nav>
<ul> <ul v-if="contacts?.length">
<li v-for="contact in contacts" :key="contact.id">
<NuxtLink :to="{name: 'contacts-contactId', params: {contactId: contact.id}}">
<template v-if="contact.first || contact.last">{{ contact.first }} {{ contact.last }}</template>
<i v-else>No Name</i>
<span v-if="contact.favorite"></span>
</NuxtLink>
</li>
<li> <li>
<NuxtLink :to="{name: 'contacts-contactId', params: {contactId: 1}}">Your Name</NuxtLink> <NuxtLink :to="{name: 'contacts-contactId', params: {contactId: 1}}">Your Name</NuxtLink>
</li> </li>
@@ -30,6 +45,7 @@
<NuxtLink :to="{name: 'contacts-contactId', params: {contactId: 2}}">Your Friend</NuxtLink> <NuxtLink :to="{name: 'contacts-contactId', params: {contactId: 2}}">Your Friend</NuxtLink>
</li> </li>
</ul> </ul>
<p v-else><i>No contacts</i></p>
</nav> </nav>
</div> </div>
<div id="detail"> <div id="detail">

View File

@@ -7,4 +7,7 @@ export default defineNuxtConfig({
build: { build: {
transpile: ['trpc-nuxt'] transpile: ['trpc-nuxt']
}, },
routeRules: {
'/about': { prerender: true },
}
}); });

View File

@@ -28,5 +28,11 @@
"devDependencies": { "devDependencies": {
"@types/node": "^22.14.0", "@types/node": "^22.14.0",
"typescript": "^5.8.2" "typescript": "^5.8.2"
},
"pnpm": {
"onlyBuiltDependencies": [
"@parcel/watcher",
"esbuild"
]
} }
} }

51
pages/about.vue Normal file
View File

@@ -0,0 +1,51 @@
<script setup lang="ts">
definePageMeta({
layout: false,
});
</script>
<template>
<div id="about">
<NuxtLink to="/"> Go to demo</NuxtLink>
<h1>About React Router Contacts</h1>
<div>
<p>
This is a demo application showing off some of the
powerful features of React Router, including
dynamic routing, nested routes, loaders, actions,
and more.
</p>
<h2>Features</h2>
<p>
Explore the demo to see how React Router handles:
</p>
<ul>
<li>
Data loading and mutations with loaders and
actions
</li>
<li>
Nested routing with parent/child relationships
</li>
<li>URL-based routing with dynamic segments</li>
<li>Pending and optimistic UI</li>
</ul>
<h2>Learn More</h2>
<p>
Check out the official documentation at{{ " " }}
<a href="https://reactrouter.com">
reactrouter.com
</a>{{ " " }}
to learn more about building great web
applications with React Router.
</p>
</div>
</div>
</template>
<style scoped>
</style>

View File

@@ -1,15 +1,9 @@
<script setup lang="ts"> <script setup lang="ts">
// const route = useRoute(); const { $trpc } = useNuxtApp();
// route.params.contactId const route = useRoute();
const contact = ref({ const { data: contact } = await $trpc.contactGet.useQuery({ contactId: `${route.params.contactId}` });
first: "Your", if (contact.value === null) throw createError({ statusCode: 404, statusMessage: 'Not Found' });
last: "Name",
avatar: "https://placecats.com/200/200",
twitter: "your_handle",
notes: "Some notes",
favorite: true,
});
function deleteSubmit(event: Event) { function deleteSubmit(event: Event) {
const response = window.confirm( const response = window.confirm(

View File

@@ -1,13 +1,16 @@
<script setup lang="ts"> <script setup lang="ts">
// const { $trpc } = useNuxtApp();
//
// const { data: hello } = await $trpc.hello.useQuery({ text: 'client' });
</script> </script>
<template> <template>
<div id="contact"> <p id="index-page">
<p>Home Page!</p> This is a demo for React Router.
</div> <br>
Check out{" "}
<a href="https://reactrouter.com">
the docs at reactrouter.com
</a>
.
</p>
</template> </template>
<style scoped> <style scoped>

View File

@@ -1,5 +1,6 @@
import { publicProcedure, router } from '~/server/trpc/init'; import { publicProcedure, router } from '~/server/trpc/init';
import { z } from 'zod'; import { z } from 'zod';
import { getContact, getContacts } from "~/server/utils/data";
export const appRouter = router({ export const appRouter = router({
hello: publicProcedure.input( hello: publicProcedure.input(
@@ -11,6 +12,14 @@ export const appRouter = router({
greeting: `hello ${opts.input.text}`, greeting: `hello ${opts.input.text}`,
}; };
}), }),
contactList: publicProcedure.query(async () => {
return await getContacts();
}),
contactGet: publicProcedure.input(
z.object({ contactId: z.string() })
).query(async (opts) => {
return await getContact(opts.input.contactId);
}),
}); });
// export type definition of API // export type definition of API