Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
30 changes: 1 addition & 29 deletions apps/web/src/components/composer.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ArrowUp, X, type LucideIcon } from "lucide-react";
import { ArrowUp } from "lucide-react";
import type { ReactNode, Ref } from "react";

import { cn } from "@/lib/utils";
Expand Down Expand Up @@ -101,34 +101,6 @@ export function Composer({
);
}

export function ComposerHeader({
title,
icon: Icon,
onClose,
}: {
readonly title: string;
readonly icon: LucideIcon;
readonly onClose?: () => void;
}) {
return (
<div className="flex h-pane items-center gap-2 px-3 text-ui text-ink-muted">
<Icon className="size-3.5" aria-hidden />
<span className="flex-1 font-medium">{title}</span>
{onClose !== undefined && (
<button
type="button"
onClick={onClose}
aria-label="Minimize reply"
className="flex items-center gap-2 rounded-md p-1 text-ink-muted outline-none hover:bg-ink/5 hover:text-ink focus-visible:ring-2 focus-visible:ring-ring press"
>
<kbd className="text-[10px]">esc</kbd>
<X className="size-3.5" aria-hidden />
</button>
)}
</div>
);
}

export function ComposerSubmit({
label,
disabled,
Expand Down
28 changes: 28 additions & 0 deletions apps/web/src/components/loader.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
const pixels = [
[0, 0],
[6, 0],
[12, 0],
[12, 6],
[12, 12],
[6, 12],
[0, 12],
[0, 6],
] as const;

export function PixelLoader() {
return (
<svg viewBox="0 0 16 16" className="size-3" fill="currentColor" shapeRendering="crispEdges" aria-hidden>
{pixels.map(([x, y], index) => (
<rect
key={`${x},${y}`}
x={x}
y={y}
width="4"
height="4"
className="pixel-loader-cell"
style={{ animationDelay: `${index * 120 - 960}ms`, opacity: 1 - index / 10 }}
/>
))}
</svg>
);
}
17 changes: 17 additions & 0 deletions apps/web/src/components/logo.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { cn } from "@/lib/utils";

/** The pixel C and square dot from the site's brand/logo.svg. */
export function Logo({ className }: { readonly className?: string }) {
return (
<svg
viewBox="0 0 10 10"
fill="currentColor"
shapeRendering="crispEdges"
className={cn("size-3.5 shrink-0 text-ink", className)}
aria-hidden
>
<path d="M0 0h10v2H2v6h8v2H0Z" />
<rect x="8" y="4" width="2" height="2" />
</svg>
);
}
6 changes: 5 additions & 1 deletion apps/web/src/components/ui/sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { PanelLeftIcon } from "lucide-react";
import { Slot } from "radix-ui";

import { useIsMobile } from "@/hooks/use-mobile";
import { useScrollFade } from "@/hooks/use-scroll-fade";
import { Button } from "@/components/ui/button";
import { Input } from "@/components/ui/input";
import { Separator } from "@/components/ui/separator";
Expand Down Expand Up @@ -437,12 +438,15 @@ function SidebarSeparator({ className, ...props }: React.ComponentProps<typeof S
}

function SidebarContent({ className, ...props }: React.ComponentProps<"div">) {
const viewport = React.useRef<HTMLDivElement>(null);
useScrollFade(viewport);
return (
<div
ref={viewport}
data-slot="sidebar-content"
data-sidebar="content"
className={cn(
"flex min-h-0 flex-1 flex-col gap-2 overflow-auto group-data-[collapsible=icon]:overflow-hidden",
"scroll-fade flex min-h-0 flex-1 flex-col gap-2 overflow-auto [scrollbar-width:none] group-data-[collapsible=icon]:overflow-hidden [&::-webkit-scrollbar]:hidden",
className,
)}
{...props}
Expand Down
24 changes: 0 additions & 24 deletions apps/web/src/components/ui/switch.tsx

This file was deleted.

32 changes: 32 additions & 0 deletions apps/web/src/hooks/use-scroll-fade.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { useLayoutEffect, type RefObject } from "react";

export function useScrollFade(viewport: RefObject<HTMLElement | null>) {
useLayoutEffect(() => {
const element = viewport.current;
if (element === null) return;
const update = () => {
element.style.setProperty("--scroll-top", element.scrollTop > 1 ? "transparent" : "black");
element.style.setProperty(
"--scroll-bottom",
element.scrollTop + element.clientHeight < element.scrollHeight - 1 ? "transparent" : "black",
);
};
const resize = new ResizeObserver(update);
const observe = () => {
resize.disconnect();
resize.observe(element);
for (const child of element.children) resize.observe(child);
update();
};
const mutations = new MutationObserver(observe);
// Direct children only: their ResizeObserver entries already catch anything nested growing.
mutations.observe(element, { childList: true });
element.addEventListener("scroll", update, { passive: true });
observe();
return () => {
resize.disconnect();
mutations.disconnect();
element.removeEventListener("scroll", update);
};
}, [viewport]);
}
2 changes: 1 addition & 1 deletion apps/web/src/kernel/servers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export interface Problem {
}

/** The default server's problem from its status; undefined while the app can work with it. */
export function problemOf(status: ServerStatus): Problem | undefined {
function problemOf(status: ServerStatus): Problem | undefined {
const { cli, server } = status;
// An already running, compatible server is usable even without a local CLI.
if (server._tag === "Running") return undefined;
Expand Down
7 changes: 5 additions & 2 deletions apps/web/src/landing/landing.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { NoticeSlot } from "@/components/banner";
import { Composer, ComposerSubmit } from "@/components/composer";
import { makeHost } from "../kernel/host";
import { sessionAddress } from "../widgets/session/address";
import { handoffs } from "../widgets/session/handoff";
import { Json, type Place as Where, topics } from "../widgets/session/schema";
import { useOpenElsewhere } from "../wm/open";
import { ModelPicker, ThinkingPicker, useChoice, useModelsNotice } from "@/components/model";
Expand Down Expand Up @@ -50,13 +51,14 @@ export function Landing() {
const where: Where = { _tag: "Folder", path: place.path };
setPending(true);
setError(undefined);
const prompt = { id: crypto.randomUUID(), text: query.trim(), createdAt: Date.now() };
const created = await bus
.request({
topic: topics.create,
payload: encodeCreate({
place: where,
messageId: crypto.randomUUID(),
text: query.trim(),
messageId: prompt.id,
text: prompt.text,
...(model === undefined ? {} : { model }),
...(thinking === undefined ? {} : { thinkingLevel: thinking }),
}),
Expand All @@ -68,6 +70,7 @@ export function Landing() {
setError(created?.message ?? "The CodeWork server is not reachable.");
return;
}
handoffs.set(created.sessionId, prompt);
refreshProjects();
await openElsewhere(sessionAddress(created.sessionId), placeLabel(place), "replace");
};
Expand Down
122 changes: 80 additions & 42 deletions apps/web/src/landing/sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import { PlusSignIcon, Search01Icon, Settings02Icon, SquarePenIcon } from "@huge
import { HugeiconsIcon } from "@hugeicons/react";
import { Link, useNavigate, useParams } from "@tanstack/react-router";
import { AsyncResult } from "effect/reactivity";
import { type MouseEvent, useMemo, useState } from "react";
import type { Project } from "@codeworksh/contract";
import { type MouseEvent, memo, useCallback, useLayoutEffect, useMemo, useRef, useState } from "react";

import {
Sidebar,
Expand All @@ -15,7 +16,7 @@ import {
} from "@/components/ui/sidebar";
import { isMac, openMode } from "@codeworksh/widget/view";
import { sessionAddress } from "../widgets/session/address";
import { projectsAtom } from "../widgets/session/projects";
import { projectsAtom, workingAtom } from "../widgets/session/projects";
import { focusedAtom } from "../wm/chrome";
import { deskAtom } from "../wm/instances";
import { useOpenElsewhere } from "../wm/open";
Expand All @@ -27,6 +28,7 @@ import { problemAtom } from "../kernel/servers";
import { Empty, EmptyAction } from "./empty";
import { useAddProject } from "../shell/palette";
import { placeAtom } from "./place";
import { PixelLoader } from "@/components/loader";

/**
* Recent sessions across every project, newest first, beside every page. With none yet it invites
Expand All @@ -35,6 +37,7 @@ import { placeAtom } from "./place";
export function SessionsSidebar() {
const result = useAtomValue(projectsAtom);
const problem = useAtomValue(problemAtom);
const working = useAtomValue(workingAtom);
const [query, setQuery] = useState("");
const openElsewhere = useOpenElsewhere();
const [place, setPlace] = useAtom(placeAtom);
Expand All @@ -56,11 +59,16 @@ export function SessionsSidebar() {
};
// Primary and middle clicks open; a right click is left to the context menu. Shift, like a
// browser's new window, asks for a workspace of its own.
const open = (session: { id: string; project: { name: string } }, event: MouseEvent) => {
// Read through a ref, so rows keep one handler and skip re-rendering when the desk changes.
const opener = useRef(openElsewhere);
useLayoutEffect(() => {
opener.current = openElsewhere;
});
const open = useCallback((session: Listed, event: MouseEvent) => {
if (event.button > 1) return;
const placement = event.shiftKey ? "workspace" : openMode(event);
void openElsewhere(sessionAddress(session.id), session.project.name, placement);
};
void opener.current(sessionAddress(session.id), session.project.name, placement);
}, []);

const needle = query.trim().toLowerCase();
const sessions = useMemo(
Expand Down Expand Up @@ -141,43 +149,13 @@ export function SessionsSidebar() {
) : (
<ul aria-label="Threads" className="flex flex-col gap-0.5">
{sessions.map((session) => (
<li key={session.id}>
<button
type="button"
title={`${session.project.path}\n${isMac ? "⌘" : "Ctrl"}-click opens it in a new frame\n⇧-click opens it in a new workspace`}
aria-current={sessionAddress(session.id) === current ? "true" : undefined}
className="group/row relative flex w-full flex-col rounded-md px-2 py-1.5 text-left text-ink/80 outline-none hover:bg-selection-subtle hover:text-ink focus-visible:ring-2 focus-visible:ring-ring aria-current:bg-selection-current aria-current:text-ink"
onClick={(event) => open(session, event)}
onAuxClick={(event) => open(session, event)}
>
<span className="flex min-w-0 items-center gap-1.5">
<span className="min-w-0 flex-1 truncate text-body font-semibold leading-snug text-ink">
{session.title}
</span>
<span className="ml-auto shrink-0 pl-2 text-2xs tabular-nums text-ink-muted">
{ago(session.updated)}
</span>
</span>
<span className="mt-1 flex min-w-0 items-center gap-2 text-2xs text-ink-muted">
<span className="flex min-w-0 flex-1 items-center gap-1.5">
<Monogram id={session.project.id} name={session.project.name} />
<span className="min-w-0 truncate">{session.project.name}</span>
</span>
{session.model !== undefined && (
<span className="flex shrink-0 items-center text-2xs text-ink-muted">
<span className="max-w-32 truncate pr-1.5 opacity-0 transition-opacity duration-150 ease-out group-hover/row:opacity-100 group-focus-visible/row:opacity-100">
{session.model.id}
</span>
<ProviderIcon
id={session.model.provider}
name={session.model.provider}
className="size-3.5 shrink-0"
/>
</span>
)}
</span>
</button>
</li>
<SessionRow
key={session.id}
session={session}
current={sessionAddress(session.id) === current}
working={working.has(session.id)}
onOpen={open}
/>
))}
</ul>
)}
Expand All @@ -195,3 +173,63 @@ export function SessionsSidebar() {
</Sidebar>
);
}

type Listed = Project["sessions"][number] & { readonly project: Project };

/** Off-screen rows skip layout and paint until scrolled near; memoized so a loader or focus change repaints one row. */
const SessionRow = memo(function SessionRow({
session,
current,
working,
onOpen,
}: {
readonly session: Listed;
readonly current: boolean;
readonly working: boolean;
readonly onOpen: (session: Listed, event: MouseEvent) => void;
}) {
return (
<li className="[contain-intrinsic-size:auto_50px] [content-visibility:auto]">
<button
type="button"
title={`${session.project.path}\n${isMac ? "⌘" : "Ctrl"}-click opens it in a new frame\n⇧-click opens it in a new workspace`}
aria-current={current ? "true" : undefined}
className="group/row relative flex w-full flex-col rounded-md px-2 py-1.5 text-left text-ink/80 outline-none hover:bg-selection-subtle hover:text-ink focus-visible:ring-2 focus-visible:ring-ring aria-current:bg-selection-current aria-current:text-ink"
onClick={(event) => onOpen(session, event)}
onAuxClick={(event) => onOpen(session, event)}
>
<span className="flex min-w-0 items-center gap-1.5">
{working && (
<span role="img" aria-label="Agent working" className="flex shrink-0 text-ink-muted">
<PixelLoader />
</span>
)}
<span className="min-w-0 flex-1 truncate text-body font-semibold leading-snug text-ink">
{session.title}
</span>
<span className="ml-auto shrink-0 pl-2 text-2xs tabular-nums text-ink-muted">
{ago(session.updated)}
</span>
</span>
<span className="mt-1 flex min-w-0 items-center gap-2 text-2xs text-ink-muted">
<span className="flex min-w-0 flex-1 items-center gap-1.5">
<Monogram id={session.project.id} name={session.project.name} />
<span className="min-w-0 truncate">{session.project.name}</span>
</span>
{session.model !== undefined && (
<span className="flex shrink-0 items-center text-2xs text-ink-muted">
<span className="max-w-32 truncate pr-1.5 opacity-0 transition-opacity duration-150 ease-out group-hover/row:opacity-100 group-focus-visible/row:opacity-100">
{session.model.id}
</span>
<ProviderIcon
id={session.model.provider}
name={session.model.provider}
className="size-3.5 shrink-0"
/>
</span>
)}
</span>
</button>
</li>
);
});
2 changes: 2 additions & 0 deletions apps/web/src/routes/__root.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@ import { NavigationControls } from "../shell/titlebar";
import { Palette } from "../shell/palette";
import { Toasts } from "../shell/toasts";
import { Splash } from "../splash";
import { useWorkingFeed } from "../widgets/session/projects";

// The sessions sidebar wraps every page but settings, which has its own; its open state carries over.
function Root() {
useWorkingFeed();
const inSettings = useLocation({ select: (location) => location.pathname.startsWith("/settings") });
return (
<SidebarProvider
Expand Down
Loading
Loading