fix: some 🐛

This commit is contained in:
codytseng
2025-01-04 12:55:55 +08:00
parent 72e1478e43
commit 14eee0240b
7 changed files with 44 additions and 14 deletions

View File

@@ -8,7 +8,7 @@ export default function BottomNavigationBar({ visible = true }: { visible?: bool
return ( return (
<div <div
className={cn( className={cn(
'fixed bottom-0 w-full z-20 bg-background/90 backdrop-blur-xl duration-700 transition-transform flex items-center justify-around [&_svg]:size-4 [&_svg]:shrink-0', 'fixed bottom-0 w-full z-20 bg-background/80 backdrop-blur-xl duration-700 transition-transform flex items-center justify-around [&_svg]:size-4 [&_svg]:shrink-0',
visible ? '' : 'translate-y-full' visible ? '' : 'translate-y-full'
)} )}
style={{ style={{

View File

@@ -12,7 +12,7 @@ export function Titlebar({
return ( return (
<div <div
className={cn( className={cn(
'fixed sm:sticky top-0 w-full z-20 bg-background/90 backdrop-blur-xl duration-700 transition-transform [&_svg]:size-4 [&_svg]:shrink-0', 'fixed sm:sticky top-0 w-full z-20 bg-background duration-700 transition-transform [&_svg]:size-4 [&_svg]:shrink-0',
visible ? '' : '-translate-y-full', visible ? '' : '-translate-y-full',
className className
)} )}

View File

@@ -29,9 +29,9 @@ export default function WebPreview({
if (isSmallScreen && image) { if (isSmallScreen && image) {
return ( return (
<div className="relative border rounded-lg w-full h-44"> <div className="rounded-lg border mt-2">
<Image src={image} className="rounded-lg object-cover w-full h-full" removeWrapper /> <Image src={image} className="rounded-t-lg object-cover w-full h-44" removeWrapper />
<div className="absolute bottom-0 z-10 bg-muted/70 px-2 py-1 w-full rounded-b-lg"> <div className="bg-muted p-2 w-full rounded-b-lg">
<div className="text-xs text-muted-foreground">{hostname}</div> <div className="text-xs text-muted-foreground">{hostname}</div>
<div className="font-semibold line-clamp-1">{title}</div> <div className="font-semibold line-clamp-1">{title}</div>
</div> </div>

View File

@@ -53,6 +53,17 @@ const PrimaryPageLayout = forwardRef(
if (current !== pageName) return if (current !== pageName) return
const handleScroll = () => { const handleScroll = () => {
const atBottom = isSmallScreen
? window.innerHeight + window.scrollY >= document.body.offsetHeight - 20
: scrollAreaRef.current
? scrollAreaRef.current?.clientHeight + scrollAreaRef.current?.scrollTop >=
scrollAreaRef.current?.scrollHeight - 20
: false
if (atBottom) {
setVisible(true)
return
}
const scrollTop = (isSmallScreen ? window.scrollY : scrollAreaRef.current?.scrollTop) || 0 const scrollTop = (isSmallScreen ? window.scrollY : scrollAreaRef.current?.scrollTop) || 0
const diff = scrollTop - lastScrollTop const diff = scrollTop - lastScrollTop
if (scrollTop <= 800) { if (scrollTop <= 800) {
@@ -99,7 +110,7 @@ const PrimaryPageLayout = forwardRef(
{displayScrollToTopButton && ( {displayScrollToTopButton && (
<ScrollToTopButton <ScrollToTopButton
scrollAreaRef={scrollAreaRef} scrollAreaRef={scrollAreaRef}
visible={visible && lastScrollTop > 500} visible={visible && lastScrollTop > 800}
/> />
)} )}
{isSmallScreen && <BottomNavigationBar visible={visible} />} {isSmallScreen && <BottomNavigationBar visible={visible} />}

View File

@@ -39,9 +39,20 @@ export default function SecondaryPageLayout({
if (currentIndex !== index) return if (currentIndex !== index) return
const handleScroll = () => { const handleScroll = () => {
const atBottom = isSmallScreen
? window.innerHeight + window.scrollY >= document.body.offsetHeight - 20
: scrollAreaRef.current
? scrollAreaRef.current?.clientHeight + scrollAreaRef.current?.scrollTop >=
scrollAreaRef.current?.scrollHeight - 20
: false
if (atBottom) {
setVisible(true)
return
}
const scrollTop = (isSmallScreen ? window.scrollY : scrollAreaRef.current?.scrollTop) || 0 const scrollTop = (isSmallScreen ? window.scrollY : scrollAreaRef.current?.scrollTop) || 0
const diff = scrollTop - lastScrollTop const diff = scrollTop - lastScrollTop
if (scrollTop <= 100) { if (scrollTop <= 800) {
setVisible(true) setVisible(true)
setLastScrollTop(scrollTop) setLastScrollTop(scrollTop)
return return
@@ -75,7 +86,7 @@ export default function SecondaryPageLayout({
scrollBarClassName="sm:z-50" scrollBarClassName="sm:z-50"
ref={scrollAreaRef} ref={scrollAreaRef}
style={{ style={{
paddingBottom: isSmallScreen ? 'env(safe-area-inset-bottom) + 3rem)' : '' paddingBottom: isSmallScreen ? 'calc(env(safe-area-inset-bottom) + 3rem)' : ''
}} }}
> >
<SecondaryPageTitlebar <SecondaryPageTitlebar
@@ -85,7 +96,7 @@ export default function SecondaryPageLayout({
/> />
<div className="pb-4 mt-2">{children}</div> <div className="pb-4 mt-2">{children}</div>
{displayScrollToTopButton && ( {displayScrollToTopButton && (
<ScrollToTopButton scrollAreaRef={scrollAreaRef} visible={visible && lastScrollTop > 500} /> <ScrollToTopButton scrollAreaRef={scrollAreaRef} visible={visible && lastScrollTop > 800} />
)} )}
{isSmallScreen && <BottomNavigationBar visible={visible} />} {isSmallScreen && <BottomNavigationBar visible={visible} />}
</ScrollArea> </ScrollArea>

View File

@@ -1,4 +1,5 @@
import NoteList from '@/components/NoteList' import NoteList from '@/components/NoteList'
import { SEARCHABLE_RELAY_URLS } from '@/constants'
import { useSearchParams } from '@/hooks' import { useSearchParams } from '@/hooks'
import SecondaryPageLayout from '@/layouts/SecondaryPageLayout' import SecondaryPageLayout from '@/layouts/SecondaryPageLayout'
import { isWebsocketUrl, simplifyUrl } from '@/lib/url' import { isWebsocketUrl, simplifyUrl } from '@/lib/url'
@@ -27,7 +28,14 @@ export default function NoteListPage({ index }: { index?: number }) {
} }
const search = searchParams.get('s') const search = searchParams.get('s')
if (search) { if (search) {
return { title: `${t('Search')}: ${search}`, filter: { search }, urls: searchableRelayUrls } return {
title: `${t('Search')}: ${search}`,
filter: { search },
urls:
searchableRelayUrls.length < 4
? searchableRelayUrls.concat(SEARCHABLE_RELAY_URLS).slice(0, 4)
: searchableRelayUrls
}
} }
const relayUrl = searchParams.get('relay') const relayUrl = searchParams.get('relay')
if (relayUrl && isWebsocketUrl(relayUrl)) { if (relayUrl && isWebsocketUrl(relayUrl)) {
@@ -38,7 +46,7 @@ export default function NoteListPage({ index }: { index?: number }) {
if (filter?.search && searchableRelayUrls.length === 0) { if (filter?.search && searchableRelayUrls.length === 0) {
return ( return (
<SecondaryPageLayout index={index} titlebarContent={title} displayScrollToTopButton> <SecondaryPageLayout index={index} titlebarContent={title}>
<div className="text-center text-sm text-muted-foreground"> <div className="text-center text-sm text-muted-foreground">
{t('The relays you are connected to do not support search')} {t('The relays you are connected to do not support search')}
</div> </div>
@@ -47,7 +55,7 @@ export default function NoteListPage({ index }: { index?: number }) {
} }
return ( return (
<SecondaryPageLayout index={index} titlebarContent={title}> <SecondaryPageLayout index={index} titlebarContent={title} displayScrollToTopButton>
<NoteList key={title} filter={filter} relayUrls={urls} /> <NoteList key={title} filter={filter} relayUrls={urls} />
</SecondaryPageLayout> </SecondaryPageLayout>
) )

View File

@@ -22,7 +22,7 @@ export default function NotePage({ id, index }: { id?: string; index?: number })
if (!event && isFetching) { if (!event && isFetching) {
return ( return (
<SecondaryPageLayout index={index} titlebarContent={t('Note')} displayScrollToTopButton> <SecondaryPageLayout index={index} titlebarContent={t('Note')}>
<div className="px-4"> <div className="px-4">
<Skeleton className="w-10 h-10 rounded-full" /> <Skeleton className="w-10 h-10 rounded-full" />
</div> </div>
@@ -32,7 +32,7 @@ export default function NotePage({ id, index }: { id?: string; index?: number })
if (!event) return <NotFoundPage /> if (!event) return <NotFoundPage />
return ( return (
<SecondaryPageLayout index={index} titlebarContent={t('Note')}> <SecondaryPageLayout index={index} titlebarContent={t('Note')} displayScrollToTopButton>
<div className="px-4"> <div className="px-4">
<ParentNote key={`root-note-${event.id}`} eventId={rootEventId} /> <ParentNote key={`root-note-${event.id}`} eventId={rootEventId} />
<ParentNote key={`parent-note-${event.id}`} eventId={parentEventId} /> <ParentNote key={`parent-note-${event.id}`} eventId={parentEventId} />