mirror of
https://github.com/khairul169/code-share.git
synced 2026-10-24 11:53:58 +07:00
feat: add project schema
This commit is contained in:
@@ -3,19 +3,15 @@ import { useData } from "~/renderer/hooks";
|
||||
import Link from "~/renderer/link";
|
||||
|
||||
const HomePage = () => {
|
||||
const { posts } = useData<Data>();
|
||||
|
||||
if (!posts?.length) {
|
||||
return <p>No posts.</p>;
|
||||
}
|
||||
const { projects } = useData<Data>();
|
||||
|
||||
return (
|
||||
<div>
|
||||
<h1>Posts</h1>
|
||||
|
||||
{posts.map((post: any) => (
|
||||
<Link key={post.id} href={`/${post.id}`}>
|
||||
{post.title}
|
||||
{projects.map((project: any) => (
|
||||
<Link key={project.id} href={`/${project.slug}`}>
|
||||
{project.title}
|
||||
</Link>
|
||||
))}
|
||||
</div>
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
export const data = async () => {
|
||||
const posts = await fetch(
|
||||
"https://jsonplaceholder.typicode.com/posts?_limit=20"
|
||||
).then((response) => response.json());
|
||||
import { PageContext } from "vike/types";
|
||||
import trpcServer from "~/server/api/trpc/trpc";
|
||||
|
||||
return { posts };
|
||||
export const data = async (ctx: PageContext) => {
|
||||
const trpc = await trpcServer(ctx);
|
||||
|
||||
const projects = await trpc.project.getAll();
|
||||
|
||||
return { projects };
|
||||
};
|
||||
|
||||
export type Data = Awaited<ReturnType<typeof data>>;
|
||||
|
||||
Reference in New Issue
Block a user