Workspace filter in the header

merged…
osebo49d ago

Replace the Evenings text with the Workspace dropdown, what I mean is to move it up there

IMG_8400.jpeg
IMG_8400.jpeg
2 repliesoldestnewest
Osebotfable-5-149d ago

Reading the screenshot: the "EVENINGS" wordmark in the header should become the workspace <select> that currently sits in the filter row under the search box.

Plan:

  • New client component components/header-workspace.tsx: the workspace dropdown rendered in app/layout.tsx where the <h1> wordmark was (signed-in users; signed-out keeps the wordmark). It reads the current selection from the URL (/?workspace=…, or /workspaces/[id]) and on change navigates to /?workspace=<id> keeping ?q/?who.
  • components/thread-browser.tsx: drop the in-page workspace select (the Everyone | Yours toggle stays); the filter state still comes from the URL so the live fetch keeps working. Page keys the browser on the workspace so a header change re-syncs it.
  • CSS: style the select for all three header modes (sidebar / top bar / phone) and move the chevron rules.
  • Mockup screenshots (phone + sidebar) for before/after.
Osebotfable-5-149d agothreadide@b266a04

Done — pushed to thread/acfb445d (commit b266a04). The workspace dropdown now lives in the header where the EVENINGS wordmark was, and the filter row under the search box keeps only Everyone | Yours.

What changed

  • threadide/components/header-workspace.tsx (new): the dropdown, rendered by app/layout.tsx in the title slot for signed-in users (signed-out pages, e.g. /signin, keep the wordmark). Options come from a new light lib/data.ts listWorkspaceNames() (id + name only).
  • It is the home-page filter: picking an entry navigates to /?workspace=<id|general>. On the home page it uses router.replace and keeps ?q/?who (read from window.location, since ThreadBrowser mirrors those via replaceState); from any other page it router.pushes to the filtered home list. Shown value = ?workspace on /, the workspace id on /workspaces/[id], otherwise "All workspaces".
  • app/page.tsx keys ThreadBrowser on the workspace so the list/empty-state re-seed after the navigation. components/thread-browser.tsx no longer renders a select; a hidden workspace field keeps the filter across a no-JS Enter submit.
  • CSS: .thread-filter → .ws-select (shared select + chevron styles) plus header.top .header-ws sizing per header mode — phone: fills the space between ☰ and the avatar; top bar (561–900px): ~240px before the nav links; sidebar (>900px): spans the column above the links. Header text is full-strength (not muted) since it's the lead element; a picked workspace goes bold with a solid border.

Trade-offs worth knowing

  • Changing the workspace is now a soft navigation (server re-render) rather than the in-page live fetch; search typing and Everyone|Yours are still live. If that feels slow we could go back to client state via a shared context — tell me.
  • The wordmark is gone from the header for signed-in users; "Threads" in the nav is the way home. Happy to add a small wordmark elsewhere (e.g. above the sidebar dropdown) if you miss it.

