Files
webstudio/app/shared/db/breakpoints.server.ts
T
Oleg Isonen e3c9eb1447 create root component with styles on a breakpoint
for this we need to create breakpoints first
2022-05-01 23:51:50 +02:00

47 lines
1.1 KiB
TypeScript

import {
initialBreakpoints,
type Project,
type Tree,
type Breakpoint,
} from "@webstudio-is/sdk";
import ObjectId from "bson-objectid";
import { applyPatches, type Patch } from "immer";
import { prisma } from "./prisma.server";
export const load = async (projectId: Project["id"]) => {
return await prisma.breakpoints.findUnique({
where: { projectId },
});
};
export const getBreakpointsWithId = () =>
initialBreakpoints.map((breakpoint) => ({
...breakpoint,
id: ObjectId().toString(),
}));
export const create = async (
projectId: Project["id"],
breakpoints: Array<Breakpoint>
) => {
const data = {
projectId,
values: breakpoints,
};
await prisma.breakpoints.create({ data });
return data;
};
export const patch = async (
{ projectId }: { treeId: Tree["id"]; projectId: Project["id"] },
patches: Array<Patch>
) => {
const breakpoints = await load(projectId);
if (breakpoints === null) return;
const nextBreakpoints = applyPatches(breakpoints.values, patches);
await prisma.breakpoints.update({
where: { projectId: projectId },
data: { values: nextBreakpoints },
});
};