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
45 changes: 31 additions & 14 deletions web/components/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { Logo } from "./Logo";
import { Button } from "@/components/ui/button";
import { Tooltip, TooltipContent, TooltipTrigger } from "@/components/ui/tooltip";
import { cn } from "@/lib/utils";
import { openCommandPalette } from "@/components/discovery/DiscoveryCommand";
import { openCommandPalette, openCalendar } from "@/components/discovery/DiscoveryCommand";

const NAV = [
{ href: "/discover", label: "Discover", icon: "ic:round-explore" },
Expand Down Expand Up @@ -80,20 +80,37 @@ export function Header({
</nav>
</div>

{/* Center: search bar — absolutely centered (lg+). The wrapper ignores
pointer events so it never blocks the left/right clusters; only the
button itself is interactive. */}
{/* Center: search bar + calendar — absolutely centered (lg+). The wrapper
ignores pointer events so it never blocks the left/right clusters;
only the buttons themselves are interactive. The calendar sits to the
right of the search bar and opens the app-level calendar dialog. */}
<div className="pointer-events-none absolute left-1/2 hidden w-full max-w-md -translate-x-1/2 px-4 lg:block">
<button
type="button"
onClick={openCommandPalette}
aria-label="Search events and commands"
className="pointer-events-auto flex w-full items-center gap-2 rounded-lg border bg-muted/40 px-3 py-1.5 text-sm text-muted-foreground transition-colors hover:bg-muted/70 hover:text-foreground"
>
<Icon icon="ic:round-search" size={16} />
<span>Search events…</span>
<kbd className="ml-auto font-mono text-[11px] text-muted-foreground">⌘K</kbd>
</button>
<div className="flex items-center gap-2">
<button
type="button"
onClick={openCommandPalette}
aria-label="Search events and commands"
className="pointer-events-auto flex grow items-center gap-2 rounded-lg border bg-muted/40 px-3 py-1.5 text-sm text-muted-foreground transition-colors hover:bg-muted/70 hover:text-foreground"
>
<Icon icon="ic:round-search" size={16} />
<span>Search events…</span>
<kbd className="ml-auto font-mono text-[11px] text-muted-foreground">⌘K</kbd>
</button>
<Tooltip>
<TooltipTrigger asChild>
<Button
variant="outline"
size="icon-sm"
onClick={openCalendar}
aria-label="Calendar"
className="pointer-events-auto flex-none"
>
<Icon icon="proicons:calendar" size={16} />
</Button>
</TooltipTrigger>
<TooltipContent>Calendar</TooltipContent>
</Tooltip>
</div>
</div>

{/* Right: actions */}
Expand Down
38 changes: 21 additions & 17 deletions web/components/discovery/DiscoveryCommand.tsx
Original file line number Diff line number Diff line change
@@ -1,22 +1,30 @@
"use client";

import { useCallback, useEffect, useState } from "react";
import { useEffect, useState } from "react";
import { useRouter } from "next/navigation";
import { useDiscoverEvents } from "@/lib/events";
import { useKeyboardShortcuts } from "@/lib/useKeyboardShortcuts";
import { CommandPalette } from "./CommandPalette";
import { CalendarViewDialog } from "./CalendarViewDialog";
import { ShortcutsHelpDialog } from "./ShortcutsHelpDialog";

/** Custom DOM event other components dispatch to open the palette (Header button,
* mobile search affordance) without prop drilling through the layout. */
/** Custom DOM events other components dispatch to open the palette / calendar
* (Header buttons, mobile search affordance) without prop drilling through the
* layout. The calendar dialog lives here in the island, so the global Header
* opens it via this event rather than owning its own state. */
export const OPEN_COMMAND_EVENT = "hostit:open-command";
export const OPEN_CALENDAR_EVENT = "hostit:open-calendar";

/** Dispatch from anywhere (e.g. the Header Cmd+K button) to open the palette. */
export function openCommandPalette() {
if (typeof window !== "undefined") window.dispatchEvent(new Event(OPEN_COMMAND_EVENT));
}

/** Dispatch from anywhere (e.g. the Header Calendar button) to open the calendar. */
export function openCalendar() {
if (typeof window !== "undefined") window.dispatchEvent(new Event(OPEN_CALENDAR_EVENT));
}

/**
* App-level discovery command island: mounts the Cmd+K command palette, the
* calendar dialog, the shortcuts help, and the global keyboard-shortcut listener
Expand All @@ -32,24 +40,20 @@ export function DiscoveryCommand() {
const [helpOpen, setHelpOpen] = useState(false);

useEffect(() => {
const open = () => setPaletteOpen(true);
window.addEventListener(OPEN_COMMAND_EVENT, open);
return () => window.removeEventListener(OPEN_COMMAND_EVENT, open);
const openCmd = () => setPaletteOpen(true);
const openCal = () => setCalendarOpen(true);
window.addEventListener(OPEN_COMMAND_EVENT, openCmd);
window.addEventListener(OPEN_CALENDAR_EVENT, openCal);
return () => {
window.removeEventListener(OPEN_COMMAND_EVENT, openCmd);
window.removeEventListener(OPEN_CALENDAR_EVENT, openCal);
};
}, []);

const focusSearch = useCallback(() => {
const el = document.getElementById("discover-search");
if (el instanceof HTMLInputElement) {
el.focus();
el.select();
} else {
router.push("/discover");
}
}, [router]);

useKeyboardShortcuts({
onCommandPalette: () => setPaletteOpen((v) => !v),
onFocusSearch: focusSearch,
// "/" — no inline search bar anymore, so open the command palette (search).
onFocusSearch: () => setPaletteOpen(true),
onGoDiscover: () => router.push("/discover"),
onGoTickets: () => router.push("/wallet"),
onGoDashboard: () => router.push("/dashboard"),
Expand Down
84 changes: 22 additions & 62 deletions web/components/screens/DiscoverScreen.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"use client";

import { useCallback, useDeferredValue, useMemo, useState } from "react";
import { useCallback, useMemo, useState } from "react";
import Link from "next/link";
import { useCurrentAccount } from "@/lib/hooks";
import { useEventList, useEventObjects, useActivityFeed, buildDiscoverEvents } from "@/lib/events";
Expand All @@ -14,11 +14,9 @@ import { TrendingRow } from "@/components/discovery/TrendingRow";
import { FeaturedCarousel } from "@/components/discovery/FeaturedCarousel";
import { RecentlyViewedRow } from "@/components/discovery/RecentlyViewedRow";
import { RecommendedRow } from "@/components/discovery/RecommendedRow";
import { CalendarViewDialog } from "@/components/discovery/CalendarViewDialog";
import { openCommandPalette } from "@/components/discovery/DiscoveryCommand";
import { Card, CardContent } from "@/components/ui/card";
import { Button } from "@/components/ui/button";
import { Input } from "@/components/ui/input";
import { ToggleGroup, ToggleGroupItem } from "@/components/ui/toggle-group";

export function DiscoverScreen() {
Expand All @@ -36,9 +34,7 @@ export function DiscoverScreen() {

const { mints } = useActivityFeed();

const [q, setQ] = useState("");
const [cat, setCat] = useState("all");
const [calendarOpen, setCalendarOpen] = useState(false);
// event_id -> searchable metadata (from Walrus metadata, fetched lazily by cards)
const [eventMeta, setEventMeta] = useState<
Record<string, { category?: string; city?: string; venue?: string }>
Expand All @@ -61,31 +57,15 @@ export function DiscoverScreen() {
[],
);

// Defer the heavy filter so typing stays responsive — the <Input> tracks `q`
// immediately while the full-list filter recomputes off the deferred value.
const deferredQ = useDeferredValue(q);
// Text search lives in the Cmd+K palette now; the page filters by category.
// Events with no category metadata yet are kept under any active category.
const filtered = useMemo(() => {
const ql = deferredQ.trim().toLowerCase();
if (cat === "all") return events;
return events.filter((e) => {
const meta = eventMeta[e.eventId];
const organizerName = names.get(e.organizer) ?? "";
const searchable = [
e.name,
e.organizer,
organizerName,
meta?.category,
meta?.city,
meta?.venue,
]
.filter(Boolean)
.join(" ")
.toLowerCase();

if (ql && !searchable.includes(ql)) return false;
if (cat !== "all" && meta?.category && meta.category !== cat) return false;
return true;
return !meta?.category || meta.category === cat;
});
}, [events, deferredQ, cat, eventMeta, names]);
}, [events, cat, eventMeta]);

// Flattened, on-chain-derived events for the curated discovery rows + calendar.
// Reuses the data already fetched here (list + objects + prices + lazy meta) —
Expand All @@ -95,9 +75,9 @@ export function DiscoverScreen() {
[events, eventObjects, pricesBySeq, eventMeta],
);

// Curated rows only show in the default browse view (no active search/filter),
// above the grid. Searching/filtering collapses straight to the grid.
const browsing = q.trim() === "" && cat === "all";
// Curated rows only show in the default browse view (no active category
// filter), above the grid. Filtering by category collapses straight to the grid.
const browsing = cat === "all";
const showRows = browsing && !isLoading && !isError && events.length > 0;

return (
Expand All @@ -110,35 +90,17 @@ export function DiscoverScreen() {

<ActivityTicker mints={mints} />

<div className="flex gap-2 flex-wrap items-center">
<div className="grow" style={{ position: "relative", minWidth: 240 }}>
<span style={{ position: "absolute", left: 12, top: "50%", transform: "translateY(-50%)", color: "var(--fg3)", zIndex: 1 }}>
<Icon icon="ic:round-search" size={18} />
</span>
<Input
id="discover-search"
name="discover-search"
aria-label="Search events"
placeholder="Search events, cities, organizers…"
value={q}
onChange={(e) => setQ(e.target.value)}
className="pl-10"
/>
</div>
<Button variant="outline" size="sm" onClick={() => setCalendarOpen(true)}>
<Icon icon="proicons:calendar" size={16} /> Calendar
</Button>
{/* Mobile palette affordance (Header Cmd+K button is desktop-only). */}
<Button
variant="outline"
size="icon-sm"
aria-label="Open command palette"
className="md:hidden"
onClick={openCommandPalette}
>
<Icon icon="ic:round-bolt" size={16} />
</Button>
</div>
{/* Mobile search + commands — the header search/calendar is desktop-only
(md+). Opens the Cmd+K palette, which also has the calendar action. */}
<button
type="button"
onClick={openCommandPalette}
aria-label="Search events and commands"
className="md:hidden flex w-full items-center gap-2 rounded-lg border bg-muted/40 px-3 py-2 text-sm text-muted-foreground transition-colors hover:bg-muted/70 hover:text-foreground"
>
<Icon icon="ic:round-search" size={16} />
<span>Search events…</span>
</button>

<ToggleGroup
type="single"
Expand Down Expand Up @@ -180,7 +142,7 @@ export function DiscoverScreen() {
<CardContent>
<div className="font-semibold">No events found.</div>
<p className="text-sm" style={{ color: "var(--fg2)", marginTop: 4 }}>
Try a different search, or{" "}
Try a different category, or{" "}
<Link href="/create" style={{ color: "var(--hi-blue)" }}>host your own</Link>.
</p>
</CardContent>
Expand All @@ -206,13 +168,11 @@ export function DiscoverScreen() {
</div>
{truncated && (
<p className="mono text-sm" style={{ color: "var(--fg3)", textAlign: "center" }}>
Search covers the {events.length} most recent events — older ones aren&apos;t loaded yet.
Showing the {events.length} most recent events — older ones aren&apos;t loaded yet.
</p>
)}
</>
)}

<CalendarViewDialog open={calendarOpen} onOpenChange={setCalendarOpen} events={discoverEvents} />
</div>
);
}
14 changes: 8 additions & 6 deletions web/lib/suins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ import { useQuery } from "@tanstack/react-query";
import { getSuiNSClient, SUINS_NETWORK } from "./suinsClient";

