* Merge workspaces across all hosts in the sidebar Replace per-host sidebar sections with a single merged project list. Projects that exist on multiple hosts (matched by projectKey) are collapsed into one row. Host identity is surfaced via: - A status-only footer pill showing online/offline host counts - Hover cards with a mandatory host row on every workspace entry - Subtitles showing the host name when a project spans >1 host - A host filter in the grouping dropdown (not a sidebar switcher) Order and group-mode stores migrated from per-server to global keys with zustand persist migrations. New-workspace screen now shows a merged project list with a host selector combobox. Key files: - workspace-structure.ts: merge algorithm by projectKey - sidebar-view-store.ts / sidebar-order-store.ts: global state - sidebar-workspace-list.tsx: context-based subtitle injection - new-workspace-screen.tsx: host selector in footer row * Add host filtering to the merged sidebar The sidebar now merges workspaces from every connected host, so a single global "active host" no longer fits. Host selection becomes explicit per action via a host chooser, and agent history pages across all hosts at once. Removes the active-host / active-server-id model and the all-agents-list hook that fed it. * Fix rebase fallout: translate archive host error, update stale workspace-key test archiveWorkspacesOptimistically used a raw "Host is not connected" string that the i18n completeness test forbids; route it through i18n.t with the existing hostDisconnected key. The selectors memoization test asserted un-prefixed workspace keys, but merged-sidebar keys are serverId-prefixed. * Fix sidebar review fallout * Address sidebar review followups * Fix sidebar workspace identity migration * Address sidebar review followups * Handle partial host history failures * Fix merged sidebar project removal and E2E drift * Restore history routes and project removal shape * Remove sidebar host context plumbing * Tighten sidebar status and host filter state * Keep new workspace project selection host-compatible * Migrate sidebar view storage * Streamline host selection flows * Update all-host history on archive * Fix empty project sidebar action Code regression: the main merge dropped the empty-project New workspace child row while keeping the empty project persistence contract. Restore the row using the project host target so the sidebar stays aligned with the no-host-selection model. * Fix Japanese shortcut translation key Stale-base integration: main added the Japanese locale after this branch added cycleAgentMode to the English shortcut help map. Merging main exposed the missing ja key in CI typecheck and resources.test. * Fix Playwright speech teardown race
336 lines
10 KiB
TypeScript
336 lines
10 KiB
TypeScript
import { useCallback, useEffect, useMemo, useState, useSyncExternalStore } from "react";
|
|
import { useTranslation } from "react-i18next";
|
|
import { Pressable, Text, View, ScrollView } from "react-native";
|
|
import { useRouter } from "expo-router";
|
|
import { StyleSheet, useUnistyles } from "react-native-unistyles";
|
|
import { QrCode, Link2, ClipboardPaste, ExternalLink, Settings } from "lucide-react-native";
|
|
import { useSafeAreaInsets } from "react-native-safe-area-context";
|
|
import type { HostProfile } from "@/types/host-connection";
|
|
import { getHostRuntimeStore, isHostRuntimeConnected, useHosts } from "@/runtime/host-runtime";
|
|
import { AddHostModal } from "./add-host-modal";
|
|
import { PairLinkModal } from "./pair-link-modal";
|
|
import { Button } from "@/components/ui/button";
|
|
import { resolveAppVersion } from "@/utils/app-version";
|
|
import { formatVersionWithPrefix } from "@/desktop/updates/desktop-updates";
|
|
import { buildOpenProjectRoute } from "@/utils/host-routes";
|
|
import { PaseoLogo } from "@/components/icons/paseo-logo";
|
|
import { openExternalUrl } from "@/utils/open-external-url";
|
|
import { isWeb, isNative } from "@/constants/platform";
|
|
|
|
interface WelcomeAction {
|
|
key: "scan-qr" | "direct-connection" | "paste-pairing-link";
|
|
label: string;
|
|
testID: string;
|
|
primary: boolean;
|
|
icon: typeof QrCode;
|
|
onPress: () => void;
|
|
}
|
|
|
|
const styles = StyleSheet.create((theme) => ({
|
|
root: {
|
|
flex: 1,
|
|
backgroundColor: theme.colors.surface0,
|
|
},
|
|
scrollView: {
|
|
flex: 1,
|
|
},
|
|
container: {
|
|
flexGrow: 1,
|
|
padding: theme.spacing[6],
|
|
paddingBottom: 0,
|
|
alignItems: "center",
|
|
},
|
|
content: {
|
|
width: "100%",
|
|
flexGrow: 1,
|
|
justifyContent: "center",
|
|
alignItems: "center",
|
|
},
|
|
title: {
|
|
color: theme.colors.foreground,
|
|
fontSize: theme.fontSize.xl,
|
|
fontWeight: theme.fontWeight.medium,
|
|
textAlign: "center",
|
|
},
|
|
subtitle: {
|
|
color: theme.colors.foregroundMuted,
|
|
fontSize: theme.fontSize.sm,
|
|
textAlign: "center",
|
|
},
|
|
copyBlock: {
|
|
alignItems: "center",
|
|
gap: theme.spacing[2],
|
|
marginBottom: theme.spacing[12],
|
|
},
|
|
actions: {
|
|
width: "100%",
|
|
maxWidth: 420,
|
|
gap: theme.spacing[3],
|
|
},
|
|
actionButton: {
|
|
flexDirection: "row",
|
|
alignItems: "center",
|
|
justifyContent: "center",
|
|
gap: theme.spacing[3],
|
|
paddingVertical: theme.spacing[4],
|
|
borderRadius: theme.borderRadius.xl,
|
|
backgroundColor: theme.colors.surface2,
|
|
borderWidth: 1,
|
|
borderColor: theme.colors.border,
|
|
},
|
|
actionButtonPrimary: {
|
|
backgroundColor: theme.colors.accent,
|
|
borderColor: theme.colors.accent,
|
|
},
|
|
actionText: {
|
|
color: theme.colors.foreground,
|
|
fontSize: theme.fontSize.base,
|
|
fontWeight: theme.fontWeight.medium,
|
|
},
|
|
actionTextPrimary: {
|
|
color: theme.colors.accentForeground,
|
|
},
|
|
setupLink: {
|
|
flexDirection: "row",
|
|
alignItems: "center",
|
|
justifyContent: "center",
|
|
gap: 6,
|
|
},
|
|
setupLinkText: {
|
|
color: theme.colors.accent,
|
|
fontSize: theme.fontSize.sm,
|
|
fontWeight: theme.fontWeight.medium,
|
|
},
|
|
versionLabel: {
|
|
color: theme.colors.foregroundMuted,
|
|
fontSize: theme.fontSize.xs,
|
|
textAlign: "center",
|
|
marginTop: theme.spacing[6],
|
|
},
|
|
settingsButton: {
|
|
alignSelf: "center",
|
|
marginTop: theme.spacing[6],
|
|
},
|
|
}));
|
|
|
|
function useAnyHostOnline(serverIds: string[]): string | null {
|
|
const runtime = getHostRuntimeStore();
|
|
return useSyncExternalStore(
|
|
(onStoreChange) => runtime.subscribeAll(onStoreChange),
|
|
() => {
|
|
let firstOnlineServerId: string | null = null;
|
|
let firstOnlineAt: string | null = null;
|
|
for (const serverId of serverIds) {
|
|
const snapshot = runtime.getSnapshot(serverId);
|
|
const lastOnlineAt = snapshot?.lastOnlineAt ?? null;
|
|
if (!isHostRuntimeConnected(snapshot) || !lastOnlineAt) {
|
|
continue;
|
|
}
|
|
if (!firstOnlineAt || lastOnlineAt < firstOnlineAt) {
|
|
firstOnlineAt = lastOnlineAt;
|
|
firstOnlineServerId = serverId;
|
|
}
|
|
}
|
|
return firstOnlineServerId;
|
|
},
|
|
() => {
|
|
let firstOnlineServerId: string | null = null;
|
|
let firstOnlineAt: string | null = null;
|
|
for (const serverId of serverIds) {
|
|
const snapshot = runtime.getSnapshot(serverId);
|
|
const lastOnlineAt = snapshot?.lastOnlineAt ?? null;
|
|
if (!isHostRuntimeConnected(snapshot) || !lastOnlineAt) {
|
|
continue;
|
|
}
|
|
if (!firstOnlineAt || lastOnlineAt < firstOnlineAt) {
|
|
firstOnlineAt = lastOnlineAt;
|
|
firstOnlineServerId = serverId;
|
|
}
|
|
}
|
|
return firstOnlineServerId;
|
|
},
|
|
);
|
|
}
|
|
|
|
export interface WelcomeScreenProps {
|
|
onHostAdded?: (profile: HostProfile) => void;
|
|
}
|
|
|
|
export function WelcomeScreen({ onHostAdded }: WelcomeScreenProps) {
|
|
const { theme } = useUnistyles();
|
|
const { t } = useTranslation();
|
|
const insets = useSafeAreaInsets();
|
|
const router = useRouter();
|
|
const appVersion = resolveAppVersion();
|
|
const appVersionText = formatVersionWithPrefix(appVersion);
|
|
const [isDirectOpen, setIsDirectOpen] = useState(false);
|
|
const [isPasteLinkOpen, setIsPasteLinkOpen] = useState(false);
|
|
const hosts = useHosts();
|
|
const anyOnlineServerId = useAnyHostOnline(hosts.map((h) => h.serverId));
|
|
|
|
useEffect(() => {
|
|
if (!anyOnlineServerId) return;
|
|
router.replace(buildOpenProjectRoute());
|
|
}, [anyOnlineServerId, router]);
|
|
|
|
const finishOnboarding = useCallback(() => {
|
|
router.replace(buildOpenProjectRoute());
|
|
}, [router]);
|
|
|
|
const handleOpenPaseoSite = useCallback(() => {
|
|
void openExternalUrl("https://paseo.sh");
|
|
}, []);
|
|
|
|
const handleOpenSettings = useCallback(() => {
|
|
router.push("/settings");
|
|
}, [router]);
|
|
|
|
const handleOpenDirect = useCallback(() => setIsDirectOpen(true), []);
|
|
const handleCloseDirect = useCallback(() => setIsDirectOpen(false), []);
|
|
const handleOpenPasteLink = useCallback(() => setIsPasteLinkOpen(true), []);
|
|
const handleClosePasteLink = useCallback(() => setIsPasteLinkOpen(false), []);
|
|
const handleScanQr = useCallback(() => {
|
|
router.push("/pair-scan?source=onboarding");
|
|
}, [router]);
|
|
|
|
const handleHostSaved = useCallback(
|
|
({ profile }: { profile: HostProfile; serverId: string }) => {
|
|
onHostAdded?.(profile);
|
|
finishOnboarding();
|
|
},
|
|
[onHostAdded, finishOnboarding],
|
|
);
|
|
|
|
const actions: WelcomeAction[] = isWeb
|
|
? [
|
|
{
|
|
key: "direct-connection",
|
|
label: t("pairing.connectionMethods.direct.title"),
|
|
testID: "welcome-direct-connection",
|
|
primary: true,
|
|
icon: Link2,
|
|
onPress: handleOpenDirect,
|
|
},
|
|
{
|
|
key: "paste-pairing-link",
|
|
label: t("pairing.connectionMethods.pasteLink.title"),
|
|
testID: "welcome-paste-pairing-link",
|
|
primary: false,
|
|
icon: ClipboardPaste,
|
|
onPress: handleOpenPasteLink,
|
|
},
|
|
]
|
|
: [
|
|
{
|
|
key: "scan-qr",
|
|
label: t("pairing.connectionMethods.scanQr.title"),
|
|
testID: "welcome-scan-qr",
|
|
primary: true,
|
|
icon: QrCode,
|
|
onPress: handleScanQr,
|
|
},
|
|
{
|
|
key: "direct-connection",
|
|
label: t("pairing.connectionMethods.direct.title"),
|
|
testID: "welcome-direct-connection",
|
|
primary: false,
|
|
icon: Link2,
|
|
onPress: handleOpenDirect,
|
|
},
|
|
{
|
|
key: "paste-pairing-link",
|
|
label: t("pairing.connectionMethods.pasteLink.title"),
|
|
testID: "welcome-paste-pairing-link",
|
|
primary: false,
|
|
icon: ClipboardPaste,
|
|
onPress: handleOpenPasteLink,
|
|
},
|
|
];
|
|
|
|
const scrollContentContainerStyle = useMemo(
|
|
() => [styles.container, { paddingBottom: theme.spacing[6] + insets.bottom }],
|
|
[theme.spacing, insets.bottom],
|
|
);
|
|
|
|
return (
|
|
<View style={styles.root}>
|
|
<ScrollView
|
|
style={styles.scrollView}
|
|
contentContainerStyle={scrollContentContainerStyle}
|
|
showsVerticalScrollIndicator={false}
|
|
testID="welcome-screen"
|
|
>
|
|
<View style={styles.content}>
|
|
<PaseoLogo size={96} />
|
|
<View style={styles.copyBlock}>
|
|
<Text style={styles.title}>{t("onboarding.title")}</Text>
|
|
<Text style={styles.subtitle}>{t("onboarding.subtitle")}</Text>
|
|
{isNative ? (
|
|
<Pressable style={styles.setupLink} onPress={handleOpenPaseoSite}>
|
|
<Text style={styles.setupLinkText}>paseo.sh</Text>
|
|
<ExternalLink size={14} color={theme.colors.accent} />
|
|
</Pressable>
|
|
) : null}
|
|
</View>
|
|
|
|
<View style={styles.actions}>
|
|
{actions.map((action) => (
|
|
<WelcomeActionButton key={action.key} action={action} />
|
|
))}
|
|
</View>
|
|
|
|
<Button
|
|
variant="ghost"
|
|
size="sm"
|
|
leftIcon={Settings}
|
|
onPress={handleOpenSettings}
|
|
style={styles.settingsButton}
|
|
testID="welcome-open-settings"
|
|
>
|
|
{t("onboarding.actions.settings")}
|
|
</Button>
|
|
</View>
|
|
<Text style={styles.versionLabel}>{appVersionText}</Text>
|
|
|
|
<AddHostModal
|
|
visible={isDirectOpen}
|
|
onClose={handleCloseDirect}
|
|
onSaved={handleHostSaved}
|
|
/>
|
|
|
|
<PairLinkModal
|
|
visible={isPasteLinkOpen}
|
|
onClose={handleClosePasteLink}
|
|
onSaved={handleHostSaved}
|
|
/>
|
|
</ScrollView>
|
|
</View>
|
|
);
|
|
}
|
|
|
|
interface WelcomeActionButtonProps {
|
|
action: WelcomeAction;
|
|
}
|
|
|
|
function WelcomeActionButton({ action }: WelcomeActionButtonProps) {
|
|
const { theme } = useUnistyles();
|
|
const Icon = action.icon;
|
|
const buttonStyle = useMemo(
|
|
() => [styles.actionButton, action.primary ? styles.actionButtonPrimary : null],
|
|
[action.primary],
|
|
);
|
|
const textStyle = useMemo(
|
|
() => [styles.actionText, action.primary ? styles.actionTextPrimary : null],
|
|
[action.primary],
|
|
);
|
|
return (
|
|
<Pressable style={buttonStyle} onPress={action.onPress} testID={action.testID}>
|
|
<Icon
|
|
size={18}
|
|
color={action.primary ? theme.colors.accentForeground : theme.colors.foreground}
|
|
/>
|
|
<Text style={textStyle}>{action.label}</Text>
|
|
</Pressable>
|
|
);
|
|
}
|