Skip to content

Commit 31ff57c

Browse files
committed
Devin: type name, known vault name, update username on change
1 parent e59af43 commit 31ff57c

4 files changed

Lines changed: 26 additions & 7 deletions

File tree

apps/obsidian/src/components/DiscourseContextView.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ const DiscourseContext = ({ activeFile }: DiscourseContextProps) => {
253253

254254
{isImported &&
255255
frontmatter.authorName &&
256-
`Vault ${frontmatter.authorName}` !== formattedVaultName && (
256+
frontmatter.authorName !== formattedVaultName && (
257257
<div className="text-modifier-text mt-2 text-xs">
258258
<div>Author: {frontmatter.authorName}</div>
259259
</div>

apps/obsidian/src/components/GeneralSettings.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { useState, useCallback, useRef, useEffect } from "react";
22
import { usePlugin } from "./PluginContext";
33
import { setIcon } from "obsidian";
44
import SuggestInput from "./SuggestInput";
5+
import { updateUsername } from "~/utils/supabaseContext";
56
import { SLACK_LOGO, WHITE_LOGO_SVG } from "~/icons";
67

78
const DOCS_URL = "https://discoursegraphs.com/docs/obsidian";
@@ -206,10 +207,11 @@ const GeneralSettings = () => {
206207
[plugin],
207208
);
208209

209-
const handleSetUsername = (newValue: string) => {
210+
const handleSetUsername = async (newValue: string) => {
210211
setUsername(newValue);
211212
plugin.settings.username = newValue;
212-
void plugin.saveSettings();
213+
await plugin.saveSettings();
214+
await updateUsername(plugin, newValue);
213215
};
214216

215217
return (
@@ -332,7 +334,7 @@ const GeneralSettings = () => {
332334
<input
333335
type="text"
334336
value={username}
335-
onChange={(e) => handleSetUsername(e.target.value)}
337+
onChange={(e) => void handleSetUsername(e.target.value)}
336338
/>
337339
</div>
338340
</div>

apps/obsidian/src/utils/importNodes.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ export const getAvailableGroupIds = async (
3636
return (data || []).map((g) => g.group_id);
3737
};
3838

39-
type publishedNode = {
39+
type PublishedNode = {
4040
source_local_id: string;
4141
space_id: number;
4242
text: string;
@@ -54,7 +54,7 @@ export const getPublishedNodesForGroups = async ({
5454
client: DGSupabaseClient;
5555
groupIds: string[];
5656
currentSpaceId: number;
57-
}): Promise<Array<publishedNode>> => {
57+
}): Promise<Array<PublishedNode>> => {
5858
if (groupIds.length === 0) {
5959
return [];
6060
}
@@ -97,7 +97,7 @@ export const getPublishedNodesForGroups = async ({
9797
groups.get(k)!.push(row);
9898
}
9999

100-
const nodes: Array<publishedNode> = [];
100+
const nodes: Array<PublishedNode> = [];
101101

102102
for (const rows of groups.values()) {
103103
const withDate = rows.filter(

apps/obsidian/src/utils/supabaseContext.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,23 @@ export const getSupabaseContext = async (
122122
return contextCache;
123123
};
124124

125+
export const updateUsername = async (
126+
plugin: DiscourseGraphPlugin,
127+
username: string,
128+
): Promise<void> => {
129+
const context = await getSupabaseContext(plugin);
130+
if (!context) return;
131+
const client = await getLoggedInClient(plugin);
132+
if (!client) return;
133+
const result = await client
134+
.from("PlatformAccount")
135+
.update({ name: username })
136+
.eq("id", context.userId);
137+
if (result.error) {
138+
console.error(result.error);
139+
}
140+
};
141+
125142
let loggedInClient: DGSupabaseClient | null = null;
126143

127144
export const getLoggedInClient = async (

0 commit comments

Comments
 (0)