/**
* Reverse-look up a Sui address → its default/primary suiNS name, or null.
* Resolves on the MAINNET suiNS client (see lib/suinsClient.ts) — names don't
* exist on testnet. Returns null for an address with no default name (the common
* case, not an error); genuine RPC failures surface as a query error (one retry)
* so they aren't masked as "no name forever" — consumers fall back to hex.
* Reverse-look up a Sui address → its primary suiNS name, or null. Resolves on
* the app's active network (see lib/suinsClient.ts `SUINS_NETWORK`, testnet by
* default), so a testnet wallet's `.sui` name resolves. Returns null for an
* address with no name (the common case, not an error); genuine RPC failures
* surface as a query error (one retry) so they aren't masked as "no name
* forever" — consumers fall back to hex.
*/
export function useSuiNSName(address: string | null | undefined) {
const client = getSuiNSClient();
Expand All @@ -28,7 +29,8 @@ export function useSuiNSName(address: string | null | undefined) {

/**
* Forward-resolve a suiNS name → address (for search by name). Accepts a bare
* label or a `.sui` name; resolves on mainnet. Returns null if unregistered.
* label or a `.sui` name; resolves on the app's active network. Returns null if
* unregistered.
*/
export function useResolveSuiNSAddress(name: string | null | undefined) {
const client = getSuiNSClient();
Expand Down
18 changes: 11 additions & 7 deletions web/lib/suinsClient.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
// suiNS names live on Sui **mainnet**, even though HostIt runs on testnet. The
// app's dapp-kit client is the active (testnet) client, so resolving names there
// always returned `[]` — the bug where a connected wallet's `.sui` name never
// rendered. This is a dedicated read-only MAINNET client used ONLY for suiNS
// reverse/forward resolution, independent of the app's active network.
// suiNS resolution runs on the app's ACTIVE network (lib/config `NETWORK`,
// testnet by default). suiNS is live on Sui testnet, so a testnet wallet's
// `.sui` name resolves on the testnet fullnode — names resolve on the same
// network the app and all its addresses live on. (Previously hard-coded to
// mainnet on the false premise that "names don't exist on testnet", so every
// lookup returned [] and no `.sui` name ever rendered — GH#113.) Dedicated
// read-only client for reverse/forward resolution; names only resolve where a
// name service exists (testnet/mainnet), not on localnet.

import { SuiJsonRpcClient, getJsonRpcFullnodeUrl } from "@mysten/sui/jsonRpc";
import { NETWORK } from "./config";

/** The network suiNS names are resolved against (part of every cache key). */
export const SUINS_NETWORK = "mainnet" as const;
export const SUINS_NETWORK = NETWORK;

interface SuiNSResolver {
resolveNameServiceNames: (input: { address: string; limit?: number }) => Promise<{
Expand All @@ -19,7 +23,7 @@ interface SuiNSResolver {

let cached: SuiNSResolver | null = null;

/** Singleton read-only mainnet client for suiNS resolution (lazy; never at module load). */
/** Singleton read-only client for suiNS resolution on the app network (lazy; never at module load). */
export function getSuiNSClient(): SuiNSResolver {
if (!cached) {
cached = new SuiJsonRpcClient({
Expand Down
5 changes: 3 additions & 2 deletions web/lib/verification.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ import { getSuiNSClient, SUINS_NETWORK } from "./suinsClient";
* Batched suiNS reverse-lookup for many addresses at once. Each lookup is
* keyed individually in tanstack-query so the cache survives address-list
* changes (an additional address just fires one new query). Resolves on the
* MAINNET suiNS client (names don't exist on testnet) — shares the same
* network-scoped cache key as `useSuiNSName`, so single + batch lookups dedupe.
* app's active network (see `SUINS_NETWORK`, testnet by default), so testnet
* `.sui` names resolve — shares the same network-scoped cache key as
* `useSuiNSName`, so single + batch lookups dedupe.
*/
export function useSuiNSNames(addresses: string[]): Map<string, string | null> {
const client = getSuiNSClient();
Expand Down
Loading