fix: 🐛

This commit is contained in:
codytseng
2025-01-14 11:55:43 +08:00
parent 35a22bd2ba
commit 6182fc914e
3 changed files with 32 additions and 32 deletions

View File

@@ -4,7 +4,7 @@ import { Separator } from '@/components/ui/separator'
import { cn } from '@/lib/utils' import { cn } from '@/lib/utils'
import NoteListPage from '@/pages/primary/NoteListPage' import NoteListPage from '@/pages/primary/NoteListPage'
import HomePage from '@/pages/secondary/HomePage' import HomePage from '@/pages/secondary/HomePage'
import { cloneElement, createContext, useContext, useEffect, useState } from 'react' import { cloneElement, createContext, ReactNode, useContext, useEffect, useState } from 'react'
import MePage from './pages/primary/MePage' import MePage from './pages/primary/MePage'
import NotificationListPage from './pages/primary/NotificationListPage' import NotificationListPage from './pages/primary/NotificationListPage'
import { useScreenSize } from './providers/ScreenSizeProvider' import { useScreenSize } from './providers/ScreenSizeProvider'
@@ -57,6 +57,14 @@ export function useSecondaryPage() {
export function PageManager({ maxStackSize = 5 }: { maxStackSize?: number }) { export function PageManager({ maxStackSize = 5 }: { maxStackSize?: number }) {
const [currentPrimaryPage, setCurrentPrimaryPage] = useState<TPrimaryPageName>('home') const [currentPrimaryPage, setCurrentPrimaryPage] = useState<TPrimaryPageName>('home')
const [primaryPages, setPrimaryPages] = useState<
{ name: TPrimaryPageName; element: ReactNode }[]
>([
{
name: 'home',
element: PRIMARY_PAGE_MAP.home
}
])
const [secondaryStack, setSecondaryStack] = useState<TStackItem[]>([]) const [secondaryStack, setSecondaryStack] = useState<TStackItem[]>([])
const { isSmallScreen } = useScreenSize() const { isSmallScreen } = useScreenSize()
@@ -104,6 +112,10 @@ export function PageManager({ maxStackSize = 5 }: { maxStackSize?: number }) {
}, []) }, [])
const navigatePrimaryPage = (page: TPrimaryPageName) => { const navigatePrimaryPage = (page: TPrimaryPageName) => {
const exists = primaryPages.find((p) => p.name === page)
if (!exists) {
setPrimaryPages((prev) => [...prev, { name: page, element: PRIMARY_PAGE_MAP[page] }])
}
setCurrentPrimaryPage(page) setCurrentPrimaryPage(page)
if (isSmallScreen) { if (isSmallScreen) {
clearSecondaryPages() clearSecondaryPages()
@@ -159,15 +171,15 @@ export function PageManager({ maxStackSize = 5 }: { maxStackSize?: number }) {
{item.component} {item.component}
</div> </div>
))} ))}
{Object.entries(PRIMARY_PAGE_MAP).map(([pageName, page]) => ( {primaryPages.map(({ name, element }) => (
<div <div
key={pageName} key={name}
style={{ style={{
display: display:
secondaryStack.length === 0 && currentPrimaryPage === pageName ? 'block' : 'none' secondaryStack.length === 0 && currentPrimaryPage === name ? 'block' : 'none'
}} }}
> >
{page} {element}
</div> </div>
))} ))}
</SecondaryPageContext.Provider> </SecondaryPageContext.Provider>
@@ -194,16 +206,16 @@ export function PageManager({ maxStackSize = 5 }: { maxStackSize?: number }) {
<Separator orientation="vertical" /> <Separator orientation="vertical" />
<ResizablePanelGroup direction="horizontal"> <ResizablePanelGroup direction="horizontal">
<ResizablePanel minSize={30}> <ResizablePanel minSize={30}>
<div {primaryPages.map(({ name, element }) => (
style={{ <div
display: !currentPrimaryPage || currentPrimaryPage === 'home' ? 'block' : 'none' key={name}
}} style={{
> display: currentPrimaryPage === name ? 'block' : 'none'
<NoteListPage /> }}
</div> >
<div style={{ display: currentPrimaryPage === 'notifications' ? 'block' : 'none' }}> {element}
<NotificationListPage /> </div>
</div> ))}
</ResizablePanel> </ResizablePanel>
<ResizableHandle /> <ResizableHandle />
<ResizablePanel minSize={30}> <ResizablePanel minSize={30}>

View File

@@ -32,7 +32,7 @@ export default function NoteList({
const { t } = useTranslation() const { t } = useTranslation()
const { isSmallScreen } = useScreenSize() const { isSmallScreen } = useScreenSize()
const { signEvent, checkLogin } = useNostr() const { signEvent, checkLogin } = useNostr()
const { isFetching: isFetchingRelayInfo, areAlgoRelays } = useFetchRelayInfos([...relayUrls]) const { areAlgoRelays } = useFetchRelayInfos([...relayUrls])
const [refreshCount, setRefreshCount] = useState(0) const [refreshCount, setRefreshCount] = useState(0)
const [timelineKey, setTimelineKey] = useState<string | undefined>(undefined) const [timelineKey, setTimelineKey] = useState<string | undefined>(undefined)
const [events, setEvents] = useState<Event[]>([]) const [events, setEvents] = useState<Event[]>([])
@@ -58,7 +58,7 @@ export default function NoteList({
}, [JSON.stringify(filter), areAlgoRelays, isPictures]) }, [JSON.stringify(filter), areAlgoRelays, isPictures])
useEffect(() => { useEffect(() => {
if (isFetchingRelayInfo || relayUrls.length === 0) return if (relayUrls.length === 0) return
async function init() { async function init() {
setRefreshing(true) setRefreshing(true)
@@ -108,13 +108,7 @@ export default function NoteList({
return () => { return () => {
promise.then((closer) => closer()) promise.then((closer) => closer())
} }
}, [ }, [JSON.stringify(relayUrls), noteFilter, areAlgoRelays, refreshCount])
JSON.stringify(relayUrls),
JSON.stringify(noteFilter),
isFetchingRelayInfo,
areAlgoRelays,
refreshCount
])
useEffect(() => { useEffect(() => {
if (refreshing) return if (refreshing) return

View File

@@ -55,21 +55,15 @@ export function FeedProvider({ children }: { children: React.ReactNode }) {
} }
if (feedType === 'following') { if (feedType === 'following') {
if (!pubkey) return
return await switchFeed('following', { pubkey }) return await switchFeed('following', { pubkey })
} else { } else {
console.log('activeRelaySetId', activeRelaySetId)
await switchFeed('relays', { activeRelaySetId }) await switchFeed('relays', { activeRelaySetId })
} }
} }
init() init()
}, []) }, [pubkey])
useEffect(() => {
if (pubkey && feedType === 'following') {
switchFeed('following', { pubkey })
}
}, [feedType, pubkey])
const switchFeed = async ( const switchFeed = async (
feedType: TFeedType, feedType: TFeedType,