Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
14 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions apps/web/src/cloud/managedRelayState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,10 +190,13 @@ export function useManagedTunnelUsage() {
(environment) => environment.endpoint.providerKind === "cloudflare_tunnel",
).length ?? null);
const cap = t3Chat.accountId !== null && t3Chat.data ? managedTunnelCap(t3Chat.data) : null;
const firstLoad = (query: { accountId: string | null; data: unknown; isPending: boolean }) =>
query.accountId !== null && query.data === null && query.isPending;
return {
used,
limit: cap?.limit ?? null,
upgrade: cap?.upgrade ?? null,
loading: firstLoad(environments) || firstLoad(t3Chat),
refresh: refreshManagedTunnelUsage,
};
}
13 changes: 13 additions & 0 deletions apps/web/src/components/cloud/TunnelUsage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { m, type MessageResolver } from "../../i18n/messages";
import { cn } from "../../lib/utils";
import { Alert, AlertAction, AlertDescription, AlertTitle } from "../ui/alert";
import { Button } from "../ui/button";
import { Skeleton } from "../ui/skeleton";

// Above this, one slot per tunnel is too thin to read, so the bar fills instead.
const MAX_SEGMENTS = 10;
Expand Down Expand Up @@ -40,6 +41,18 @@ export function tunnelUpgradeCopy(
}
}

/** Holds the meter's height while usage loads, so the rows below it stay put. */
export function TunnelUsageMeterSkeleton() {
return (
<div aria-hidden className="flex max-w-sm flex-col gap-1.5">
<div className="flex h-4 items-center">
<Skeleton shape="pill" className="h-3 w-32" />
</div>
<Skeleton shape="pill" className="h-1.5 w-full" />
</div>
);
}

/** "2 of 3 tunnels in use" with one bar slot per tunnel. */
export function TunnelUsageMeter({
used,
Expand Down
26 changes: 24 additions & 2 deletions apps/web/src/components/settings/KeybindingsSettings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
type KeyboardEvent,
type ReactNode,
type RefObject,
useDeferredValue,
useReducer,
useRef,
useState,
Expand Down Expand Up @@ -50,6 +51,7 @@ import { serverEnvironment } from "../../state/server";
import { useSettingsScope } from "./SettingsScopeContext";
import { useClientSettings } from "../../hooks/useSettings";
import { Badge } from "../ui/badge";
import { Skeleton } from "../ui/skeleton";
import { Button } from "../ui/button";
import { Input } from "../ui/input";
import { InputGroup, InputGroupAddon, InputGroupInput } from "../ui/input-group";
Expand Down Expand Up @@ -1463,6 +1465,21 @@ function KeybindingsGroups(props: KeybindingsGroupsProps) {
));
}

function KeybindingsGroupsSkeleton() {
return (
<>
<div aria-hidden className="space-y-2.5">
<Skeleton shape="pill" className="h-3 w-24" />
<Skeleton shape="card" className="h-96" />
</div>
<div aria-hidden className="space-y-2.5">
<Skeleton shape="pill" className="h-3 w-24" />
<Skeleton shape="card" className="h-72" />
</div>
</>
);
}

