-
- >
- );
-}
-
-export default page;
-
-const content = [
- {
- content:
- "Regional growth patterns diverge, with strong performance in the United States and several emerging markets, contrasted by weaker prospects in many advanced economies, particularly in Europe (World Economic Forum) (OECD). The rapid adoption of artificial intelligence (AI) is expected to drive productivity growth, especially in advanced economies, potentially mitigating labor shortages and boosting income levels in emerging markets (World Economic Forum) (OECD). However, ongoing geopolitical tensions and economic fragmentation are likely to maintain a level of uncertainty and volatility in the global economy (World Economic Forum.",
- icon: AutocompleteIcon,
- iconAlt: "Autocomplete",
- extraInfo:
- "Page Url: https://chatgpt.com/c/762cd44e-1752-495b-967a-aa3c23c6024a",
- },
- {
- content:
- "As of mid-2024, the global economy is experiencing modest growth with significant regional disparities. Global GDP growth is projected to be around 3.1% in 2024, rising slightly to 3.2% in 2025. This performance, although below the pre-pandemic average, reflects resilience despite various economic pressures, including tight monetary conditions and geopolitical tensions (IMF)(OECD) Inflation is moderating faster than expected, with global headline inflation projected to fall to 5.8% in 2024 and 4.4% in 2025, contributing to improving real incomes and positive trade growth (IMF) (OECD)",
- icon: blockIcon,
- iconAlt: "Autocomplete",
- extraInfo:
- "Page Url: https://www.cnbc.com/2024/05/23/nvidia-keeps-hitting-records-can-investors-still-buy-the-stock.html?&qsearchterm=nvidia",
- },
-];
diff --git a/apps/web/app/(canvas)/canvas/layout.tsx b/apps/web/app/(canvas)/canvas/layout.tsx
deleted file mode 100644
index 9bc3b6d7..00000000
--- a/apps/web/app/(canvas)/canvas/layout.tsx
+++ /dev/null
@@ -1,13 +0,0 @@
-import "../canvasStyles.css";
-
-export default function RootLayout({
- children,
-}: {
- children: React.ReactNode;
-}) {
- return (
-
-
{children}
-
- );
-}
diff --git a/apps/web/app/(canvas)/canvas/page.tsx b/apps/web/app/(canvas)/canvas/page.tsx
index 8b5252af..d0824a20 100644
--- a/apps/web/app/(canvas)/canvas/page.tsx
+++ b/apps/web/app/(canvas)/canvas/page.tsx
@@ -1,9 +1,22 @@
-import { redirect } from "next/navigation";
import React from "react";
+import { getCanvas } from "@/app/actions/fetchers";
+import SearchandCreate from "./search&create";
+import ThinkPads from "./thinkPads";
-function page() {
- redirect("/signin");
- return
+
+ >
+ );
+}
+
+const content = [
+ {
+ content:
+ "Regional growth patterns diverge, with strong performance in the United States and several emerging markets, contrasted by weaker prospects in many advanced economies, particularly in Europe (World Economic Forum) (OECD). The rapid adoption of artificial intelligence (AI) is expected to drive productivity growth, especially in advanced economies, potentially mitigating labor shortages and boosting income levels in emerging markets (World Economic Forum) (OECD). However, ongoing geopolitical tensions and economic fragmentation are likely to maintain a level of uncertainty and volatility in the global economy (World Economic Forum.",
+ iconAlt: "Autocomplete",
+ extraInfo:
+ "Page Url: https://chatgpt.com/c/762cd44e-1752-495b-967a-aa3c23c6024a",
+ },
+ {
+ content:
+ "As of mid-2024, the global economy is experiencing modest growth with significant regional disparities. Global GDP growth is projected to be around 3.1% in 2024, rising slightly to 3.2% in 2025. This performance, although below the pre-pandemic average, reflects resilience despite various economic pressures, including tight monetary conditions and geopolitical tensions (IMF)(OECD) Inflation is moderating faster than expected, with global headline inflation projected to fall to 5.8% in 2024 and 4.4% in 2025, contributing to improving real incomes and positive trade growth (IMF) (OECD)",
+ iconAlt: "Autocomplete",
+ extraInfo:
+ "Page Url: https://www.cnbc.com/2024/05/23/nvidia-keeps-hitting-records-can-investors-still-buy-the-stock.html?&qsearchterm=nvidia",
+ },
+];
diff --git a/packages/ui/components/canvas/components/savesnap.tsx b/apps/web/components/canvas/savesnap.tsx
similarity index 55%
rename from packages/ui/components/canvas/components/savesnap.tsx
rename to apps/web/components/canvas/savesnap.tsx
index f82e97e3..a8cacd3e 100644
--- a/packages/ui/components/canvas/components/savesnap.tsx
+++ b/apps/web/components/canvas/savesnap.tsx
@@ -1,27 +1,19 @@
import { useCallback, useEffect, useState } from "react";
-import { debounce, useEditor } from "tldraw";
+import { debounce, getSnapshot, useEditor } from "tldraw";
+import { SaveCanvas } from "@/app/actions/doers";
-export function SaveStatus() {
+export function SaveStatus({ id }: { id: string }) {
const [save, setSave] = useState("saved!");
const editor = useEditor();
const debouncedSave = useCallback(
debounce(async () => {
- const snapshot = editor.store.getSnapshot();
- localStorage.setItem("saved", JSON.stringify(snapshot));
+ const snapshot = getSnapshot(editor.store);
+ const bounds = editor.getViewportPageBounds();
+ console.log(bounds);
- const res = await fetch(
- "https://learning-cf.pruthvirajthinks.workers.dev/post/page3",
- {
- method: "POST",
- headers: { "Content-Type": "application/json" },
- body: JSON.stringify({
- data: snapshot,
- }),
- },
- );
+ SaveCanvas({ id, data: JSON.stringify({ snapshot, bounds }) });
- console.log(await res.json());
setSave("saved!");
}, 3000),
[editor], // Dependency array ensures the function is not recreated on every render
@@ -40,4 +32,4 @@ export function SaveStatus() {
}, [editor, debouncedSave]);
return ;
-}
\ No newline at end of file
+}
diff --git a/packages/ui/components/canvas/components/textCard.tsx b/apps/web/components/canvas/textCard.tsx
similarity index 91%
rename from packages/ui/components/canvas/components/textCard.tsx
rename to apps/web/components/canvas/textCard.tsx
index b24dae52..600dc1a5 100644
--- a/packages/ui/components/canvas/components/textCard.tsx
+++ b/apps/web/components/canvas/textCard.tsx
@@ -25,9 +25,11 @@ export class textCardUtil extends BaseBoxShapeUtil {
height: s.props.h,
width: s.props.w,
pointerEvents: "all",
- background: "#2C3439",
+ background: "#2E3C4C",
borderRadius: "16px",
+ border: "2px solid #3e4449",
padding: "8px 14px",
+ overflow: "auto",
}}
>
{s.props.content}
diff --git a/packages/ui/components/canvas/components/twitterCard.tsx b/apps/web/components/canvas/twitterCard.tsx
similarity index 95%
rename from packages/ui/components/canvas/components/twitterCard.tsx
rename to apps/web/components/canvas/twitterCard.tsx
index c5582a98..8cf8e576 100644
--- a/packages/ui/components/canvas/components/twitterCard.tsx
+++ b/apps/web/components/canvas/twitterCard.tsx
@@ -1,4 +1,9 @@
-import { BaseBoxShapeUtil, HTMLContainer, TLBaseShape, toDomPrecision } from "tldraw";
+import {
+ BaseBoxShapeUtil,
+ HTMLContainer,
+ TLBaseShape,
+ toDomPrecision,
+} from "tldraw";
type ITwitterCardShape = TLBaseShape<
"Twittercard",
diff --git a/apps/web/env.d.ts b/apps/web/env.d.ts
index ee41239f..d52ab7b5 100644
--- a/apps/web/env.d.ts
+++ b/apps/web/env.d.ts
@@ -5,4 +5,5 @@ interface CloudflareEnv {
STORAGE: R2Bucket;
DATABASE: D1Database;
DEV_IMAGES: R2Bucket;
+ CANVAS_SNAPS: KVNamespace;
}
diff --git a/packages/ui/components/canvas/lib/context.ts b/apps/web/lib/context.ts
similarity index 69%
rename from packages/ui/components/canvas/lib/context.ts
rename to apps/web/lib/context.ts
index 4e6ecd1c..840c0d31 100644
--- a/packages/ui/components/canvas/lib/context.ts
+++ b/apps/web/lib/context.ts
@@ -1,4 +1,4 @@
-import { createContext, useContext } from 'react';
+import { createContext, useContext } from "react";
export interface DragContextType {
isDraggingOver: boolean;
@@ -10,9 +10,9 @@ const DragContext = createContext(undefined);
export const useDragContext = () => {
const context = useContext(DragContext);
if (context === undefined) {
- throw new Error('useAppContext must be used within an AppProvider');
+ throw new Error("useAppContext must be used within an AppProvider");
}
return context;
};
-export default DragContext;
\ No newline at end of file
+export default DragContext;
diff --git a/packages/ui/components/canvas/lib/createAssetUrl.ts b/apps/web/lib/createAssetUrl.ts
similarity index 100%
rename from packages/ui/components/canvas/lib/createAssetUrl.ts
rename to apps/web/lib/createAssetUrl.ts
diff --git a/packages/ui/components/canvas/lib/createEmbeds.ts b/apps/web/lib/createEmbeds.ts
similarity index 100%
rename from packages/ui/components/canvas/lib/createEmbeds.ts
rename to apps/web/lib/createEmbeds.ts
diff --git a/apps/web/lib/loadSnap.ts b/apps/web/lib/loadSnap.ts
new file mode 100644
index 00000000..083603eb
--- /dev/null
+++ b/apps/web/lib/loadSnap.ts
@@ -0,0 +1,14 @@
+import { createTLStore, defaultShapeUtils, loadSnapshot } from "tldraw";
+import { getCanvasData } from "../app/actions/fetchers";
+import { twitterCardUtil } from "../components/canvas/twitterCard";
+import { textCardUtil } from "../components/canvas/textCard";
+
+export async function loadRemoteSnapshot(id: string) {
+ const snapshot = await getCanvasData(id);
+
+ const newStore = createTLStore({
+ shapeUtils: [...defaultShapeUtils, twitterCardUtil, textCardUtil],
+ });
+ loadSnapshot(newStore, snapshot.snapshot);
+ return newStore;
+}
diff --git a/apps/web/migrations/000_setup.sql b/apps/web/migrations/0000_bitter_electro.sql
similarity index 85%
rename from apps/web/migrations/000_setup.sql
rename to apps/web/migrations/0000_bitter_electro.sql
index a4855ec9..3ce840e7 100644
--- a/apps/web/migrations/000_setup.sql
+++ b/apps/web/migrations/0000_bitter_electro.sql
@@ -27,6 +27,15 @@ CREATE TABLE `authenticator` (
FOREIGN KEY (`userId`) REFERENCES `user`(`id`) ON UPDATE no action ON DELETE cascade
);
--> statement-breakpoint
+CREATE TABLE `canvas` (
+ `id` text PRIMARY KEY NOT NULL,
+ `title` text DEFAULT 'Untitled' NOT NULL,
+ `description` text DEFAULT 'Untitled' NOT NULL,
+ `url` text DEFAULT '' NOT NULL,
+ `userId` text NOT NULL,
+ FOREIGN KEY (`userId`) REFERENCES `user`(`id`) ON UPDATE no action ON DELETE cascade
+);
+--> statement-breakpoint
CREATE TABLE `chatHistory` (
`id` integer PRIMARY KEY AUTOINCREMENT NOT NULL,
`threadId` text NOT NULL,
@@ -86,7 +95,8 @@ CREATE TABLE `user` (
`name` text,
`email` text NOT NULL,
`emailVerified` integer,
- `image` text
+ `image` text,
+ `telegramId` text
);
--> statement-breakpoint
CREATE TABLE `verificationToken` (
@@ -97,6 +107,7 @@ CREATE TABLE `verificationToken` (
);
--> statement-breakpoint
CREATE UNIQUE INDEX `authenticator_credentialID_unique` ON `authenticator` (`credentialID`);--> statement-breakpoint
+CREATE INDEX `canvas_user_userId` ON `canvas` (`userId`);--> statement-breakpoint
CREATE INDEX `chatHistory_thread_idx` ON `chatHistory` (`threadId`);--> statement-breakpoint
CREATE INDEX `chatThread_user_idx` ON `chatThread` (`userId`);--> statement-breakpoint
CREATE UNIQUE INDEX `space_name_unique` ON `space` (`name`);--> statement-breakpoint
@@ -105,4 +116,7 @@ CREATE INDEX `spaces_user_idx` ON `space` (`user`);--> statement-breakpoint
CREATE INDEX `storedContent_url_idx` ON `storedContent` (`url`);--> statement-breakpoint
CREATE INDEX `storedContent_savedAt_idx` ON `storedContent` (`savedAt`);--> statement-breakpoint
CREATE INDEX `storedContent_title_idx` ON `storedContent` (`title`);--> statement-breakpoint
-CREATE INDEX `storedContent_user_idx` ON `storedContent` (`user`);
+CREATE INDEX `storedContent_user_idx` ON `storedContent` (`user`);--> statement-breakpoint
+CREATE INDEX `users_email_idx` ON `user` (`email`);--> statement-breakpoint
+CREATE INDEX `users_telegram_idx` ON `user` (`telegramId`);--> statement-breakpoint
+CREATE INDEX `users_id_idx` ON `user` (`id`);
\ No newline at end of file
diff --git a/apps/web/migrations/meta/0000_snapshot.json b/apps/web/migrations/meta/0000_snapshot.json
index 291848ad..92a05c00 100644
--- a/apps/web/migrations/meta/0000_snapshot.json
+++ b/apps/web/migrations/meta/0000_snapshot.json
@@ -1,7 +1,7 @@
{
"version": "6",
"dialect": "sqlite",
- "id": "6988522d-8117-484d-b52a-94c0fbd75140",
+ "id": "58ec8bd8-5aad-4ade-a718-74eaf6056d36",
"prevId": "00000000-0000-0000-0000-000000000000",
"tables": {
"account": {
@@ -191,6 +191,69 @@
},
"uniqueConstraints": {}
},
+ "canvas": {
+ "name": "canvas",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "text",
+ "primaryKey": true,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "title": {
+ "name": "title",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": "'Untitled'"
+ },
+ "description": {
+ "name": "description",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": "'Untitled'"
+ },
+ "url": {
+ "name": "url",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": "''"
+ },
+ "userId": {
+ "name": "userId",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ }
+ },
+ "indexes": {
+ "canvas_user_userId": {
+ "name": "canvas_user_userId",
+ "columns": ["userId"],
+ "isUnique": false
+ }
+ },
+ "foreignKeys": {
+ "canvas_userId_user_id_fk": {
+ "name": "canvas_userId_user_id_fk",
+ "tableFrom": "canvas",
+ "tableTo": "user",
+ "columnsFrom": ["userId"],
+ "columnsTo": ["id"],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ }
+ },
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {}
+ },
"chatHistory": {
"name": "chatHistory",
"columns": {
@@ -415,13 +478,6 @@
"primaryKey": false,
"notNull": false,
"autoincrement": false
- },
- "createdAt": {
- "name": "createdAt",
- "type": "integer",
- "primaryKey": false,
- "notNull": true,
- "autoincrement": false
}
},
"indexes": {
@@ -681,5 +737,8 @@
"schemas": {},
"tables": {},
"columns": {}
+ },
+ "internal": {
+ "indexes": {}
}
}
diff --git a/apps/web/migrations/meta/_journal.json b/apps/web/migrations/meta/_journal.json
index 6231765b..b628749f 100644
--- a/apps/web/migrations/meta/_journal.json
+++ b/apps/web/migrations/meta/_journal.json
@@ -1,26 +1,12 @@
{
- "version": "6",
+ "version": "7",
"dialect": "sqlite",
"entries": [
{
"idx": 0,
"version": "6",
- "when": 1719671614406,
- "tag": "0000_classy_speed_demon",
- "breakpoints": true
- },
- {
- "idx": 1,
- "version": "6",
- "when": 1719772835765,
- "tag": "0001_chubby_vulture",
- "breakpoints": true
- },
- {
- "idx": 2,
- "version": "6",
- "when": 1719789157348,
- "tag": "0002_old_titanium_man",
+ "when": 1719619409551,
+ "tag": "0000_bitter_electro",
"breakpoints": true
}
]
diff --git a/apps/web/server/db/schema.ts b/apps/web/server/db/schema.ts
index 2f4c0c41..01cf202d 100644
--- a/apps/web/server/db/schema.ts
+++ b/apps/web/server/db/schema.ts
@@ -201,5 +201,24 @@ export const chatHistory = createTable(
}),
);
+export const canvas = createTable(
+ "canvas",
+ {
+ id: text("id")
+ .notNull()
+ .primaryKey()
+ .$defaultFn(() => crypto.randomUUID()),
+ title: text("title").default("Untitled").notNull(),
+ description: text("description").default("Untitled").notNull(),
+ imageUrl: text("url").default("").notNull(),
+ userId: text("userId")
+ .notNull()
+ .references(() => users.id, { onDelete: "cascade" }),
+ },
+ (canvas) => ({
+ userIdx: index("canvas_user_userId").on(canvas.userId),
+ }),
+);
+
export type ChatThread = typeof chatThreads.$inferSelect;
export type ChatHistory = typeof chatHistory.$inferSelect;
diff --git a/apps/web/tsconfig.json b/apps/web/tsconfig.json
index 63996482..35e6a20c 100644
--- a/apps/web/tsconfig.json
+++ b/apps/web/tsconfig.json
@@ -18,7 +18,8 @@
"**/*.tsx",
".next/types/**/*.ts",
"../../packages/ui/",
- "../../packages/shared-types/utils.ts"
+ "../../packages/shared-types/utils.ts",
+ "./components"
],
"exclude": ["node_modules/"]
}
diff --git a/apps/web/wrangler.toml b/apps/web/wrangler.toml
index 594614c7..a5f9b461 100644
--- a/apps/web/wrangler.toml
+++ b/apps/web/wrangler.toml
@@ -16,6 +16,10 @@ binding = "DATABASE"
database_name = "dev-d1-anycontext"
database_id = "fc562605-157a-4f60-b439-2a24ffed5b4c"
+[[kv_namespaces]]
+binding = "CANVAS_SNAPS"
+id = "c6446f7190dd4afebe1c318df3400518"
+
[[env.production.d1_databases]]
binding = "DATABASE"
database_name = "prod-d1-supermemory"
diff --git a/packages/ui/components/canvas/lib/loadSnap.ts b/packages/ui/components/canvas/lib/loadSnap.ts
deleted file mode 100644
index 846b1967..00000000
--- a/packages/ui/components/canvas/lib/loadSnap.ts
+++ /dev/null
@@ -1,14 +0,0 @@
-import { createTLStore, defaultShapeUtils, loadSnapshot } from "tldraw";
-import { twitterCardUtil } from "../components/twitterCard";
-import { textCardUtil } from "../components/textCard";
-export async function loadRemoteSnapshot() {
- const res = await fetch(
- "https://learning-cf.pruthvirajthinks.workers.dev/get/page3",
- );
- const snapshot = JSON.parse(await res.json());
- const newStore = createTLStore({
- shapeUtils: [...defaultShapeUtils, twitterCardUtil, textCardUtil],
- });
- loadSnapshot(newStore, snapshot);
- return newStore;
-}