-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathAdminPanelSettings.tsx
More file actions
53 lines (49 loc) · 1.69 KB
/
AdminPanelSettings.tsx
File metadata and controls
53 lines (49 loc) · 1.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
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<boolean>(
plugin.settings.syncModeEnabled ?? false,
);
const handleSyncModeToggle = useCallback(
async (newValue: boolean) => {
setSyncModeEnabled(newValue);
plugin.settings.syncModeEnabled = newValue;
await plugin.saveSettings();
if (newValue) {
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)}`,
);
}
}
},
[plugin],
);
return (
<div className="general-settings">
<div className="setting-item">
<div className="setting-item-info">
<div className="setting-item-name">(BETA) Sync mode enable</div>
<div className="setting-item-description">
Enable synchronization with Discourse Graph database
</div>
</div>
<div className="setting-item-control">
<div
className={`checkbox-container ${syncModeEnabled ? "is-enabled" : ""}`}
onClick={() => void handleSyncModeToggle(!syncModeEnabled)}
>
<input type="checkbox" checked={syncModeEnabled} />
</div>
</div>
</div>
</div>
);
};