nomadro/apps/miniprogram/h5/src/pages/social/people/index.tsx
Eric f20406397a Harden social UX and APIs: idempotent chat/join, config cache, weapp polish.
Improve hall chat retries, meetup-live lifecycle, home/mine remote-config UX, and add isolated social/API regression tests without deploying.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-11-02 14:00:11 +08:00

223 lines
9.5 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { useSocialLikes } from '@/services/socialLocal'
import { useSocialContent } from '@/hooks/useSocialContent'
import { useSocialPage } from '@/hooks/useSocialPage'
import { useEffect, useMemo, useState, type CSSProperties } from 'react'
import { useRouter } from '@tarojs/taro'
import { Input } from '@tarojs/components'
import type { SocialCafe } from '@/data/socialTypes'
import { CafeReviews } from '../_components/CafeReviews'
import { MiniModuleGate } from '@/components/MiniModuleGate'
import {
MOCK_ROSTER,
SEED_CAFES,
SEED_GIGS,
SOCIAL_CITIES,
TEAM_KIND_LABEL,
ROLE_EMOJI,
} from '@/data/socialSeed'
import { goSocialPage as goPage } from '@/utils/socialNavigation'
import { usePageShare } from '@/utils/pageShare'
import { usePageTrack } from '@/hooks/usePageTrack'
import { getSafeAreaMetrics, safePx } from '@/utils/safeArea'
import { PeopleChip } from '../_components/PeopleChip'
import { SocialDock } from '../_components/SocialDock'
import { SocialExperience } from '../_components/SocialExperience'
import { H5El } from '../_components/H5El'
import '@/styles/social-next/entry'
import './index.scss'
function SocialPeople() {
const { theme, pageStyle } = useSocialPage()
usePageShare({ title: 'nomadro · 想见的人', path: '/pages/social/people/index' })
usePageTrack('social_people')
const router = useRouter()
const mode = ['all', 'cafe', 'team'].includes(String(router.params?.mode)) ? String(router.params?.mode) : 'all'
const { roster, cafes, pages } = useSocialContent()
const [filter, setFilter] = useState<'all' | 'online' | 'f' | 'm' | 'liked'>('all')
const [query, setQuery] = useState('')
const [city, setCity] = useState(() => {
const value = String(router.params?.city || '')
return SOCIAL_CITIES.find((item) => item.id === value || item.name === value)?.name || value
})
const [activeCafe, setActiveCafe] = useState<SocialCafe | null>(null)
const [likes, setLikes] = useSocialLikes()
const safe = useMemo(() => getSafeAreaMetrics(), [])
useEffect(() => {
if (mode === 'team') goPage('/pages/social/team/index')
}, [mode])
const title =
mode === 'cafe' ? '同城,见一面' : mode === 'team' ? '一起,做点事' : '想见的人'
const list = useMemo(() => {
return roster.filter((m) => {
if (city && !m.city.includes(city)) return false
const q = query.trim().toLowerCase()
if (q && !`${m.name} ${m.title} ${m.city} ${m.tags.join(' ')} ${m.lookingFor}`.toLowerCase().includes(q)) return false
if (filter === 'liked') return !!likes[m.id]
if (filter === 'online') return m.online
if (filter === 'f' || filter === 'm') return m.gender === filter
return true
})
}, [filter, roster, query, city, likes])
const visibleCafes = cafes.filter((cafe) => (!city || cafe.city.includes(city)) &&
(!query.trim() || `${cafe.name} ${cafe.city} ${cafe.vibe}`.toLowerCase().includes(query.trim().toLowerCase())))
const clearFilters = () => { setCity(''); setQuery(''); setFilter('all') }
return (
<SocialExperience>
<H5El
className='soc-taro-root social-root social-workspace social-home social-weapp'
data-theme={theme}
style={pageStyle}
>
<H5El className='social-live-bar'>
<H5El className='social-live-bar-main'>
<H5El
as='button'
type='button'
className='social-nav-back'
onClick={() => goPage('/pages/social/index')}
>
← 首页
</H5El>
<H5El>
<H5El as='strong'>{pages[mode === 'cafe' ? 'coffeechat' : 'people']?.title || title}</H5El>
<H5El as='span' className='social-muted'>
{pages[mode === 'cafe' ? 'coffeechat' : 'people']?.description || '示例介绍 · 离线可逛'}
</H5El>
</H5El>
<H5El
as='button'
type='button'
className='btn btn-sm'
onClick={() => goPage('/pages/social/date/index')}
>
认识一下
</H5El>
</H5El>
</H5El>
<H5El className='container social-sub-body'>
<H5El className='social-search-row'><Input className='social-field-input' value={query} maxlength={80}
placeholder={mode === 'cafe' ? '搜索城市、咖啡馆或想认识的人' : '搜索昵称、城市、职业或兴趣'}
confirmType='search' onInput={(event) => setQuery(event.detail.value)} /></H5El>
<H5El className='social-search-summary'>
<H5El as='span'>{city ? `${city} · ` : ''}{list.length} 份介绍{mode === 'cafe' ? ` · ${visibleCafes.length} 家咖啡馆` : ''}</H5El>
<H5El as='button' className='btn btn-ghost' onClick={clearFilters}>清空筛选</H5El>
</H5El>
<H5El className='social-section-actions'>
<H5El as='button' className='btn' onClick={() => goPage('/pages/social/roster/index')}>编辑我的介绍</H5El>
</H5El>
{mode === 'cafe' ? (
<>
<H5El className='social-panel-grid social-panel-grid-2 social-sub-block'>
{SOCIAL_CITIES.filter((c) => c.hot)
.slice(0, 6)
.map((c) => (
<H5El key={c.id} className='social-panel' role='button' aria-pressed={city === c.name}
onClick={() => setCity(city === c.name ? '' : c.name)}>
<H5El as='span' style={{ fontSize: 26 }}>
{c.emoji}
</H5El>
<H5El as='strong'>{c.name}</H5El>
<H5El as='p' className='social-muted'>
{c.vibe}
</H5El>
</H5El>
))}
</H5El>
<H5El className='social-panel-grid social-panel-grid-2 social-sub-block'>
{visibleCafes.map((cafe) => (
<H5El key={cafe.id} className='social-panel'>
<H5El as='strong'>☕ {cafe.name}</H5El>
<H5El as='p' className='social-muted'>
{cafe.city} · WiFi {cafe.wifiMbps}Mbps
</H5El>
<H5El as='p'>{cafe.vibe}</H5El>
<H5El as='button' className='btn' onClick={() => setActiveCafe(cafe)}>查看与分享评价</H5El>
</H5El>
))}
</H5El>
{!visibleCafes.length ? <H5El className='social-panel social-empty-state'>
<H5El as='strong'>这个筛选下暂未收录咖啡馆</H5El><H5El as='button' className='btn' onClick={clearFilters}>看看全部咖啡馆</H5El>
</H5El> : null}
</>
) : null}
{mode === 'team' ? (
<H5El className='social-panel-grid social-panel-grid-2 social-sub-block'>
{SEED_GIGS.map((g) => (
<H5El key={g.id} className='social-panel'>
<H5El as='span'>{ROLE_EMOJI[g.kind || 'parttime']}</H5El>
<H5El as='span' className='social-muted'>
{TEAM_KIND_LABEL[g.kind || 'parttime']}
</H5El>
<H5El as='strong'>{g.title}</H5El>
<H5El as='p'>{g.pay}</H5El>
</H5El>
))}
</H5El>
) : null}
{mode === 'all' || mode === 'cafe' ? (
<>
<H5El className='social-people-filters'>
{(
[
['all', '全部', '✨'],
['online', '在线', '🟢'],
['f', '女生', '👩'],
['m', '男生', '👨'],
['liked', '已关注', '♥'],
] as const
).map(([id, label, emoji]) => (
<H5El
key={id}
as='button'
type='button'
className={`social-people-filter${filter === id ? ' is-on active' : ''}`}
aria-pressed={filter === id}
onClick={() => setFilter(id)}
>
{emoji} {label}
</H5El>
))}
</H5El>
{!list.length ? <H5El className='social-panel social-empty-state'>
<H5El as='strong'>{filter === 'liked' ? '还没有符合筛选的关注' : '暂时没有匹配的介绍'}</H5El>
<H5El as='p' className='social-muted'>换个关键词,或看看其他城市的人。</H5El>
<H5El as='button' className='btn' onClick={clearFilters}>查看全部介绍</H5El>
</H5El> : null}
<H5El className='social-people-grid'>
{list.map((m, i) => (
<PeopleChip
key={m.id}
member={m}
liked={!!likes[m.id]}
staggerMs={Math.min(i, 12) * 40}
onToggleLike={() =>
setLikes((prev) => ({ ...prev, [m.id]: !prev[m.id] }))
}
/>
))}
</H5El>
</>
) : null}
</H5El>
{activeCafe ? <CafeReviews key={activeCafe.id} cafe={activeCafe} onClose={() => setActiveCafe(null)} /> : null}
<SocialDock />
</H5El>
</SocialExperience>
)
}
export default function SocialPeoplePage() {
return (
<MiniModuleGate moduleKey='social'>
<SocialPeople />
</MiniModuleGate>
)
}