Skip to content

Commit 349f842

Browse files
committed
address review comments, wip
1 parent ab6e7ea commit 349f842

3 files changed

Lines changed: 31 additions & 40 deletions

File tree

apps/obsidian/src/components/AdminPanelSettings.tsx

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { useState, useCallback, useEffect } from "react";
1+
import { useState, useCallback } from "react";
22
import { usePlugin } from "./PluginContext";
3-
import { Notice } from "obsidian";
3+
import { Notice, setIcon } from "obsidian";
44
import { updateUsername } from "~/utils/supabaseContext";
55
import { initializeSupabaseSync } from "~/utils/syncDgNodesToSupabase";
66
import { nextRoot } from "@repo/utils/execContext";
@@ -14,18 +14,6 @@ export const AdminPanelSettings = () => {
1414
const [username, setUsername] = useState<string>(
1515
plugin.settings.username || "",
1616
);
17-
const [isLoggedIn, setIsLoggedIn] = useState(false);
18-
useEffect(() => {
19-
if (syncModeEnabled) {
20-
const checkLogin = async () => {
21-
const client = await getLoggedInClient(plugin);
22-
setIsLoggedIn(client !== null);
23-
};
24-
void checkLogin();
25-
} else {
26-
setIsLoggedIn(false);
27-
}
28-
}, [syncModeEnabled, plugin]);
2917

3018
const handleSyncModeToggle = useCallback(
3119
async (newValue: boolean) => {
@@ -57,14 +45,17 @@ export const AdminPanelSettings = () => {
5745

5846
const handleLoginHandoff = async () => {
5947
const client = await getLoggedInClient(plugin);
60-
if (!client) return;
48+
if (!client) {
49+
new Notice("Failed to connect to the database", 3000);
50+
return;
51+
}
6152
const sessionData = await client.auth.getSession();
6253
if (!sessionData.data.session) return;
6354
/* eslint-disable @typescript-eslint/naming-convention */
6455
const { access_token, refresh_token } = sessionData.data.session;
6556
const { data, error } = await client.rpc("create_secret_token", {
6657
v_payload: JSON.stringify({ access_token, refresh_token }),
67-
expiry_interval: "10s",
58+
expiry_interval: "45s",
6859
});
6960
/* eslint-enable @typescript-eslint/naming-convention */
7061
if (error || typeof data !== "string") return;
@@ -110,7 +101,11 @@ export const AdminPanelSettings = () => {
110101
/>
111102
</div>
112103
</div>
113-
<div className={"setting-item " + (isLoggedIn ? "" : "hidden")}>
104+
<div
105+
className={
106+
"setting-item " + (plugin.settings.syncModeEnabled ? "" : "hidden")
107+
}
108+
>
114109
<div className="setting-item-info">
115110
<div className="setting-item-name">Group management</div>
116111
<div className="setting-item-description">
@@ -124,6 +119,10 @@ export const AdminPanelSettings = () => {
124119
}}
125120
>
126121
Manage groups
122+
<span
123+
className="icon"
124+
ref={(el) => (el && setIcon(el, "arrow-up-right")) || undefined}
125+
/>
127126
</button>
128127
</div>
129128
</div>

apps/roam/src/components/settings/AdminPanel.tsx

Lines changed: 8 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useState, useEffect } from "react";
1+
import React, { useState, useEffect, useMemo } from "react";
22
import {
33
Button,
44
HTMLTable,
@@ -267,28 +267,15 @@ const FeatureFlagsTab = (): React.ReactElement => {
267267
const [suggestiveOverlayValue, setSuggestiveOverlayValue] = useState(
268268
getFeatureFlag("Suggestive mode overlay enabled"),
269269
);
270-
const [accessToken, setAccessToken] = useState<string | null>(null);
271-
useEffect(() => {
272-
if (duplicateNodeAlertValue || suggestiveOverlayValue) {
273-
const fetchTokens = async () => {
274-
const client = await getLoggedInClient();
275-
if (client) {
276-
const session = await client.auth.getSession();
277-
if (session.data.session) {
278-
setAccessToken(session.data.session.access_token);
279-
}
280-
}
281-
};
282-
void fetchTokens();
283-
} else {
284-
setAccessToken(null);
285-
}
286-
}, [duplicateNodeAlertValue, suggestiveOverlayValue]);
270+
const syncAlreadyEnabled = useMemo(
271+
() => duplicateNodeAlertValue || suggestiveOverlayValue,
272+
[duplicateNodeAlertValue, suggestiveOverlayValue],
273+
);
287274

288275
const ensureSyncEnabled = (
289276
featureKey: keyof FeatureFlags,
290277
): Promise<boolean> => {
291-
if (duplicateNodeAlertValue || suggestiveOverlayValue) {
278+
if (syncAlreadyEnabled) {
292279
return Promise.resolve(true);
293280
}
294281
setPendingFeatureKey(featureKey);
@@ -315,7 +302,7 @@ const FeatureFlagsTab = (): React.ReactElement => {
315302
const { access_token, refresh_token } = sessionData.data.session;
316303
const { data, error } = await client.rpc("create_secret_token", {
317304
v_payload: JSON.stringify({ access_token, refresh_token }),
318-
expiry_interval: "10s",
305+
expiry_interval: "45s",
319306
});
320307
/* eslint-enable @typescript-eslint/naming-convention */
321308
if (error || typeof data !== "string") return;
@@ -425,7 +412,7 @@ const FeatureFlagsTab = (): React.ReactElement => {
425412
>
426413
Send Error Email
427414
</Button>
428-
{accessToken && (
415+
{syncAlreadyEnabled && (
429416
<Button
430417
className="w-96"
431418
icon="document-open"

apps/website/app/utils/supabase/client.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,13 @@ import { createBrowserClient } from "@supabase/ssr";
22
import type { Database } from "@repo/database/dbTypes";
33

44
export const createClient = () => {
5+
if (
6+
!process.env.NEXT_PUBLIC_SUPABASE_URL ||
7+
!process.env.NEXT_PUBLIC_SUPABASE_PUBLISHABLE_KEY
8+
)
9+
throw new Error("Configuration error: supabase variables not configured.");
510
return createBrowserClient<Database, "public">(
6-
process.env.NEXT_PUBLIC_SUPABASE_URL!,
7-
process.env.NEXT_PUBLIC_SUPABASE_PUBLISHABLE_KEY!,
11+
process.env.NEXT_PUBLIC_SUPABASE_URL,
12+
process.env.NEXT_PUBLIC_SUPABASE_PUBLISHABLE_KEY,
813
);
914
};

0 commit comments

Comments
 (0)