import './style.css'
const Home = () => {
return (
<div>Home</div>
)
}
export default Home
.tabContainer {
position: fixed;
height: 50px;
top: 0;
width: 100%;
}
.listContainer {
position: fixed;
top: 50px;
bottom: 0px;
width: 100%;
}
import { Tabs } from 'antd-mobile'
import './style.css'
const Home = () => {
return (
<div className="tabContainer">
<Tabs defaultActiveKey="0">
<Tabs.Tab title='abc' key='0'>
<div className="listContainer">
{}
</div>
</Tabs.Tab>
</Tabs>
{
}
</div>
)
}
export default Home
import { http } from '@/utils'
import type { ResType } from './shared'
export type ChannelItem = {
id: string
name: string
}
type ChannelRes = {
channels: ChannelItem[]
}
export function fetchChannelAPI() {
return http.request<ResType<ChannelRes>>({
url: '/channels',
})
}
import { fetchChannelAPI } from '@/apis/list'
import type { ChannelItem } from '@/apis/list'
import { useEffect, useState } from 'react'
function useFetchChannels() {
const [channels, setChannels] = useState<ChannelItem[]>([])
useEffect(() => {
async function getChannels() {
try {
const { data } = await fetchChannelAPI()
setChannels(data.data.channels)
} catch (error) {
throw new Error('fetch channels error')
}
}
getChannels()
}, [])
return {
channels,
}
}
export { useFetchChannels }
import { Tabs } from 'antd-mobile'
import HomeList from './HomeList'
import { useFetchChannels } from './useFetchChannels'
import './style.css'
const Home = () => {
const { channels } = useFetchChannels()
return (
<Tabs defaultActiveKey="0">
{channels.map((item) => (
<Tabs.Tab title={item.name} key={item.id}>
<div className="listContainer">
{}
</div>
</Tabs.Tab>
))}
</Tabs>
)
}
export default Home
import { Image, List } from 'antd-mobile'
import { users } from './users'
const HomeList = () => {
return (
<>
<List>
{users.map((item) => (
<List.Item
key={item.id}
prefix={
<Image
src={item.avatar}
style={{ borderRadius: 20 }}
fit="cover"
width={40}
height={40}
/>
}
description={item.description}
>
{item.name}
</List.Item>
))}
</List>
</>
)
}
export default HomeList
export const users = [
{
id: '1',
avatar:
'https://images.unsplash.com/photo-1548532928-b34e3be62fc6?ixlib=rb-1.2.1&q=80&fm=jpg&crop=faces&fit=crop&h=200&w=200&ixid=eyJhcHBfaWQiOjE3Nzg0fQ',
name: 'Novalee Spicer',
description: 'Deserunt dolor ea eaque eos',
},
{
id: '2',
avatar:
'https://images.unsplash.com/photo-1493666438817-866a91353ca9?ixlib=rb-0.3.5&q=80&fm=jpg&crop=faces&fit=crop&h=200&w=200&s=b616b2c5b373a80ffc9636ba24f7a4a9',
name: 'Sara Koivisto',
description: 'Animi eius expedita, explicabo',
},
{
id: '3',
avatar:
'https://images.unsplash.com/photo-1542624937-8d1e9f53c1b9?ixlib=rb-1.2.1&q=80&fm=jpg&crop=faces&fit=crop&h=200&w=200&ixid=eyJhcHBfaWQiOjE3Nzg0fQ',
name: 'Marco Gregg',
description: 'Ab animi cumque eveniet ex harum nam odio omnis',
},
{
id: '4',
avatar:
'https://images.unsplash.com/photo-1546967191-fdfb13ed6b1e?ixlib=rb-1.2.1&q=80&fm=jpg&crop=faces&fit=crop&h=200&w=200&ixid=eyJhcHBfaWQiOjE3Nzg0fQ',
name: 'Edith Koenig',
description: 'Commodi earum exercitationem id numquam vitae',
},
]
export type ListParams = {
channel_id: string
timestamp: string
}
type ListItem = {
art_id: string
title: string
aut_id: string
comm_count: number
pubdate: string
aut_name: string
is_top: 0 | 1
cover: {
type: 0 | 1 | 3
images: string[]
}
}
export type ListRes = {
results: ListItem[]
pre_timestamp: string
}
export function fetchListAPI(params: ListParams) {
return http.request<ResType<ListRes>>({
url: '/articles',
params,
})
}
import { ListRes, fetchListAPI } from '@/apis/list'
import { Image, List } from 'antd-mobile'
import { useState, useEffect } from 'react'
const HomeList = (props: Props) => {
const { channelId } = props
const [listRes, setListRes] = useState<ListRes>({
results: [],
pre_timestamp: '' + new Date().getTime(),
})
useEffect(() => {
async function getList() {
try {
const res = await fetchListAPI({
channel_id: '0',
timestamp: '' + new Date().getTime(),
})
setListRes(res.data.data)
} catch (error) {
throw new Error('fetch list error')
}
}
getList()
}, [])
return (
<>
<List>
{listRes.results.map((item) => (
<List.Item
key={item.art_id}
prefix={
<Image
src={item.cover.images?.[0]}
style={{ borderRadius: 20 }}
fit="cover"
width={40}
height={40}
/>
}
description={item.pubdate}>
>
{item.title}
</List.Item>
))}
</List>
</>
)
}
export default HomeList
import { ListRes, fetchListAPI } from '@/apis/list'
import { Image, List, InfiniteScroll } from 'antd-mobile'
import { useState, useEffect } from 'react'
type Props = {
channelId: string
}
const HomeList = (props: Props) => {
const { channelId } = props
const [listRes, setListRes] = useState<ListRes>({
results: [],
pre_timestamp: '' + new Date().getTime(),
})
useEffect(() => {
async function getList() {
try {
const res = await fetchListAPI({
channel_id: channelId,
timestamp: '' + new Date().getTime(),
})
setListRes(res.data.data)
} catch (error) {
throw new Error('fetch list error')
}
}
getList()
}, [channelId])
return (
<>
<List>
{listRes.results.map((item) => (
<List.Item
key={item.art_id}
prefix={
<Image
src={item.cover.images?.[0]}
style={{ borderRadius: 20 }}
fit="cover"
width={40}
height={40}
/>
}>
{item.title}
</List.Item>
))}
</List>
</>
)
}
export default HomeList
<Tabs.Tab title={item.name} key={item.id}>
{}
<HomeList channelId={'' + item.id} />
</Tabs.Tab>
<div className="listContainer">
{}
</div>
import { ListRes, fetchListAPI } from '@/apis/list'
import { Image, List, InfiniteScroll } from 'antd-mobile'
import { useState, useEffect } from 'react'
type Props = {
channelId: string
}
const HomeList = (props: Props) => {
const { channelId } = props
const [listRes, setListRes] = useState<ListRes>({
results: [],
pre_timestamp: '' + new Date().getTime(),
})
useEffect(() => {
async function getList() {
try {
const res = await fetchListAPI({
channel_id: channelId,
timestamp: '' + new Date().getTime(),
})
setListRes(res.data.data)
} catch (error) {
throw new Error('fetch list error')
}
}
getList()
}, [channelId])
const [hasMore, setHadMore] = useState(true)
const loadMore = async () => {
try {
const res = await fetchListAPI({
channel_id: channelId,
timestamp: listRes.pre_timestamp,
})
if (res.data.data.results.length === 0) {
setHadMore(false)
}
setListRes({
results: [...listRes.results, ...res.data.data.results],
pre_timestamp: res.data.data.pre_timestamp,
})
} catch (error) {
throw new Error('load list error')
}
}
return (
<>
<List>
{listRes.results.map((item) => (
<List.Item
key={item.art_id}
prefix={
<Image
src={item.cover.images?.[0]}
style={{ borderRadius: 20 }}
fit="cover"
width={40}
height={40}
/>
}>
{item.title}
</List.Item>
))}
</List>
<InfiniteScroll loadMore={loadMore} hasMore={hasMore} />
</>
)
}
export default HomeList