-
Notifications
You must be signed in to change notification settings - Fork 3
fix: Thread bar shows correct origin (Network, Profile, My Spaces) #2015
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
webguru-hypha
wants to merge
1
commit into
main
Choose a base branch
from
cursor/web-application-issue-1614-711e
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
21 changes: 21 additions & 0 deletions
21
apps/web/src/app/[lang]/dho/[id]/_components/breadcrumb-space-item.tsx
This file contains hidden or 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,21 @@ | ||
| 'use client'; | ||
|
|
||
| import { SpaceBreadcrumbItem } from '@hypha-platform/epics'; | ||
| import { useBreadcrumbFrom } from './breadcrumbs-root-selector'; | ||
|
|
||
| export function BreadcrumbSpaceItem({ | ||
| breadcrumb, | ||
| lang, | ||
| }: { | ||
| breadcrumb: { slug: string; title: string }; | ||
| lang: string; | ||
| }) { | ||
| const fromQuery = useBreadcrumbFrom(); | ||
| return ( | ||
| <SpaceBreadcrumbItem | ||
| breadcrumb={breadcrumb} | ||
| lang={lang} | ||
| fromQuery={fromQuery} | ||
| /> | ||
| ); | ||
| } |
165 changes: 165 additions & 0 deletions
165
apps/web/src/app/[lang]/dho/[id]/_components/breadcrumbs-root-selector.tsx
This file contains hidden or 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,165 @@ | ||
| 'use client'; | ||
|
|
||
| import { | ||
| Breadcrumb, | ||
| BreadcrumbItem, | ||
| BreadcrumbLink, | ||
| BreadcrumbList, | ||
| } from '@hypha-platform/ui'; | ||
| import { useSearchParams, useParams } from 'next/navigation'; | ||
| import { useTranslations } from 'next-intl'; | ||
| import { createContext, useContext, useEffect, useMemo } from 'react'; | ||
|
|
||
| const BREADCRUMB_ORIGIN_COOKIE = 'breadcrumb_origin'; | ||
| const COOKIE_MAX_AGE_DAYS = 1; | ||
|
|
||
| type BreadcrumbOrigin = 'network' | 'profile' | 'my-spaces'; | ||
|
|
||
| function getBreadcrumbOriginFromCookie(): { | ||
| from: BreadcrumbOrigin; | ||
| profileSlug?: string; | ||
| } | null { | ||
| if (typeof document === 'undefined') return null; | ||
| const match = document.cookie.match( | ||
| new RegExp(`(?:^|; )${BREADCRUMB_ORIGIN_COOKIE}=([^;]*)`), | ||
| ); | ||
| if (!match?.[1]) return null; | ||
| try { | ||
| return JSON.parse(decodeURIComponent(match[1])) as { | ||
| from: BreadcrumbOrigin; | ||
| profileSlug?: string; | ||
| }; | ||
| } catch { | ||
| return null; | ||
| } | ||
| } | ||
|
|
||
| function setBreadcrumbOriginCookie(from: BreadcrumbOrigin, profileSlug?: string) { | ||
| if (typeof document === 'undefined') return; | ||
| const value = JSON.stringify( | ||
| profileSlug ? { from, profileSlug } : { from }, | ||
| ); | ||
| document.cookie = `${BREADCRUMB_ORIGIN_COOKIE}=${encodeURIComponent(value)}; path=/; max-age=${60 * 60 * 24 * COOKIE_MAX_AGE_DAYS}; SameSite=Lax`; | ||
| } | ||
|
|
||
| function getFromQuery(from: BreadcrumbOrigin, profileSlug?: string): string { | ||
| if (from === 'profile' && profileSlug) { | ||
| return `from=profile&profileSlug=${encodeURIComponent(profileSlug)}`; | ||
| } | ||
| return `from=${from}`; | ||
| } | ||
|
|
||
| const BreadcrumbFromContext = createContext<string | undefined>(undefined); | ||
|
|
||
| export function useBreadcrumbFrom() { | ||
| return useContext(BreadcrumbFromContext); | ||
| } | ||
|
|
||
| /** Returns the from query string for preserving breadcrumb origin in links */ | ||
| export function useBreadcrumbFromQuery(): string | undefined { | ||
| const searchParams = useSearchParams(); | ||
| const from = searchParams.get('from') as BreadcrumbOrigin | null; | ||
| const profileSlug = searchParams.get('profileSlug'); | ||
|
|
||
| return useMemo(() => { | ||
| let resolvedFrom = from; | ||
| let resolvedProfileSlug = profileSlug; | ||
|
|
||
| if (!resolvedFrom) { | ||
| const cookie = getBreadcrumbOriginFromCookie(); | ||
| if (cookie) { | ||
| resolvedFrom = cookie.from; | ||
| resolvedProfileSlug = cookie.profileSlug ?? null; | ||
| } else { | ||
| return undefined; | ||
| } | ||
| } | ||
|
|
||
| return getFromQuery( | ||
| resolvedFrom, | ||
| resolvedProfileSlug ?? undefined, | ||
| ); | ||
| }, [from, profileSlug]); | ||
| } | ||
|
|
||
| export function BreadcrumbsRootSelector({ | ||
| children, | ||
| }: { | ||
| children: React.ReactNode; | ||
| }) { | ||
| const searchParams = useSearchParams(); | ||
| const params = useParams<{ lang: string }>(); | ||
| const lang = params?.lang ?? 'en'; | ||
| const tNavigation = useTranslations('Navigation'); | ||
|
|
||
| const from = searchParams.get('from') as BreadcrumbOrigin | null; | ||
| const profileSlug = searchParams.get('profileSlug'); | ||
|
|
||
| const { rootHref, rootLabel, fromQuery } = useMemo(() => { | ||
| let resolvedFrom = from; | ||
| let resolvedProfileSlug = profileSlug; | ||
|
|
||
| if (!resolvedFrom) { | ||
| const cookie = getBreadcrumbOriginFromCookie(); | ||
| if (cookie) { | ||
| resolvedFrom = cookie.from; | ||
| resolvedProfileSlug = cookie.profileSlug ?? null; | ||
| } else { | ||
| resolvedFrom = 'my-spaces'; | ||
| } | ||
| } else { | ||
| setBreadcrumbOriginCookie( | ||
| resolvedFrom, | ||
| resolvedProfileSlug ?? undefined, | ||
| ); | ||
| } | ||
|
|
||
| let href: string; | ||
| let label: string; | ||
|
|
||
| switch (resolvedFrom) { | ||
| case 'network': | ||
| href = `/${lang}/network`; | ||
| label = tNavigation('network'); | ||
| break; | ||
| case 'profile': | ||
| href = resolvedProfileSlug | ||
| ? `/${lang}/profile/${resolvedProfileSlug}` | ||
| : `/${lang}/profile`; | ||
| label = tNavigation('profile'); | ||
| break; | ||
| case 'my-spaces': | ||
| default: | ||
| href = `/${lang}/my-spaces`; | ||
| label = tNavigation('mySpaces'); | ||
| break; | ||
| } | ||
|
|
||
| const query = getFromQuery(resolvedFrom, resolvedProfileSlug ?? undefined); | ||
|
|
||
| return { rootHref: href, rootLabel: label, fromQuery: query }; | ||
| }, [from, profileSlug, lang, tNavigation]); | ||
|
|
||
| useEffect(() => { | ||
| if (from) { | ||
| setBreadcrumbOriginCookie(from, profileSlug ?? undefined); | ||
| } | ||
| }, [from, profileSlug]); | ||
|
|
||
| const contextValue = useMemo(() => fromQuery, [fromQuery]); | ||
|
|
||
| return ( | ||
| <BreadcrumbFromContext.Provider value={contextValue}> | ||
| <Breadcrumb> | ||
| <BreadcrumbList> | ||
| <BreadcrumbItem> | ||
| <BreadcrumbLink href={rootHref} className="flex items-center"> | ||
| {rootLabel} | ||
| </BreadcrumbLink> | ||
| </BreadcrumbItem> | ||
| {children} | ||
| </BreadcrumbList> | ||
| </Breadcrumb> | ||
| </BreadcrumbFromContext.Provider> | ||
| ); | ||
| } | ||
This file contains hidden or 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
59 changes: 59 additions & 0 deletions
59
apps/web/src/app/[lang]/dho/[id]/_components/spaces-carousel-with-from.tsx
This file contains hidden or 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 { | ||
| SpaceCard, | ||
| getDhoPathAgreements, | ||
| } from '@hypha-platform/epics'; | ||
| import { | ||
| isSpaceArchived, | ||
| DEFAULT_SPACE_LEAD_IMAGE, | ||
| type Space, | ||
| } from '@hypha-platform/core/client'; | ||
| import { Carousel, CarouselContent, CarouselItem } from '@hypha-platform/ui'; | ||
| import Link from 'next/link'; | ||
| import { Locale } from '@hypha-platform/i18n'; | ||
| import { useBreadcrumbFromQuery } from './breadcrumbs-root-selector'; | ||
|
|
||
| export function SpacesCarouselWithFrom({ | ||
| spaces, | ||
| lang, | ||
| }: { | ||
| spaces: Space[]; | ||
| lang: Locale; | ||
| }) { | ||
| const fromQuery = useBreadcrumbFromQuery(); | ||
|
|
||
| return ( | ||
| <Carousel className="my-6 mt-6"> | ||
| <CarouselContent className="pb-5" showScrollbar> | ||
| {spaces.map((space) => { | ||
| const baseHref = getDhoPathAgreements(lang, space.slug as string); | ||
| const href = fromQuery ? `${baseHref}?${fromQuery}` : baseHref; | ||
| return ( | ||
| <CarouselItem | ||
| key={space.id} | ||
| className="w-full sm:w-[454px] max-w-[454px] flex-shrink-0" | ||
| > | ||
| <Link className="flex flex-col flex-1" href={href}> | ||
| <SpaceCard | ||
| description={space.description as string} | ||
| icon={space.logoUrl || ''} | ||
| leadImage={space.leadImage || DEFAULT_SPACE_LEAD_IMAGE} | ||
| members={space.memberCount} | ||
| agreements={space.documentCount} | ||
| title={space.title as string} | ||
| isSandbox={space.flags?.includes('sandbox') ?? false} | ||
| isDemo={space.flags?.includes('demo') ?? false} | ||
| isArchived={isSpaceArchived(space)} | ||
| web3SpaceId={space.web3SpaceId as number} | ||
| configPath={`${baseHref}/space-configuration`} | ||
| createdAt={space.createdAt} | ||
| /> | ||
| </Link> | ||
| </CarouselItem> | ||
| ); | ||
| })} | ||
| </CarouselContent> | ||
| </Carousel> | ||
| ); | ||
| } |
This file contains hidden or 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 hidden or 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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Validate
frombefore using it in cookie/query propagation.Line 61 and Line 95 trust
fromvia type-cast only. A crafted value (e.g.?from=foo) can be persisted to cookie and forwarded infromQuery, creating inconsistent breadcrumb behavior across navigation.🔧 Proposed fix
Also applies to: 95-97, 111-114, 138-140
🤖 Prompt for AI Agents