-
Notifications
You must be signed in to change notification settings - Fork 446
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(explorer): prefetch guilds on the server
- Loading branch information
1 parent
2ad30be
commit d4fdd34
Showing
8 changed files
with
229 additions
and
171 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
"use client" | ||
|
||
import { walletSelectorModalAtom } from "@/components/Providers/atoms" | ||
import { useWeb3ConnectionManager } from "@/components/Web3ConnectionManager/hooks/useWeb3ConnectionManager" | ||
import { Button } from "@/components/ui/Button" | ||
import { Card } from "@/components/ui/Card" | ||
import { SignIn } from "@phosphor-icons/react" | ||
import { GuildSearchBar } from "app/explorer/_components/GuildSearchBar" | ||
import { YourGuilds } from "app/explorer/_components/YourGuilds" | ||
import useIsStuck from "hooks/useIsStuck" | ||
import { useSetAtom } from "jotai" | ||
import { Suspense } from "react" | ||
import Robot from "/public/landing/robot.svg" | ||
import { guildQueryAtom, isSearchStuckAtom } from "../atoms" | ||
import { ActiveSection } from "../types" | ||
import { GuildInfiniteScroll } from "./GuildInfiniteScroll" | ||
import { StickyBar } from "./StickyBar" | ||
|
||
export const Explorer = () => { | ||
const { isWeb3Connected } = useWeb3ConnectionManager() | ||
const setIsSearchStuck = useSetAtom(isSearchStuckAtom) | ||
const setIsWalletSelectorModalOpen = useSetAtom(walletSelectorModalAtom) | ||
|
||
const { ref: searchRef } = useIsStuck(setIsSearchStuck) | ||
|
||
return ( | ||
<> | ||
<StickyBar /> | ||
|
||
{isWeb3Connected ? ( | ||
<YourGuilds /> | ||
) : ( | ||
<Card className="my-2 mb-12 flex flex-col items-stretch justify-between gap-8 p-6 font-semibold sm:flex-row sm:items-center"> | ||
<div className="flex items-center gap-4"> | ||
<Robot className="size-8 min-w-8 text-white" /> | ||
<span>Sign in to view your guilds / create new ones</span> | ||
</div> | ||
<Button | ||
className="space-x-2" | ||
onClick={() => setIsWalletSelectorModalOpen(true)} | ||
> | ||
<SignIn /> | ||
<span className="text-md">Sign in</span> | ||
</Button> | ||
</Card> | ||
)} | ||
|
||
<section id={ActiveSection.ExploreGuilds}> | ||
<h2 className="font-bold text-lg tracking-tight">Explore verified guilds</h2> | ||
<div className="sticky top-8 z-10" ref={searchRef}> | ||
<Suspense> | ||
<GuildSearchBar queryAtom={guildQueryAtom} /> | ||
</Suspense> | ||
</div> | ||
<GuildInfiniteScroll queryAtom={guildQueryAtom} /> | ||
</section> | ||
</> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
"use client" | ||
|
||
import { PropsWithChildren } from "react" | ||
import { SWRConfig, type SWRConfiguration } from "swr" | ||
|
||
export const ExplorerSWRProvider = ({ | ||
children, | ||
value, | ||
}: PropsWithChildren<{ value: SWRConfiguration }>) => { | ||
return <SWRConfig value={value}>{children}</SWRConfig> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
"use client" | ||
|
||
import { cn } from "@/lib/utils" | ||
import { useAtomValue } from "jotai" | ||
import { isNavStuckAtom, isSearchStuckAtom } from "../atoms" | ||
|
||
export const HeaderBackground = () => { | ||
const isNavStuck = useAtomValue(isNavStuckAtom) | ||
const isSearchStuck = useAtomValue(isSearchStuckAtom) | ||
|
||
return ( | ||
<div | ||
className={cn( | ||
"fixed inset-x-0 top-0 z-10 h-0 bg-background shadow-md transition-all duration-200", | ||
{ | ||
"h-16": isNavStuck, | ||
"h-[calc(theme(space.28)-theme(space.2))] bg-gradient-to-b from-background to-card-secondary": | ||
isSearchStuck, | ||
} | ||
)} | ||
/> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
"use client" | ||
|
||
import { useWeb3ConnectionManager } from "@/components/Web3ConnectionManager/hooks/useWeb3ConnectionManager" | ||
import { Button } from "@/components/ui/Button" | ||
import { ToggleGroup, ToggleGroupItem } from "@/components/ui/ToggleGroup" | ||
import { cn } from "@/lib/utils" | ||
import { Plus } from "@phosphor-icons/react" | ||
import useIsStuck from "hooks/useIsStuck" | ||
import useScrollspy from "hooks/useScrollSpy" | ||
import { useAtom, useAtomValue, useSetAtom } from "jotai" | ||
import { useEffect } from "react" | ||
import { activeSectionAtom, isNavStuckAtom, isSearchStuckAtom } from "../atoms" | ||
import { ActiveSection } from "../types" | ||
|
||
const Nav = () => { | ||
const isNavStuck = useAtomValue(isNavStuckAtom) | ||
const isSearchStuck = useAtomValue(isSearchStuckAtom) | ||
const [activeSection, setActiveSection] = useAtom(activeSectionAtom) | ||
const spyActiveSection = useScrollspy(Object.values(ActiveSection), 100) | ||
useEffect(() => { | ||
if (!spyActiveSection) return | ||
setActiveSection(spyActiveSection as ActiveSection) | ||
}, [spyActiveSection, setActiveSection]) | ||
|
||
return ( | ||
<ToggleGroup | ||
type="single" | ||
className="gap-2" | ||
size={isSearchStuck ? "sm" : "lg"} | ||
variant={isNavStuck ? "default" : "mono"} | ||
onValueChange={(value) => value && setActiveSection(value as ActiveSection)} | ||
value={activeSection} | ||
> | ||
<ToggleGroupItem | ||
value={ActiveSection.YourGuilds} | ||
className={cn("rounded-xl transition-all", { | ||
"rounded-lg": isSearchStuck, | ||
})} | ||
asChild | ||
> | ||
<a href={`#${ActiveSection.YourGuilds}`}>Your guilds</a> | ||
</ToggleGroupItem> | ||
<ToggleGroupItem | ||
value={ActiveSection.ExploreGuilds} | ||
className={cn("rounded-xl transition-all", { | ||
"rounded-lg": isSearchStuck, | ||
})} | ||
asChild | ||
> | ||
<a href={`#${ActiveSection.ExploreGuilds}`}>Explore guilds</a> | ||
</ToggleGroupItem> | ||
</ToggleGroup> | ||
) | ||
} | ||
|
||
const CreateGuildLink = () => { | ||
const isNavStuck = useAtomValue(isNavStuckAtom) | ||
return ( | ||
<Button | ||
variant="ghost" | ||
size="sm" | ||
className={cn("gap-1.5", { | ||
"text-white": !isNavStuck, | ||
})} | ||
> | ||
<Plus /> | ||
<span>Create guild</span> | ||
</Button> | ||
) | ||
} | ||
|
||
export const StickyBar = () => { | ||
const { isWeb3Connected } = useWeb3ConnectionManager() | ||
const setIsNavStuck = useSetAtom(isNavStuckAtom) | ||
const isSearchStuck = useAtomValue(isSearchStuckAtom) | ||
const { ref: navToggleRef } = useIsStuck(setIsNavStuck) | ||
|
||
return ( | ||
<div | ||
className={cn( | ||
"sticky top-0 z-10 flex h-16 w-full items-center transition-all", | ||
{ | ||
"h-12": isSearchStuck, | ||
} | ||
)} | ||
ref={navToggleRef} | ||
> | ||
<div className="relative flex w-full items-center justify-between"> | ||
<Nav /> | ||
{isWeb3Connected && <CreateGuildLink />} | ||
</div> | ||
</div> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.