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
4 changes: 0 additions & 4 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,3 @@ The rest of this document is meant to help you navigate the codebase and make ch
- Inferred types over annotations. `any` is the enemy.
- Comments describe how a thing is used, and move when the code moves. To be used mostly to describe functions, not to annotate every line of behavior.
- If a rule here fights the task in front of you, say so loudly and get a human sign-off before breaking it.

## Additional tips

- Don't verify with browsers or computer use unless the user explicitly agrees or requests it.
17 changes: 11 additions & 6 deletions src/components/AppNavbar.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { createHotkey, formatForDisplay, type HotkeySequence } from "@tanstack/solid-hotkeys";
import { createHotkey, type HotkeySequence } from "@tanstack/solid-hotkeys";
import { useNavigate } from "@tanstack/solid-router";
import { useServerFn } from "@tanstack/solid-start";

import { signOutFn } from "@/modules/auth/serverFunctions";

import { Button } from "./ui/Button";
import { ButtonLink } from "./ui/ButtonLink";
import { HotkeyHint } from "./ui/HotkeyHint";

export function AppNavbar() {
const signOut = useServerFn(signOutFn);
Expand All @@ -32,18 +33,22 @@ export function AppNavbar() {
>
<div class="flex items-center gap-3 sm:gap-4">
<ButtonLink variant="link" class="font-semibold" to="/">
bg · {formatForDisplay(organizationsHotkeySequence).toLocaleLowerCase()}
bg
<HotkeyHint hotkey={organizationsHotkeySequence} />
</ButtonLink>
<ButtonLink variant="link" to="/">
organizations · {formatForDisplay(organizationsHotkeySequence).toLocaleLowerCase()}
<ButtonLink variant="link" class="max-sm:hidden" to="/">
organizations
<HotkeyHint hotkey={organizationsHotkeySequence} />
</ButtonLink>
<ButtonLink variant="link" to="/settings">
settings · {formatForDisplay(settingsHotkeySequence).toLocaleLowerCase()}
settings
<HotkeyHint hotkey={settingsHotkeySequence} />
</ButtonLink>
</div>

<Button variant="secondary" onClick={signOutHandler}>
sign out · {formatForDisplay(signOutHotkeySequence).toLocaleLowerCase()}
sign out
<HotkeyHint hotkey={signOutHotkeySequence} />
</Button>
</nav>
</header>
Expand Down
12 changes: 12 additions & 0 deletions src/components/ui/HotkeyHint.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { createFormatForDisplay, type DisplayHotkey } from "@tanstack/solid-hotkeys";

/** Renders ` · g h` after a label: `<>settings<HotkeyHint hotkey={["G", "S"]} /></>`. Hidden on touch screens. */
export function HotkeyHint(props: { hotkey: DisplayHotkey }) {
const formatForDisplay = createFormatForDisplay();
return (
<span class="pointer-coarse:hidden">
{" "}
· {formatForDisplay(props.hotkey).toLocaleLowerCase()}
</span>
);
}
2 changes: 1 addition & 1 deletion src/modules/auth/components/SignInForm.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const mocks = vi.hoisted(() => ({
vi.mock("@tanstack/solid-hotkeys", () => ({
createHotkey: (hotkey: { key: string } | string[], callback: () => unknown) =>
mocks.shortcuts.set(Array.isArray(hotkey) ? hotkey.join(",") : hotkey.key, callback),
formatForDisplay: () => "shortcut",
createFormatForDisplay: () => () => "shortcut",
}));

vi.mock("@tanstack/solid-router", () => ({
Expand Down
15 changes: 9 additions & 6 deletions src/modules/auth/components/SignInForm.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { FieldApi, FormApi } from "@tanstack/form-core";
import {
createHotkey,
formatForDisplay,
type HotkeySequence,
type RegisterableHotkey,
} from "@tanstack/solid-hotkeys";
Expand All @@ -17,6 +16,7 @@ import {
SUBMIT_HOTKEY,
} from "@/components/forms/FormControls";
import { Button, buttonVariants } from "@/components/ui/Button";
import { HotkeyHint } from "@/components/ui/HotkeyHint";
import { Separator } from "@/components/ui/Separator";
import { useField, useForm } from "@/lib/form";
import { destinationAfterAuth, inviteTokenFromHash } from "@/modules/organizations/inviteToken";
Expand Down Expand Up @@ -123,7 +123,8 @@ export function SignInForm() {
field={password()}
/>
<FormSubmitButton {...submission()}>
sign in · {formatForDisplay(SUBMIT_HOTKEY).toLocaleLowerCase()}
sign in
<HotkeyHint hotkey={SUBMIT_HOTKEY} />
</FormSubmitButton>
</form>

Expand All @@ -135,15 +136,17 @@ export function SignInForm() {
disabled={isPasskeyPending()}
onClick={signInWithPasskey}
>
{isPasskeyPending()
? "..."
: `use passkey · ${formatForDisplay(passkeyHotkey).toLocaleLowerCase()}`}
<Show when={!isPasskeyPending()} fallback="...">
use passkey
<HotkeyHint hotkey={passkeyHotkey} />
</Show>
</Button>

<p class="text-muted-foreground text-sm">
don't have an account?{" "}
<Link class={buttonVariants({ variant: "link" })} to="/sign-up" hash={invite()}>
sign up · {formatForDisplay(signUpHotkeySequence).toLocaleLowerCase()}
sign up
<HotkeyHint hotkey={signUpHotkeySequence} />
</Link>
</p>
</div>
Expand Down
9 changes: 6 additions & 3 deletions src/modules/auth/components/SignUpForm.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { FieldApi, FormApi, revalidateLogic } from "@tanstack/form-core";
import { createHotkey, formatForDisplay, type HotkeySequence } from "@tanstack/solid-hotkeys";
import { createHotkey, type HotkeySequence } from "@tanstack/solid-hotkeys";
import { Link, useLocation, useNavigate, useRouter } from "@tanstack/solid-router";
import { useServerFn } from "@tanstack/solid-start";
import { createSignal, Show } from "solid-js";
Expand All @@ -11,6 +11,7 @@ import {
SUBMIT_HOTKEY,
} from "@/components/forms/FormControls";
import { buttonVariants } from "@/components/ui/Button";
import { HotkeyHint } from "@/components/ui/HotkeyHint";
import { useField, useForm } from "@/lib/form";
import { destinationAfterAuth, inviteTokenFromHash } from "@/modules/organizations/inviteToken";

Expand Down Expand Up @@ -117,7 +118,8 @@ export function SignupForm() {
<FormTextField label="password" type="password" field={password()} />
<FormTextField label="confirm password" type="password" field={passwordConfirm()} />
<FormSubmitButton {...submission()}>
sign up · {formatForDisplay(SUBMIT_HOTKEY).toLocaleLowerCase()}
sign up
<HotkeyHint hotkey={SUBMIT_HOTKEY} />
</FormSubmitButton>
</form>
}
Expand All @@ -128,7 +130,8 @@ export function SignupForm() {
<p class="text-muted-foreground text-sm">
already have an account?{" "}
<Link class={buttonVariants({ variant: "link" })} to="/sign-in" hash={invite()}>
sign in · {formatForDisplay(signInHotkeySequence).toLocaleLowerCase()}
sign in
<HotkeyHint hotkey={signInHotkeySequence} />
</Link>
</p>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export function BackgroundRemovalGrid(props: {

return (
<section class="flex flex-col gap-5" aria-label="Background removal images">
<div class="bg-background sticky top-[calc(var(--app-navbar-height,0px)+var(--org-navbar-height,0px))] z-10 -my-4 flex flex-col gap-5 py-4">
<div class="bg-background top-[calc(var(--app-navbar-height,0px)+var(--org-navbar-height,0px))] z-10 -my-4 flex flex-col gap-5 py-4 sm:sticky">
<div class="flex flex-wrap items-center justify-between gap-4 border-b pb-4">
<div class="flex items-baseline gap-3">
<h2 class="font-medium">your images</h2>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { Dialog } from "@kobalte/core/dialog";
import { CloudUpload, X } from "@lucide/solid";
import { createHotkey, formatForDisplay, type RegisterableHotkey } from "@tanstack/solid-hotkeys";
import { createHotkey, type RegisterableHotkey } from "@tanstack/solid-hotkeys";
import { createMemo, createSignal, For, onSettled, Show } from "solid-js";

import { Button } from "@/components/ui/Button";
import { HotkeyHint } from "@/components/ui/HotkeyHint";
import type { ReadyFile } from "@/modules/files/files";
import { SUPPORTED_IMAGE_MEDIA_TYPES } from "@/modules/files/images";
import { formatBytes } from "@/modules/files/imageUpload";
Expand Down Expand Up @@ -297,19 +298,21 @@ export function BackgroundRemovalUploader(props: {
</div>
<div class="bg-muted/20 flex shrink-0 flex-col gap-3 border-t p-4 sm:flex-row sm:items-center sm:justify-between sm:p-5">
<Button variant="ghost" disabled={batch.isUploading()} onClick={chooseFiles}>
+ add more · {formatForDisplay(addMoreHotkey).toLocaleLowerCase()}
+ add more
<HotkeyHint hotkey={addMoreHotkey} />
</Button>
<div class="flex gap-2 [&>button]:flex-1 sm:[&>button]:flex-none">
<Show
when={batch.isUploading()}
fallback={
<>
<Button variant="outline" onClick={close}>
cancel · esc
cancel
<HotkeyHint hotkey="Escape" />
</Button>
<Button disabled={pendingCount() === 0} onClick={() => void upload()}>
upload {pendingCount()} {pendingCount() === 1 ? "image" : "images"} ·{" "}
{formatForDisplay(uploadHotkey).toLocaleLowerCase()}
upload {pendingCount()} {pendingCount() === 1 ? "image" : "images"}
<HotkeyHint hotkey={uploadHotkey} />
</Button>
</>
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { FieldApi, FormApi } from "@tanstack/form-core";
import { formatForDisplay } from "@tanstack/solid-hotkeys";
import { useNavigate } from "@tanstack/solid-router";
import { useServerFn } from "@tanstack/solid-start";
import * as v from "valibot";
Expand All @@ -10,6 +9,7 @@ import {
createFormSubmission,
SUBMIT_HOTKEY,
} from "@/components/forms/FormControls";
import { HotkeyHint } from "@/components/ui/HotkeyHint";
import { useField, useForm } from "@/lib/form";

import { createAndJoinOrganizationFn } from "../serverFunctions";
Expand Down Expand Up @@ -88,7 +88,8 @@ export function CreateOrganizationForm() {
/>
<FormTextField label="slug" type="text" autocomplete="off" field={slug()} />
<FormSubmitButton {...submission()}>
create · {formatForDisplay(SUBMIT_HOTKEY).toLocaleLowerCase()}
create
<HotkeyHint hotkey={SUBMIT_HOTKEY} />
</FormSubmitButton>
</form>
</div>
Expand Down
27 changes: 22 additions & 5 deletions src/routes/__root.tsx
Original file line number Diff line number Diff line change
@@ -1,32 +1,49 @@
import { HydrationScript } from "@solidjs/web";
import { TanStackDevtools } from "@tanstack/solid-devtools";
import { detectPlatform, HotkeysProvider } from "@tanstack/solid-hotkeys";
import { hotkeysDevtoolsPlugin } from "@tanstack/solid-hotkeys-devtools";
import { HeadContent, Outlet, Scripts, createRootRouteWithContext } from "@tanstack/solid-router";
import { TanStackRouterDevtools } from "@tanstack/solid-router-devtools";
import { createIsomorphicFn } from "@tanstack/solid-start";
import { getRequestHeader } from "@tanstack/solid-start/server";
import { Loading } from "solid-js";

import styleCss from "../styles.css?url";

// The server reads the request's user agent so hotkey labels hydrate without changing.
const getHotkeyPlatform = createIsomorphicFn()
.server(() => detectPlatform(getRequestHeader("User-Agent") ?? ""))
.client(() => detectPlatform());

export const Route = createRootRouteWithContext()({
head: () => ({
meta: [
{ charSet: "utf-8" },
{ name: "viewport", content: "width=device-width, initial-scale=1" },
],
links: [{ rel: "stylesheet", href: styleCss }],
}),
loader: () => ({ hotkeyPlatform: getHotkeyPlatform() }),
staleTime: Infinity,
shellComponent: RootComponent,
});

function RootComponent() {
const data = Route.useLoaderData();
return (
<html lang="en">
<head>
<HydrationScript />
<HeadContent />
</head>
<body>
<Loading>
<Outlet />
<TanStackDevtools plugins={[hotkeysDevtoolsPlugin()]} />
<TanStackRouterDevtools />
</Loading>
<HotkeysProvider defaultOptions={{ platform: data().hotkeyPlatform }}>
<Loading>
<Outlet />
<TanStackDevtools plugins={[hotkeysDevtoolsPlugin()]} />
<TanStackRouterDevtools />
</Loading>
</HotkeysProvider>
<Scripts />
</body>
</html>
Expand Down
2 changes: 1 addition & 1 deletion src/routes/_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ function RouteComponent() {

return (
<div
class="bg-muted/30 min-h-screen"
class="bg-muted/30 min-h-dvh"
style={{ "--app-navbar-height": navbar.height() ?? "calc(3.5rem + 1px)" }}
>
<div ref={navbar.ref} class="sticky top-0 z-30">
Expand Down
17 changes: 10 additions & 7 deletions src/routes/_app/$orgSlug.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { createHotkey, formatForDisplay, type HotkeySequence } from "@tanstack/solid-hotkeys";
import { createHotkey, type HotkeySequence } from "@tanstack/solid-hotkeys";
import { createFileRoute, Outlet, redirect } from "@tanstack/solid-router";

import { ButtonLink } from "@/components/ui/ButtonLink";
import { HotkeyHint } from "@/components/ui/HotkeyHint";
import { createElementHeight } from "@/lib/createElementHeight";
import { getOrganizationFn } from "@/modules/organizations/serverFunctions";

Expand Down Expand Up @@ -42,13 +43,13 @@ function RouteComponent() {

return (
<div
class="min-h-[calc(100vh-var(--app-navbar-height))]"
class="min-h-[calc(100dvh-var(--app-navbar-height))]"
style={{ "--org-navbar-height": navbar.height() ?? "calc(3rem + 1px)" }}
>
<div ref={navbar.ref} class="bg-background sticky top-(--app-navbar-height) z-20 border-b">
<nav
aria-label="Organization"
class="mx-auto flex min-h-12 w-full max-w-6xl flex-wrap items-center gap-x-5 gap-y-2 px-4 py-2 text-sm sm:px-6"
class="mx-auto flex min-h-12 w-full max-w-6xl items-center gap-x-5 gap-y-2 overflow-x-auto px-4 py-2 text-sm whitespace-nowrap sm:flex-wrap sm:px-6"
>
<span class="font-medium">{context().organization.name}</span>
<ButtonLink
Expand All @@ -57,15 +58,16 @@ function RouteComponent() {
params={{ orgSlug: context().organization.slug }}
activeOptions={{ exact: true }}
>
home · {formatForDisplay(homeHotkeySequence).toLocaleLowerCase()}
home
<HotkeyHint hotkey={homeHotkeySequence} />
</ButtonLink>
<ButtonLink
variant="link"
to="/$orgSlug/remove-background"
params={{ orgSlug: context().organization.slug }}
>
remove background ·{" "}
{formatForDisplay(removeBackgroundHotkeySequence).toLocaleLowerCase()}
remove background
<HotkeyHint hotkey={removeBackgroundHotkeySequence} />
</ButtonLink>
<ButtonLink
variant="link"
Expand All @@ -79,7 +81,8 @@ function RouteComponent() {
to="/$orgSlug/invites"
params={{ orgSlug: context().organization.slug }}
>
invites · {formatForDisplay(invitesHotkeySequence).toLocaleLowerCase()}
invites
<HotkeyHint hotkey={invitesHotkeySequence} />
</ButtonLink>
</nav>
</div>
Expand Down
2 changes: 1 addition & 1 deletion src/routes/_app/_user/create-organization.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export const Route = createFileRoute("/_app/_user/create-organization")({

function RouteComponent() {
return (
<div class="flex min-h-[calc(100vh-7.5rem)] items-center justify-center py-8">
<div class="flex min-h-[calc(100dvh-7.5rem)] items-center justify-center py-8">
<CreateOrganizationForm />
</div>
);
Expand Down
11 changes: 7 additions & 4 deletions src/routes/_app/_user/index.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import {
createHotkeys,
DEFAULT_SEQUENCE_TIMEOUT,
formatForDisplay,
type HotkeySequence,
} from "@tanstack/solid-hotkeys";
import { createFileRoute } from "@tanstack/solid-router";
import { createMemo, For, onCleanup, Show } from "solid-js";

import { ButtonLink } from "@/components/ui/ButtonLink";
import { HotkeyHint } from "@/components/ui/HotkeyHint";
import { listOrganizationsFn } from "@/modules/organizations/serverFunctions";

export const Route = createFileRoute("/_app/_user/")({
Expand Down Expand Up @@ -54,7 +54,8 @@ function RouteComponent() {
<p class="text-muted-foreground mt-1 text-sm">Choose where you want to work.</p>
</div>
<ButtonLink variant="link" to="/create-organization">
create organization · o c
create organization
<HotkeyHint hotkey={["O", "C"]} />
</ButtonLink>
</div>

Expand All @@ -69,7 +70,8 @@ function RouteComponent() {
</p>
</div>
<ButtonLink variant="link" to="/create-organization">
create organization · o c
create organization
<HotkeyHint hotkey={["O", "C"]} />
</ButtonLink>
</div>
}
Expand All @@ -83,7 +85,8 @@ function RouteComponent() {
<div class="text-muted-foreground truncate text-sm">/{organization.slug}</div>
</div>
<ButtonLink variant="link" to="/$orgSlug" params={{ orgSlug: organization.slug }}>
open · {formatForDisplay(sequence).toLocaleLowerCase()}
open
<HotkeyHint hotkey={sequence} />
</ButtonLink>
</li>
)}
Expand Down
Loading
Loading