30 lines
861 B
TypeScript
Raw Normal View History

import { PageContext } from "vike/types";
2024-02-22 20:59:20 +00:00
import { render } from "vike/abort";
import trpcServer from "~/server/api/trpc/trpc";
export const data = async (ctx: PageContext) => {
const trpc = await trpcServer(ctx);
2024-02-24 00:27:52 +00:00
const searchParams = ctx.urlParsed.search;
const filesParam = searchParams.files ? searchParams.files.split(",") : null;
2024-02-22 20:59:20 +00:00
const project = await trpc.project.getById(ctx.routeParams?.slug!);
if (!project) {
throw render(404, "Project not found!");
}
const files = await trpc.file.getAll({ projectId: project.id });
2024-02-24 00:27:52 +00:00
const initialFiles = files.filter((i) =>
filesParam != null ? filesParam.includes(i.path) : i.isPinned
);
2024-02-22 20:59:20 +00:00
return {
title: project.title,
description: `Check ${project.title} on CodeShare!`,
project,
files,
2024-02-24 00:27:52 +00:00
initialFiles,
2024-02-22 20:59:20 +00:00
};
};
export type Data = Awaited<ReturnType<typeof data>>;