Skip to content

Commit

Permalink
add sample editor
Browse files Browse the repository at this point in the history
  • Loading branch information
Himasnhu-AT committed Sep 29, 2024
1 parent d4b95fa commit 3ede587
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 15 deletions.
1 change: 1 addition & 0 deletions apps/web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"@nextui-org/react": "^2.4.6",
"@radix-ui/react-label": "^2.1.0",
"@tabler/icons-react": "^3.11.0",
"axios": "^1.7.7",
"class-variance-authority": "^0.7.0",
"clsx": "^2.1.1",
"console": "^0.7.2",
Expand Down
21 changes: 13 additions & 8 deletions apps/web/src/app/editor/page.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
import { useEffect, useState } from 'react';
import Head from 'next/head';
import Editor from '../components/Editor';
import { Document } from '../types';
import { fetchDocument } from '../utils/api';
"use client";

import { useEffect, useState } from "react";
import Head from "next/head";
import { fetchDocument } from "@/utils/editor_api";
import Editor from "@/components/editor/editor";
import { Document } from "@/types/editor";

export default function Home() {
const [document, setDocument] = useState<Document | null>(null);

useEffect(() => {
const loadDocument = async () => {
try {
const doc = await fetchDocument('example-document-id');
const doc: Document = await fetchDocument("example-document-id");
setDocument(doc);
} catch (error) {
console.error('Error loading document:', error);
console.error("Error loading document:", error);
}
};

Expand All @@ -24,7 +26,10 @@ export default function Home() {
<div className="container mx-auto px-4">
<Head>
<title>NotionAI Alternative</title>
<meta name="description" content="An open-source NotionAI alternative" />
<meta
name="description"
content="An open-source NotionAI alternative"
/>
<link rel="icon" href="/favicon.ico" />
</Head>

Expand Down
2 changes: 1 addition & 1 deletion apps/web/src/components/editor/BlockComponent.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Block } from "@/types/editor";
import { useState } from "react";
import { Block } from "../types";

interface BlockComponentProps {
block: Block;
Expand Down
8 changes: 4 additions & 4 deletions apps/web/src/components/editor/editor.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { useState } from "react";
import { Document, Block } from "../types";
import BlockComponent from "./BlockComponent";
import { Document, Block } from "@/types/editor";
import Toolbar from "./Toolbar";
import {
updateDocument,
createBlock,
updateBlock,
deleteBlock,
} from "../utils/api";
updateBlock,
updateDocument,
} from "@/utils/editor_api";

interface EditorProps {
initialDocument: Document;
Expand Down
4 changes: 2 additions & 2 deletions apps/web/src/utils/editor_api.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { Document, Block } from "@/types/editor";
import axios from "axios";
import { Document, Block } from "../types";

const API_URL = process.env.NEXT_PUBLIC_API_URL || "http://localhost:3000/api";

export const fetchDocument = async (id: string): Promise<Document> => {
const response = await axios.get(`${API_URL}/documents/${id}`);
return response.data;
return response.data as Document;
};

export const updateDocument = async (
Expand Down

0 comments on commit 3ede587

Please sign in to comment.