Skip to content

Commit cb3f0bf

Browse files
author
Rajat Saxena
committed
migrated to tiptap
1 parent 77896b6 commit cb3f0bf

26 files changed

+8605
-11490
lines changed

apps/web/app/layout.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import "remirror/styles/all.css";
21
import "@courselit/page-blocks/styles.css";
32
import "@courselit/components-library/styles.css";
43
import "@courselit/page-primitives/styles.css";
4+
import "@courselit/text-editor/styles.css";
55
import "../styles/globals.css";
66
import type { Metadata } from "next";
77
import { headers } from "next/headers";

apps/web/components/admin/page-editor/index.tsx

Lines changed: 44 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,10 @@ export default function PageEditor({
125125

126126
const fontString = generateFontString(draftTypefaces);
127127

128+
const fetcher = new FetchBuilder()
129+
.setUrl(`${address.backend}/api/graph`)
130+
.setIsGraphQLEndpoint(true);
131+
128132
useEffect(() => {
129133
loadDraftTypefaces();
130134
loadPage();
@@ -144,11 +148,7 @@ export default function PageEditor({
144148
}
145149
}
146150
`;
147-
const fetch = new FetchBuilder()
148-
.setUrl(`${address.backend}/api/graph`)
149-
.setPayload(query)
150-
.setIsGraphQLEndpoint(true)
151-
.build();
151+
const fetch = fetcher.setPayload(query).build();
152152
try {
153153
setLoadingPages(true);
154154
const response = await fetch.exec();
@@ -292,11 +292,7 @@ export default function PageEditor({
292292
}
293293
}
294294
`;
295-
const fetch = new FetchBuilder()
296-
.setUrl(`${address.backend}/api/graph`)
297-
.setPayload(query)
298-
.setIsGraphQLEndpoint(true)
299-
.build();
295+
const fetch = fetcher.setPayload(query).build();
300296
try {
301297
setLoading(true);
302298
const response = await fetch.exec();
@@ -328,11 +324,7 @@ export default function PageEditor({
328324
refreshLayout?: boolean;
329325
variables?: Record<string, unknown>;
330326
}) => {
331-
const fetch = new FetchBuilder()
332-
.setUrl(`${address.backend}/api/graph`)
333-
.setPayload({ query, variables })
334-
.setIsGraphQLEndpoint(true)
335-
.build();
327+
const fetch = fetcher.setPayload({ query, variables }).build();
336328
try {
337329
setLoading(true);
338330
const response = await fetch.exec();
@@ -468,13 +460,43 @@ export default function PageEditor({
468460
};
469461

470462
const deleteWidget = async (widgetId: string) => {
471-
const widgetIndex = layout.findIndex(
472-
(widget) => widget.widgetId === widgetId,
473-
);
474-
layout.splice(widgetIndex, 1);
475-
setLayout(layout);
476-
onClose();
477-
await savePage({ pageId: page.pageId!, layout });
463+
// const widgetIndex = layout.findIndex(
464+
// (widget) => widget.widgetId === widgetId,
465+
// );
466+
// layout.splice(widgetIndex, 1);
467+
// setLayout(layout);
468+
// onClose();
469+
// await savePage({ pageId: page.pageId!, layout });
470+
const mutation = `
471+
mutation ($pageId: String!, $blockId: String!) {
472+
page: deleteBlock(pageId: $pageId, blockId: $blockId) {
473+
pageId,
474+
draftLayout,
475+
}
476+
}
477+
`;
478+
try {
479+
const fetch = fetcher
480+
.setPayload({
481+
query: mutation,
482+
variables: { pageId: page.pageId!, blockId: widgetId },
483+
})
484+
.build();
485+
const response = await fetch.exec();
486+
if (response.page) {
487+
// setPage(response.page);
488+
setLayout(response.page.draftLayout);
489+
onClose();
490+
}
491+
} catch (err: any) {
492+
toast({
493+
title: TOAST_TITLE_ERROR,
494+
description: err.message,
495+
variant: "destructive",
496+
});
497+
} finally {
498+
setLoading(false);
499+
}
478500
};
479501

480502
const addWidget = async (name: string) => {

apps/web/graphql/pages/logic.ts

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -424,3 +424,39 @@ export const deletePage = async (
424424

425425
return true;
426426
};
427+
428+
export const deleteBlock = async ({
429+
context: ctx,
430+
pageId,
431+
blockId,
432+
}: {
433+
context: GQLContext;
434+
pageId: string;
435+
blockId: string;
436+
}) => {
437+
checkIfAuthenticated(ctx);
438+
if (!checkPermission(ctx.user.permissions, [permissions.manageSite])) {
439+
throw new Error(responses.action_not_allowed);
440+
}
441+
const page: Page | null = await PageModel.findOne({
442+
pageId,
443+
domain: ctx.subdomain._id,
444+
});
445+
446+
if (!page) {
447+
return null;
448+
}
449+
450+
const block = page.draftLayout.find(
451+
(block: any) => block.widgetId === blockId,
452+
);
453+
if (!block) {
454+
return null;
455+
}
456+
457+
page.draftLayout = page.draftLayout.filter(
458+
(block: any) => block.widgetId !== blockId,
459+
);
460+
await (page as any).save();
461+
return getPageResponse(page!, ctx);
462+
};

apps/web/graphql/pages/mutation.ts

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
import { GraphQLBoolean, GraphQLNonNull, GraphQLString } from "graphql";
22
import GQLContext from "../../models/GQLContext";
3-
import { updatePage, createPage, deletePage, publish } from "./logic";
3+
import {
4+
updatePage,
5+
createPage,
6+
deletePage,
7+
publish,
8+
deleteBlock,
9+
} from "./logic";
410
import types from "./types";
511
import constants from "../../config/constants";
612
const { defaultPages } = constants;
@@ -89,6 +95,18 @@ const mutations = {
8995
context: GQLContext,
9096
) => deletePage(context, id),
9197
},
98+
deleteBlock: {
99+
type: types.page,
100+
args: {
101+
pageId: { type: new GraphQLNonNull(GraphQLString) },
102+
blockId: { type: new GraphQLNonNull(GraphQLString) },
103+
},
104+
resolve: async (
105+
_: any,
106+
{ pageId, blockId }: { pageId: string; blockId: string },
107+
context: GQLContext,
108+
) => deleteBlock({ context, pageId, blockId }),
109+
},
92110
};
93111

94112
export default mutations;

0 commit comments

Comments
 (0)