Skip to content

Open source website builder and Webflow alternative. Webstudio is an advanced visual builder that connects to any headless CMS, supports all CSS properties, and can be hosted anywhere, including with us.

add breakpoints rest

Oleg Isonen1388f7be67ff
diff --git a/app/routes/rest/breakpoints.$projectId.ts b/app/routes/rest/breakpoints.$projectId.ts
new file mode 100644
index 0000000000..9cd0dea7e2
--- /dev/null
+++ b/app/routes/rest/breakpoints.$projectId.ts
@@ -0,0 +1,23 @@
+import { type LoaderFunction } from "remix";
+import type { Breakpoint } from "@webstudio-is/sdk";
+import * as db from "~/shared/db";
+
+export type ErrorData = {
+ errors: string;
+};
+
+export const loader: LoaderFunction = async ({
+ params,
+}): Promise<Array<Breakpoint> | ErrorData> => {
+ try {
+ const data = await db.breakpoints.load(params.projectId);
+ return data?.values || [];
+ } catch (error) {
+ if (error instanceof Error) {
+ return {
+ errors: error.message,
+ };
+ }
+ }
+ return { errors: "Unexpected error" };
+};
diff --git a/app/shared/db/breakpoints.server.ts b/app/shared/db/breakpoints.server.ts
index 86b79d31dd..8d455c18f1 100644
--- a/app/shared/db/breakpoints.server.ts
+++ b/app/shared/db/breakpoints.server.ts
@@ -8,7 +8,11 @@ import ObjectId from "bson-objectid";
import { applyPatches, type Patch } from "immer";
import { prisma } from "./prisma.server";
-export const load = async (projectId: Project["id"]) => {
+export const load = async (projectId?: Project["id"]) => {
+ if (typeof projectId !== "string") {
+ throw new Error("Project ID required");
+ }
+
return await prisma.breakpoints.findUnique({
where: { projectId },
});