mirror of
https://github.com/block/buzz.git
synced 2026-12-01 13:42:45 +00:00
Fix SPROUT_SHARE_IDENTITY worktree dev workflow breaks (#702)
This commit is contained in:
@@ -4,13 +4,7 @@ import { getIdentity } from "@/shared/api/tauri";
|
||||
import { Button } from "@/shared/ui/button";
|
||||
import { Input } from "@/shared/ui/input";
|
||||
|
||||
import type { Workspace } from "../types";
|
||||
import {
|
||||
deriveWorkspaceName,
|
||||
normalizeRelayUrl,
|
||||
saveActiveWorkspaceId,
|
||||
saveWorkspaces,
|
||||
} from "../workspaceStorage";
|
||||
import { initFirstWorkspace, deriveWorkspaceName } from "../workspaceStorage";
|
||||
|
||||
const LOCAL_RELAY_URL = "ws://localhost:3000";
|
||||
|
||||
@@ -35,7 +29,6 @@ export function WelcomeSetup({
|
||||
return;
|
||||
}
|
||||
|
||||
const normalizedUrl = normalizeRelayUrl(trimmedUrl);
|
||||
setIsConnecting(true);
|
||||
setError(null);
|
||||
|
||||
@@ -44,17 +37,7 @@ export function WelcomeSetup({
|
||||
// labels, etc.). The private key lives on disk in `identity.key` and
|
||||
// is the single source of truth — never copied into localStorage.
|
||||
const identity = await getIdentity();
|
||||
|
||||
const workspace: Workspace = {
|
||||
id: crypto.randomUUID(),
|
||||
name: deriveWorkspaceName(normalizedUrl),
|
||||
relayUrl: normalizedUrl,
|
||||
pubkey: identity.pubkey,
|
||||
addedAt: new Date().toISOString(),
|
||||
};
|
||||
|
||||
saveWorkspaces([workspace]);
|
||||
saveActiveWorkspaceId(workspace.id);
|
||||
initFirstWorkspace(trimmedUrl, identity.pubkey);
|
||||
|
||||
// The reload triggered by onComplete() will re-run useWorkspaceInit,
|
||||
// which calls applyWorkspace with the saved config. No need to apply here.
|
||||
|
||||
@@ -1,12 +1,17 @@
|
||||
import { useEffect, useRef, useState } from "react";
|
||||
|
||||
import { relayClient } from "@/shared/api/relayClient";
|
||||
import { applyWorkspace, getDefaultRelayUrl } from "@/shared/api/tauri";
|
||||
import {
|
||||
applyWorkspace,
|
||||
getDefaultRelayUrl,
|
||||
getIdentity,
|
||||
} from "@/shared/api/tauri";
|
||||
import { resetMediaCaches } from "@/shared/lib/mediaUrl";
|
||||
import { clearSearchHitEventCache } from "@/app/navigation/searchHitEventCache";
|
||||
import { clearAllDrafts } from "@/features/messages/lib/useDrafts";
|
||||
import { resetAgentObserverStore } from "@/features/agents/observerRelayStore";
|
||||
|
||||
import { initFirstWorkspace } from "./workspaceStorage";
|
||||
import type { Workspace } from "./types";
|
||||
|
||||
/**
|
||||
@@ -43,6 +48,7 @@ type WorkspaceInitResult =
|
||||
export function useWorkspaceInit(
|
||||
activeWorkspace: Workspace | null,
|
||||
workspaceKey: string,
|
||||
isSharedIdentity: boolean,
|
||||
): WorkspaceInitResult {
|
||||
const [result, setResult] = useState<WorkspaceInitResult>({
|
||||
isReady: false,
|
||||
@@ -60,9 +66,19 @@ export function useWorkspaceInit(
|
||||
|
||||
async function init() {
|
||||
if (!activeWorkspace) {
|
||||
// No workspace — need setup
|
||||
try {
|
||||
const defaultRelayUrl = await getDefaultRelayUrl();
|
||||
|
||||
if (isSharedIdentity) {
|
||||
const identity = await getIdentity();
|
||||
if (cancelled) return;
|
||||
initFirstWorkspace(defaultRelayUrl, identity.pubkey);
|
||||
if (!cancelled) {
|
||||
window.location.reload();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (!cancelled) {
|
||||
setResult({
|
||||
isReady: false,
|
||||
@@ -136,6 +152,7 @@ export function useWorkspaceInit(
|
||||
activeWorkspace?.id,
|
||||
activeWorkspace?.relayUrl,
|
||||
activeWorkspace?.token,
|
||||
isSharedIdentity,
|
||||
workspaceKey,
|
||||
]);
|
||||
|
||||
|
||||
@@ -79,3 +79,20 @@ export function deriveWorkspaceName(relayUrl: string): string {
|
||||
return "Workspace";
|
||||
}
|
||||
}
|
||||
|
||||
export function initFirstWorkspace(
|
||||
relayUrl: string,
|
||||
pubkey: string,
|
||||
): Workspace {
|
||||
const normalizedUrl = normalizeRelayUrl(relayUrl);
|
||||
const workspace: Workspace = {
|
||||
id: crypto.randomUUID(),
|
||||
name: deriveWorkspaceName(normalizedUrl),
|
||||
relayUrl: normalizedUrl,
|
||||
pubkey,
|
||||
addedAt: new Date().toISOString(),
|
||||
};
|
||||
saveWorkspaces([workspace]);
|
||||
saveActiveWorkspaceId(workspace.id);
|
||||
return workspace;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user