feat: improve mobile experience

This commit is contained in:
codytseng
2025-01-02 21:57:14 +08:00
parent 8ec0d46d58
commit 3946e603b3
98 changed files with 2508 additions and 1058 deletions

View File

@@ -9,7 +9,7 @@ import { useNostr } from './NostrProvider'
type TFollowListContext = {
followListEvent: Event | undefined
followings: string[]
isReady: boolean
isFetching: boolean
follow: (pubkey: string) => Promise<void>
unfollow: (pubkey: string) => Promise<void>
}
@@ -27,33 +27,35 @@ export const useFollowList = () => {
export function FollowListProvider({ children }: { children: React.ReactNode }) {
const { pubkey: accountPubkey, publish } = useNostr()
const [followListEvent, setFollowListEvent] = useState<Event | undefined>(undefined)
const [isReady, setIsReady] = useState(false)
const followings = useMemo(
() =>
followListEvent?.tags
.filter(tagNameEquals('p'))
.map(([, pubkey]) => pubkey)
.filter(Boolean)
.reverse() ?? [],
[followListEvent]
)
const [isFetching, setIsFetching] = useState(true)
const followings = useMemo(() => {
return Array.from(
new Set(
followListEvent?.tags
.filter(tagNameEquals('p'))
.map(([, pubkey]) => pubkey)
.filter(Boolean)
.reverse() ?? []
)
)
}, [followListEvent])
useEffect(() => {
if (!accountPubkey) return
const init = async () => {
setIsReady(false)
setIsFetching(true)
setFollowListEvent(undefined)
const event = await client.fetchFollowListEvent(accountPubkey)
setFollowListEvent(event)
setIsReady(true)
setIsFetching(false)
}
init()
}, [accountPubkey])
const follow = async (pubkey: string) => {
if (!isReady || !accountPubkey) return
if (isFetching || !accountPubkey) return
const newFollowListDraftEvent: TDraftEvent = {
kind: kinds.Contacts,
@@ -67,7 +69,7 @@ export function FollowListProvider({ children }: { children: React.ReactNode })
}
const unfollow = async (pubkey: string) => {
if (!isReady || !accountPubkey || !followListEvent) return
if (isFetching || !accountPubkey || !followListEvent) return
const newFollowListDraftEvent: TDraftEvent = {
kind: kinds.Contacts,
@@ -87,7 +89,7 @@ export function FollowListProvider({ children }: { children: React.ReactNode })
value={{
followListEvent,
followings,
isReady,
isFetching,
follow,
unfollow
}}