diff --git a/apps/obsidian/package.json b/apps/obsidian/package.json index c8171caee..6b70f9052 100644 --- a/apps/obsidian/package.json +++ b/apps/obsidian/package.json @@ -37,6 +37,9 @@ }, "dependencies": { "@codemirror/view": "^6.38.8", + "@repo/database": "workspace:*", + "@repo/utils": "workspace:*", + "@supabase/supabase-js": "catalog:", "date-fns": "^4.1.0", "nanoid": "^4.0.2", "react": "catalog:obsidian", diff --git a/apps/obsidian/scripts/compile.ts b/apps/obsidian/scripts/compile.ts index 04ea91aee..e749cb6af 100644 --- a/apps/obsidian/scripts/compile.ts +++ b/apps/obsidian/scripts/compile.ts @@ -1,3 +1,4 @@ +/* eslint-disable @typescript-eslint/naming-convention */ import esbuild from "esbuild"; import fs from "fs"; import path from "path"; @@ -10,6 +11,19 @@ import autoprefixer from "autoprefixer"; dotenv.config(); +// For local dev: Set SUPABASE_USE_DB=local and run `pnpm run genenv` in packages/database +let envContents: (() => Record) | null = null; +try { + const dbDotEnv = require("@repo/database/dbDotEnv"); + envContents = dbDotEnv.envContents; +} catch (error) { + if ((error as Error).message.includes("Cannot find module")) { + console.error("Build the database module before compiling obsidian"); + process.exit(1); + } + throw error; +} + const DEFAULT_FILES_INCLUDED = ["manifest.json"]; const isProd = process.env.NODE_ENV === "production"; @@ -43,6 +57,7 @@ export const args = { "@lezer/common", "@lezer/highlight", "@lezer/lr", + "tslib=window.TSLib", ...builtins, ], } as CliOpts; @@ -89,6 +104,10 @@ export const compile = ({ fs.mkdirSync(outdir, { recursive: true }); const buildPromises = [] as Promise[]; + if (!envContents) { + throw new Error("envContents not loaded. Build the database module first."); + } + const dbEnv = envContents(); buildPromises.push( builder({ absWorkingDir: process.cwd(), @@ -100,6 +119,15 @@ export const compile = ({ minify: isProd, entryNames: out, external: external, + define: { + "process.env.SUPABASE_URL": dbEnv.SUPABASE_URL + ? `"${dbEnv.SUPABASE_URL}"` + : "null", + "process.env.SUPABASE_ANON_KEY": dbEnv.SUPABASE_ANON_KEY + ? `"${dbEnv.SUPABASE_ANON_KEY}"` + : "null", + "process.env.NEXT_API_ROOT": `"${dbEnv.NEXT_API_ROOT || ""}"`, + }, plugins: [ { name: "log", diff --git a/apps/obsidian/src/components/AdminPanelSettings.tsx b/apps/obsidian/src/components/AdminPanelSettings.tsx index 80e24ce8e..66f6ee70b 100644 --- a/apps/obsidian/src/components/AdminPanelSettings.tsx +++ b/apps/obsidian/src/components/AdminPanelSettings.tsx @@ -1,20 +1,57 @@ -import { useState } from "react"; +import { useState, useCallback } from "react"; import { usePlugin } from "./PluginContext"; import { Notice } from "obsidian"; +import { initializeSupabaseSync } from "~/utils/syncDgNodesToSupabase"; export const AdminPanelSettings = () => { const plugin = usePlugin(); + const [syncModeEnabled, setSyncModeEnabled] = useState( + plugin.settings.syncModeEnabled ?? false, + ); const [hasUnsavedChanges, setHasUnsavedChanges] = useState(false); + const handleSyncModeToggle = useCallback((newValue: boolean) => { + setSyncModeEnabled(newValue); + setHasUnsavedChanges(true); + }, []); + const handleSave = async () => { + plugin.settings.syncModeEnabled = syncModeEnabled; await plugin.saveSettings(); new Notice("Admin panel settings saved"); setHasUnsavedChanges(false); + + if (syncModeEnabled) { + try { + await initializeSupabaseSync(plugin); + new Notice("Sync mode initialized successfully"); + } catch (error) { + console.error("Failed to initialize sync mode:", error); + new Notice( + `Failed to initialize sync mode: ${error instanceof Error ? error.message : String(error)}`, + ); + } + } }; return (
- {/* Add more admin panel settings sections here */} +
+
+
(BETA) Sync mode enable
+
+ Enable synchronization with Discourse Graph database +
+
+
+
handleSyncModeToggle(!syncModeEnabled)} + > + +
+
+