Skip to content

Commit

Permalink
Add draft in table
Browse files Browse the repository at this point in the history
  • Loading branch information
constantgillet committed Apr 28, 2024
1 parent f49c48a commit 1075206
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 2 deletions.
2 changes: 1 addition & 1 deletion app/routes/_app._main-layout.templates.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ const TemplateCard = ({
>
<Link to={`/editor/${template.id}`}>
<img
src={`/api/render/${template.id}`}
src={`/api/render/${template.id}?draft=true`}
width={"full"}
height={"full"}
alt="Og template"
Expand Down
9 changes: 8 additions & 1 deletion app/routes/api.render.$templateId.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ export const loader = async ({ params, request }: LoaderFunctionArgs) => {
const url = new URL(request.url);
const searchParams = url.searchParams;

const isDraft = searchParams.get("draft") === "true";

const variablesValues = [] as { name: string; value: string }[];

searchParams.forEach((value, key) => {
Expand Down Expand Up @@ -105,7 +107,12 @@ export const loader = async ({ params, request }: LoaderFunctionArgs) => {
);
}

tree = template.tree as unknown as Tree;
// If the template is

tree =
template.prodTree === null || isDraft
? (template.tree as unknown as Tree)
: (template.prodTree as unknown as Tree);
} catch (error) {
console.error("Error fetching template", error);
throw json(
Expand Down
2 changes: 2 additions & 0 deletions prisma/migrations/20240428172126_add_prodtree/migration.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-- AlterTable
ALTER TABLE "Template" ADD COLUMN "prodTree" JSONB NOT NULL DEFAULT 'null';
1 change: 1 addition & 0 deletions prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ model Template {
id String @id @unique
name String @unique //Slugname
tree Json
prodTree Json @default("null")
user User @relation(fields: [userId], references: [id])
userId String
Asset Asset[]
Expand Down

0 comments on commit 1075206

Please sign in to comment.