Skip to content

Commit

Permalink
Merge pull request #17 from git-init-priyanshu/nextjs
Browse files Browse the repository at this point in the history
Fixed saving bug & test
  • Loading branch information
git-init-priyanshu authored Aug 18, 2024
2 parents 6f12827 + 9f5520f commit b52fe54
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 32 deletions.
20 changes: 10 additions & 10 deletions app/writer/[id]/editor/editorConfig.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Color } from '@tiptap/extension-color'
import { WebsocketProvider } from 'y-websocket'
// import { WebsocketProvider } from 'y-websocket'
import Collaboration from '@tiptap/extension-collaboration'
import StarterKit from '@tiptap/starter-kit'
import Highlight from '@tiptap/extension-highlight'
Expand All @@ -13,16 +13,16 @@ import { cn } from '@/lib/utils'

export const ydoc = new Y.Doc();

const room = `room.${new Date()
.getFullYear()
.toString()
.slice(-2)}${new Date().getMonth() + 1}${new Date().getDate()}`
// const room = `room.${new Date()
// .getFullYear()
// .toString()
// .slice(-2)}${new Date().getMonth() + 1}${new Date().getDate()}`

export const provider = new WebsocketProvider(
process.env.NEXT_PUBLIC_WEBSOCKET_URL as string,
room,
ydoc
);
// export const provider = new WebsocketProvider(
// process.env.NEXT_PUBLIC_WEBSOCKET_URL as string,
// room,
// ydoc
// );

export const extensions = [
StarterKit.configure({
Expand Down
43 changes: 21 additions & 22 deletions app/writer/[id]/page.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
"use client"

import {
useState,
useMemo,
Expand All @@ -13,18 +12,18 @@ import { EditorContent } from '@tiptap/react'
import { useEditor } from "@tiptap/react"
import { debounce } from 'lodash'
import html2canvas from 'html2canvas'
import CollaborationCursor from '@tiptap/extension-collaboration-cursor'
// import CollaborationCursor from '@tiptap/extension-collaboration-cursor'

import { ScrollArea } from "@/components/ui/scroll-area"
import { getRandomColor } from '@/helpers/getRandomColor'
// import { getRandomColor } from '@/helpers/getRandomColor'

import { FormatOptions, InsertOptions } from "./components/options"
import Header from "./components/Header/Header"
import Tabs from "./components/Tabs"
import Loading from './components/EditorLoading'

import {
provider,
// provider,
extensions,
props
} from './editor/editorConfig'
Expand Down Expand Up @@ -63,8 +62,7 @@ export default function Dashboard() {
const createDocThumbnail = async () => {
try {
const page = document.getElementsByClassName("tiptap")[0];
if (!page) return;

if (!page) return setIsSaving(false);
// @ts-ignore
const canvas = await html2canvas(page, { scale: 1 })

Expand All @@ -82,7 +80,7 @@ export default function Dashboard() {
const res = await upload.json();
const url = res.data.display_url;

if (!session?.id) return;
if (!session?.id) return setIsSaving(false);
await UpdateThumbnail(params.id, session.id, url)

setIsSaving(false);
Expand All @@ -95,7 +93,7 @@ export default function Dashboard() {

const saveDoc = useCallback((editor: any) => {
setIsSaving(true);
if (!session?.id) return;
if (!session?.id) return setIsSaving(false);

UpdateDocData(params.id, session.id, JSON.stringify(editor.getJSON()));
createDocThumbnail();
Expand All @@ -107,26 +105,27 @@ export default function Dashboard() {
);

const editor = useEditor({
onCreate: ({ editor: currentEditor }) => {
provider.on('synced', () => {
if (currentEditor.isEmpty) {
currentEditor.commands.setContent("")
}
})
},
// onCreate: ({ editor: currentEditor }) => {
// provider.on('synced', () => {
// if (currentEditor.isEmpty) {
// currentEditor.commands.setContent("")
// }
// })
// },
extensions: [
...extensions,
CollaborationCursor.configure({
provider,
user: {
name: localStorage.getItem('name'),
color: getRandomColor()
}
}),
// CollaborationCursor.configure({
// provider,
// user: {
// name: localStorage.getItem('name'),
// color: getRandomColor()
// }
// }),
],
editorProps: props,
content: "",
onUpdate({ editor }) {
console.log("update")
debouncedSaveDoc(editor);
},
});
Expand Down

0 comments on commit b52fe54

Please sign in to comment.