function BrowserKeybindingNotice() {
const gt = useGT();
const message = gt(
Expand Down Expand Up @@ -1548,6 +1565,9 @@ export function KeybindingsSettingsPanel() {
const { commandOptions, allRows } = useKeybindingCatalog();
const rows = filterKeybindingRows(allRows, query, m);
const groups = groupKeybindingRows(rows);
// Building every row takes a long frame, so the page opens at once and the list fills in
// without blocking input. A search the user types renders the same way.
const shownGroups = useDeferredValue(groups, null);
const anchorIds = keybindingAnchorIds(rows);

const openKeybindingsFile = () => {
Expand Down Expand Up @@ -1744,9 +1764,11 @@ export function KeybindingsSettingsPanel() {
</SettingsGroup>
) : null}

{groups.length > 0 ? (
{shownGroups === null ? (
<KeybindingsGroupsSkeleton />
) : shownGroups.length > 0 ? (
<KeybindingsGroups
groups={groups}
groups={shownGroups}
anchorIds={anchorIds}
savingCommand={savingCommand}
{...rowActions}
Expand Down
4 changes: 3 additions & 1 deletion apps/web/src/components/settings/SavedEnvironmentRows.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ import { useT3ConnectTurnOn } from "~/cloud/useT3ConnectTurnOn";
import { useCloudLinkController } from "~/cloud/useCloudLinkController";
import { useManagedTunnelUsage } from "~/cloud/managedRelayState";
import { useT3ConnectAccountPage } from "../clerk/T3ConnectAccountPages";
import { TunnelLimitAlert, TunnelUsageMeter } from "../cloud/TunnelUsage";
import { TunnelLimitAlert, TunnelUsageMeter, TunnelUsageMeterSkeleton } from "../cloud/TunnelUsage";
import { environmentCatalog } from "~/connection/catalog";
import { readEnvironmentScope } from "~/state/session";
import { type EnvironmentPresentation, useRelayEnvironmentDiscovery } from "~/state/environments";
Expand Down Expand Up @@ -538,6 +538,8 @@ function T3ConnectTunnelUsage({ tunnelLimit }: { readonly tunnelLimit: number |
) : null
}
/>
) : usage.loading ? (
<TunnelUsageMeterSkeleton />
) : null;
return (
<>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { RegistryContext } from "@effect/atom-react";
import * as Effect from "effect/Effect";
import { Atom, AtomRegistry } from "effect/reactivity";
import { AsyncResult, Atom, AtomRegistry } from "effect/reactivity";
import {
DEFAULT_UNIFIED_SETTINGS,
EnvironmentId,
Expand Down Expand Up @@ -71,6 +71,16 @@ const state = vi.hoisted(() => ({
}));
const secondaryId = EnvironmentId.make("secondary");
const permissions = new Map<string, Atom.Writable<boolean>>();
type TaskList = { readonly tasks: ReadonlyArray<ScheduledTask>; readonly timeZone: string };
// The list each machine streams when several are in scope; unset machines are still loading.
const taskLists = new Map<string, Atom.Writable<AsyncResult.AsyncResult<TaskList>>>();
function taskList(id: string) {
const existing = taskLists.get(id);
if (existing) return existing;
const created = Atom.make<AsyncResult.AsyncResult<TaskList>>(AsyncResult.initial());
taskLists.set(id, created);
return created;
}

function setup() {
state.connected = true;
Expand All @@ -82,6 +92,7 @@ function setup() {
state.settings = DEFAULT_UNIFIED_SETTINGS;
state.upsert.mockReset().mockReturnValue(Effect.succeed({ id: task.id }));
permissions.clear();
taskLists.clear();
permissions.set(environmentId, Atom.make(true));
permissions.set(secondaryId, Atom.make(true));
permissions.set("", Atom.make(false));
Expand All @@ -100,6 +111,7 @@ function environment() {
return {
environmentId,
label: "Laptop",
entry: { target: { _tag: "PrimaryConnectionTarget" } },
connection: { phase: state.connected ? "connected" : "disconnected" },
serverConfig: state.connected
? { environment: { platform: "linux", capabilities: { oneTimeSchedules: true } } }
Expand Down Expand Up @@ -140,6 +152,8 @@ vi.mock(import("../../state/server"), async (original) => {
run: state.remove,
},
providersValueAtom: (() => state.providers) as never,
scheduledTasksLive: (({ environmentId }: { environmentId: string }) =>
taskList(environmentId)) as never,
upsertScheduledTask: {
...actual.serverEnvironment.upsertScheduledTask,
run: state.upsert,
Expand Down Expand Up @@ -346,6 +360,35 @@ describe("ScheduledTasksSettings", () => {
await expect.element(page.getByLabelText("Runs on")).toHaveTextContent("Secondary");
});

it("waits for every machine before saying there are no tasks", async () => {
setup();
state.secondary = true;
const registry = AtomRegistry.make();
using _registry = { [Symbol.dispose]: () => registry.dispose() };
registry.set(taskList(secondaryId), AsyncResult.success({ tasks: [], timeZone: "UTC" }));
await using screen = await render(
<RegistryContext.Provider value={registry}>
<ScheduledTasksSettings />
</RegistryContext.Provider>,
);
await expect
.element(screen.getByRole("status", { name: "Loading scheduled tasks…" }))
.toBeVisible();
await expect.element(screen.getByText("No scheduled tasks")).not.toBeInTheDocument();

await act(() =>
registry.set(
taskList(environmentId),
AsyncResult.success({ tasks: [task], timeZone: "UTC" }),
),
);
await expect.element(screen.getByText("Review issues")).toBeVisible();
await expect.element(screen.getByText("No scheduled tasks")).not.toBeInTheDocument();
await expect
.element(screen.getByRole("status", { name: "Loading scheduled tasks…" }))
.not.toBeInTheDocument();
});

it("keeps the permitted representative as the creation target", async () => {
setup();
state.secondary = true;
Expand Down
42 changes: 39 additions & 3 deletions apps/web/src/components/settings/ScheduledTasksSettings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ import { Label } from "../ui/label";
import { Menu, MenuTrigger, MenuPopup, MenuItem, MenuSeparator } from "../ui/menu";
import { ToggleGroup, Toggle } from "../ui/toggle-group";
import { Empty, EmptyHeader, EmptyTitle, EmptyDescription, EmptyMedia } from "../ui/empty";
import { Skeleton } from "../ui/skeleton";
import { ProviderModelPicker } from "../chat/ProviderModelPicker";
import { TraitsPicker } from "../chat/TraitsPicker";
import { createModelSelection } from "@t3tools/shared/model";
Expand Down Expand Up @@ -576,6 +577,9 @@ function ScheduledTaskEnvironmentList({

const loaded = states.filter((state) => state.connected && state.error === null && state.tasks);
const populated = loaded.filter((state) => state.tasks && state.tasks.length > 0);
const loading = states.some((state) => state.connected && state.error === null && !state.tasks);
// Until one machine has tasks to show, rows stand in for the list instead of a status line.
const placeholder = loading && populated.length === 0;
const summaries: Record<string, string[]> = {
"Not connected:": [],
"Loading scheduled tasks on": [],
Expand All @@ -591,7 +595,7 @@ function ScheduledTaskEnvironmentList({
} else if (error !== null) {
summaries["Could not load scheduled tasks:"]!.push(`${label}: ${error}`);
} else if (!tasks) {
summaries["Loading scheduled tasks on"]!.push(label);
if (!placeholder) summaries["Loading scheduled tasks on"]!.push(label);
} else if (tasks.length === 0 && populated.length > 0) {
summaries["No tasks on"]!.push(label);
}
Expand Down Expand Up @@ -639,7 +643,8 @@ function ScheduledTaskEnvironmentList({
role="status"
/>
) : null}
{populated.length === 0 && loaded.length > 0 ? (
{placeholder ? <ScheduledTaskRowsSkeleton /> : null}
{populated.length === 0 && loaded.length > 0 && !loading ? (
<SettingsRow
title={gt("No scheduled tasks")}
description={gt("No tasks match this environment and project selection.")}
Expand Down Expand Up @@ -734,7 +739,7 @@ function ScheduledTaskEnvironmentSection({
) : tasksQuery.error ? (
<SettingsRow title={gt("Could not load scheduled tasks")} description={tasksQuery.error} />
) : !tasks ? (
<SettingsRow title={gt("Loading scheduled tasks…")} role="status" />
<ScheduledTaskRowsSkeleton />
) : (
<>
{taskId && !linkedTask ? (
Expand Down Expand Up @@ -768,6 +773,37 @@ function ScheduledTaskEnvironmentSection({
);
}

const SKELETON_ROWS = [0, 1] as const;

function ScheduledTaskRowsSkeleton() {
const gt = useGT();
return (
<div
role="status"
aria-label={gt("Loading scheduled tasks…")}
className="divide-y divide-border/50"
>
{SKELETON_ROWS.map((row) => (
<div
key={row}
aria-hidden
className="flex items-center justify-between gap-3 px-3 py-3 sm:px-4"
>
<div className="min-w-0 flex-1 space-y-2">
<Skeleton shape="pill" className="h-4 w-40" />
<Skeleton shape="pill" className="h-3 w-full max-w-sm" />
<Skeleton shape="pill" className="h-3 w-48" />
</div>
<div className="flex shrink-0 items-center gap-2">
<Skeleton shape="pill" className="h-5 w-9" />
<Skeleton className="size-7" />
</div>
</div>
))}
</div>
);
}

function ScheduledTaskRow({
environmentId,
task,
Expand Down
3 changes: 2 additions & 1 deletion apps/web/src/components/settings/SettingsFontPreviews.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { DEFAULT_COMPOSER_PLACEHOLDER } from "../../composerPlaceholder";
import { resolveDiffThemeName, type DiffThemeName } from "../../lib/diffRendering";
import { PREFERRED_HIGHLIGHTER } from "../../lib/syntaxHighlighting";
import { GhosttyTerminalSurface } from "~/terminal/ghostty/surface";
import { Skeleton } from "../ui/skeleton";

const PREVIEW_SKILLS: ReadonlyArray<ServerProviderSkill> = [
{ name: "frontend-design", path: ".agents/skills/frontend-design/SKILL.md", enabled: true },
Expand Down Expand Up @@ -122,7 +123,7 @@ export function CodeFontPreview() {
// An appearance switch keeps the previous theme's preview up while the new one renders.
const [htmlByFile, setHtmlByFile] = useState(loadedHtml);
if (loadedHtml !== null && loadedHtml !== htmlByFile) setHtmlByFile(loadedHtml);
if (htmlByFile === null) return null;
if (htmlByFile === null) return <Skeleton shape="card" className="mt-1 mb-2 h-32" />;
return (
<div className="mt-1 mb-2 space-y-2">
{htmlByFile.map((html) => (
Expand Down
5 changes: 3 additions & 2 deletions apps/web/src/components/settings/SettingsScopeNotice.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { resolveEnvironmentMachineKind, type EnvironmentId } from "@t3tools/contracts";
import { useLocation, useNavigate } from "@tanstack/react-router";
import { useNavigate } from "@tanstack/react-router";
import { useGT } from "gt-react";
import { ChevronRightIcon, LayersIcon } from "lucide-react";
import type { ReactNode } from "react";
Expand All @@ -21,6 +21,7 @@ import {
settingsScopeEnvironmentLabels,
settingsScopeProjectMachines,
} from "./settingsScopeAxis";
import { useRenderedSettingsPathname } from "./useRenderedSettingsPathname";
import { SharedTooltipTrigger } from "../ui/shared-tooltip";

interface ScopeChoice {
Expand All @@ -47,7 +48,7 @@ export function SettingsScopeNotice({
const gt = useGT();
const { selectScope, search, groups } = useSettingsScope();
const navigate = useNavigate({ from: "/settings" });
const pathname = useLocation({ select: (location) => location.pathname });
const pathname = useRenderedSettingsPathname();
const { environments } = useEnvironments();
const environmentIcon = (environment: EnvironmentPresentation | undefined) =>
environment ? (
Expand Down
4 changes: 2 additions & 2 deletions apps/web/src/components/settings/SettingsScopeSentence.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { resolveEnvironmentMachineKind } from "@t3tools/contracts";
import { fileDisplayName } from "@t3tools/shared/path";
import { useLocation } from "@tanstack/react-router";
import { CheckIcon, ChevronDownIcon, FolderIcon, LayersIcon } from "lucide-react";
import { Fragment, useState, type ReactNode } from "react";
import { T, useGT, useMessages, Var } from "gt-react";
Expand Down Expand Up @@ -47,6 +46,7 @@ import {
settingsScopeEnvironmentLabels,
settingsScopeProjectMachines,
} from "./settingsScopeAxis";
import { useRenderedSettingsPathname } from "./useRenderedSettingsPathname";

export const SETTINGS_DEVICE_ONLY_PATHS: ReadonlySet<string> = new Set([
"/settings/general",
Expand All @@ -70,7 +70,7 @@ interface SettingsScopeMenuProps {

export function SettingsScopeSentence() {
const scope = useOptionalSettingsScope();
const pathname = useLocation({ select: (location) => location.pathname });
const pathname = useRenderedSettingsPathname();
const { environments } = useEnvironments();
if (scope === null || SETTINGS_DEVICE_ONLY_PATHS.has(pathname)) return null;
const props: SettingsScopeMenuProps = {
Expand Down
Loading
Loading