Skip to content

Commit

Permalink
chore: hook sticky header together
Browse files Browse the repository at this point in the history
  • Loading branch information
dominik-stumpf committed Nov 21, 2024
1 parent 1693802 commit 2b19a9a
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 32 deletions.
4 changes: 1 addition & 3 deletions src/app/explorer/_components/InfiniteScrollGuilds.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,7 @@ export const InfiniteScrollGuilds = () => {
<p className="mt-6 text-center text-foreground-secondary">
{isFetchingNextPage
? "Loading more..."
: hasNextPage
? "Load More"
: "No More Data"}
: hasNextPage || "No More Data"}
</p>
)}
</section>
Expand Down
20 changes: 17 additions & 3 deletions src/app/explorer/_components/Search.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
"use client";

import { Input } from "@/components/ui/Input";
import useIsStuck from "@/hooks/useIsStuck";
import { MagnifyingGlass } from "@phosphor-icons/react/dist/ssr";
import { useDebouncedValue } from "foxact/use-debounced-value";
import { useSetAtom } from "jotai";
import { usePathname, useSearchParams } from "next/navigation";
import { useEffect, useState } from "react";
import { searchAtom } from "../atoms";
import { Suspense, useEffect, useState } from "react";
import { isSearchStuckAtom, searchAtom } from "../atoms";

export const Search = () => {
const Search = () => {
const searchParams = useSearchParams();
const pathname = usePathname();
const [value, setValue] = useState(
Expand Down Expand Up @@ -48,3 +49,16 @@ export const Search = () => {
</div>
);
};

export const StickySearch = () => {
const setIsSearchStuck = useSetAtom(isSearchStuckAtom);
const { ref: searchRef } = useIsStuck(setIsSearchStuck);

return (
<div className="sticky top-12 z-10" ref={searchRef}>
<Suspense>
<Search />
</Suspense>
</div>
);
};
14 changes: 4 additions & 10 deletions src/app/explorer/_components/StickyBar.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
"use client";

import { AuthBoundary } from "@/components/AuthBoundary";
//import { useWeb3ConnectionManager } from "@/components/Web3ConnectionManager/hooks/useWeb3ConnectionManager"
import { buttonVariants } from "@/components/ui/Button";
import { ToggleGroup, ToggleGroupItem } from "@/components/ui/ToggleGroup";
import useIsStuck from "@/hooks/useIsStuck";
Expand All @@ -10,7 +7,7 @@ import { cn } from "@/lib/cssUtils";
import { Plus } from "@phosphor-icons/react";
import { useAtom, useAtomValue, useSetAtom } from "jotai";
import Link from "next/link";
import { useEffect } from "react";
import { type PropsWithChildren, useEffect } from "react";
import { activeSectionAtom, isNavStuckAtom, isSearchStuckAtom } from "../atoms";
import { ACTIVE_SECTION } from "../constants";

Expand Down Expand Up @@ -73,7 +70,7 @@ const Nav = () => {
);
};

const CreateGuildLink = () => {
export const CreateGuildLink = () => {
const isNavStuck = useAtomValue(isNavStuckAtom);
return (
<Link
Expand All @@ -98,8 +95,7 @@ const CreateGuildLink = () => {
);
};

export const StickyBar = () => {
//const { isWeb3Connected } = useWeb3ConnectionManager()
export const StickyBar = ({ children }: PropsWithChildren) => {
const setIsNavStuck = useSetAtom(isNavStuckAtom);
const isSearchStuck = useAtomValue(isSearchStuckAtom);
const { ref: navToggleRef } = useIsStuck(setIsNavStuck);
Expand All @@ -116,9 +112,7 @@ export const StickyBar = () => {
>
<div className="relative flex w-full items-center justify-between">
<Nav />
<AuthBoundary fallback={null}>
<CreateGuildLink />
</AuthBoundary>
{children}
</div>
</div>
);
Expand Down
23 changes: 13 additions & 10 deletions src/app/explorer/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { GuildCardSkeleton } from "@/components/GuildCard";
import { GuildCard } from "@/components/GuildCard";
import { Button } from "@/components/ui/Button";
import { env } from "@/lib/env";
import { Plus, SignIn } from "@phosphor-icons/react/dist/ssr";
import { SignIn } from "@phosphor-icons/react/dist/ssr";
import {
HydrationBoundary,
QueryClient,
Expand All @@ -12,7 +12,8 @@ import {
import { Suspense } from "react";
import { HeaderBackground } from "./_components/HeaderBackground";
import { InfiniteScrollGuilds } from "./_components/InfiniteScrollGuilds";
import { Search } from "./_components/Search";
import { StickySearch } from "./_components/Search";
import { CreateGuildLink, StickyBar } from "./_components/StickyBar";
import { ACTIVE_SECTION } from "./constants";
import { getGuildSearch } from "./fetchers";

Expand Down Expand Up @@ -46,11 +47,17 @@ export default async function Explorer() {
</h1>
</section>

<StickyBar>
<AuthBoundary fallback={null}>
<CreateGuildLink />
</AuthBoundary>
</StickyBar>
<YourGuildsSection />

<section>
<Search />
</section>
<h2 className="mt-12 font-bold text-lg tracking-tight">
Explore verified guilds
</h2>
<StickySearch />

<HydrationBoundary state={dehydrate(queryClient)}>
<InfiniteScrollGuilds />
Expand All @@ -63,8 +70,6 @@ export default async function Explorer() {
async function YourGuildsSection() {
return (
<section className="grid gap-2">
<h2 className="font-bold text-lg">Your guilds</h2>

<AuthBoundary
fallback={
<div className="flex items-center gap-4 rounded-2xl bg-card px-5 py-6">
Expand Down Expand Up @@ -110,9 +115,7 @@ async function YourGuilds() {
or create your own!
</p>

<Button leftIcon={<Plus weight="bold" />} className="ml-auto h-10">
Create guild
</Button>
<CreateGuildLink />
</div>
);
}
Expand Down
6 changes: 0 additions & 6 deletions src/components/Header.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,13 @@
import { me } from "@/actions/me";
import { AuthBoundary } from "./AuthBoundary";
import { SignInButton } from "./SignInButton";
import { SignOutButton } from "./SignOutButton";
import { Button } from "./ui/Button";
import { Card } from "./ui/Card";

export const Header = () => (
<header className="flex h-14 items-center justify-between gap-4 p-2">
{/* TODO: NavMenu component */}
<Card className="h-10 w-24 rounded-xl" />

<form action={me}>
<Button type="submit">me (test auth)</Button>
</form>

<AuthBoundary fallback={<SignInButton />}>
<SignOutButton />
</AuthBoundary>
Expand Down

0 comments on commit 2b19a9a

Please sign in to comment.