Verified with tsc and a full next build. Screenshots are static mockups of the real CSS (the app can't run in the sandbox); attached: phone before/after-style pair and the desktop sidebar.

Phone header after: workspace dropdown where the EVENINGS wordmark was (left: nothing picked, right: a workspace picked)
Phone header after: workspace dropdown where the EVENINGS wordmark was (left: nothing picked, right: a workspace picked)
Desktop sidebar after: the dropdown spans the sidebar column above the nav links
Desktop sidebar after: the dropdown spans the sidebar column above the nav links
Diff · 6 files
diff --git a/app/layout.tsx b/app/layout.tsx
--- a/threadide/app/layout.tsx
+++ b/threadide/app/layout.tsx
@@ -2,6 +2,8 @@ import type { Metadata } from "next";
 import Link from "next/link";
 import "./globals.css";
 import { currentUser } from "@/lib/session";
+import { listWorkspaceNames } from "@/lib/data";
+import { HeaderWorkspace } from "@/components/header-workspace";
 import { UserMenu } from "@/components/user-menu";
@@ -24,6 +26,8 @@ export const metadata: Metadata = {
 export default async function RootLayout({ children }: { children: React.ReactNode }) {
   const user = await currentUser();
+  // Signed in: the header shows the workspace dropdown (home-page filter) in place of the wordmark.
+  const workspaces = user ? await listWorkspaceNames() : [];
   return (
@@ -36,14 +40,19 @@ export default async function RootLayout({ children }: { children: React.ReactNo
           <SiteNav />
-          <h1>
-            <Link href="/" style={{ textDecoration: "none" }}>
-              {SITE_NAME}
-            </Link>
-          </h1>
+          {user ? (
+            <HeaderWorkspace workspaces={workspaces} />
+          ) : (
+            <h1>
+              <Link href="/" style={{ textDecoration: "none" }}>
+                {SITE_NAME}
+              </Link>
+            </h1>
+          )}
           <span className="top-user">
diff --git a/app/page.tsx b/app/page.tsx
--- a/threadide/app/page.tsx
+++ b/threadide/app/page.tsx
@@ -25,7 +25,10 @@ export default async function Home({ searchParams }: { searchParams: Promise<{ q
   return (
+    // Keyed on the workspace: the header dropdown (components/header-workspace.tsx) changes it by navigating,
+    // and the remount re-seeds the browser's filter state from the new URL.
     <ThreadBrowser
+      key={filters.workspace}
       initialQ={q}
diff --git a/components/header-workspace.tsx b/components/header-workspace.tsx
new file mode 100644
--- /dev/null
+++ b/threadide/components/header-workspace.tsx
@@ -0,0 +1,73 @@
+"use client";
+
+import { usePathname, useRouter, useSearchParams } from "next/navigation";
+import { Suspense } from "react";
+import { GENERAL_WORKSPACE } from "@/lib/workspace-filter";
+
+export type WorkspaceOption = { id: string; name: string };
+
+/**
+ * The workspace dropdown in the header, where the site wordmark used to be. It is the home page's
+ * workspace filter: picking an entry navigates to `/?workspace=<id|general>` — on the home page via
+ * router.replace (keeping ?q and ?who, which ThreadBrowser mirrors into the URL with replaceState, so we
+ * read window.location rather than the hook), elsewhere via router.push. app/page.tsx keys ThreadBrowser
+ * on the workspace so the list and the empty-state text re-sync after the navigation.
+ */
+export function HeaderWorkspace({ workspaces }: { workspaces: WorkspaceOption[] }) {
+  return (
+    <Suspense fallback={<WorkspaceSelect workspaces={workspaces} value="" />}>
+      <LiveWorkspaceSelect workspaces={workspaces} />
+    </Suspense>
+  );
+}
+
+function LiveWorkspaceSelect({ workspaces }: { workspaces: WorkspaceOption[] }) {
+  const pathname = usePathname();
+  const router = useRouter();
+  const params = useSearchParams();
+  const known = new Set(workspaces.map((w) => w.id));
+  let value = "";
+  if (pathname === "/") {
+    const ws = params.get("workspace") ?? "";
+    value = ws === GENERAL_WORKSPACE || known.has(ws) ? ws : "";
+  } else if (pathname.startsWith("/workspaces/")) {
+    const id = pathname.split("/")[2] ?? "";
+    value = known.has(id) ? id : "";
+  }
+
+  const onChange = (next: string) => {
+    const onHome = pathname === "/";
+    const qs = new URLSearchParams(onHome ? window.location.search : "");
+    if (next) qs.set("workspace", next);
+    else qs.delete("workspace");
+    const s = qs.toString();
+    const url = `/${s ? `?${s}` : ""}`;
+    if (onHome) router.replace(url);
+    else router.push(url);
+  };
+
+  return <WorkspaceSelect workspaces={workspaces} value={value} onChange={onChange} />;
+}
+
+function WorkspaceSelect({ workspaces, value, onChange }: { workspaces: WorkspaceOption[]; value: string; onChange?: (v: string) => void }) {
+  return (
+    <div className={value ? "ws-select header-ws has-value" : "ws-select header-ws"}>
+      <select name="workspace" value={value} aria-label="Workspace" disabled={!onChange} onChange={(e) => onChange?.(e.target.value)}>
+        <option value="">All workspaces</option>
+        {workspaces.map((w) => (
+          <option key={w.id} value={w.id}>
+            {w.name}
+          </option>
+        ))}
+        <option value={GENERAL_WORKSPACE}>General (no workspace)</option>
+      </select>
+    </div>
+  );
+}
diff --git a/components/thread-browser.tsx b/components/thread-browser.tsx
--- a/threadide/components/thread-browser.tsx
+++ b/threadide/components/thread-browser.tsx
@@ -202,17 +204,9 @@ export function ThreadBrowser({
                 </label>
               ))}
             </div>
-            <div className={filters.workspace ? "thread-filter has-value" : "thread-filter"}>
-              <select name="workspace" value={filters.workspace} aria-label="Workspace" onChange={(e) => setFilters((f) => ({ ...f, workspace: e.target.value }))}>
-                <option value="">All workspaces</option>
-                {Object.entries(workspaces ?? {}).map(([id, w]) => (
-                  <option key={id} value={id}>
-                    {w.name}
-                  </option>
-                ))}
-                <option value={GENERAL_WORKSPACE}>General (no workspace)</option>
-              </select>
-            </div>
+            {/* The workspace filter itself is the dropdown in the header (components/header-workspace.tsx), which
+                navigates to /?workspace=…; this hidden field keeps it across a no-JS Enter submit. */}
+            {filters.workspace && <input type="hidden" name="workspace" value={filters.workspace} />}
           </div>
         )}
diff --git a/lib/data.ts b/lib/data.ts
--- a/threadide/lib/data.ts
+++ b/threadide/lib/data.ts
@@ -25,6 +25,11 @@ export async function listWorkspaces(userId: string) {
 }
 
+/** id + name of every workspace, for the header dropdown (components/header-workspace.tsx). Readable by any signed-in user. */
+export async function listWorkspaceNames() {
+  return db.select({ id: workspaces.id, name: workspaces.name }).from(workspaces).orderBy(asc(workspaces.name));
+}
+
 /** Only the workspaces the user belongs to (can ask Claude / manage in). */