Skip to content

Commit

Permalink
空状态放进content组件
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaoyuanxun committed Dec 13, 2023
1 parent f4304c7 commit 3746888
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 102 deletions.
100 changes: 66 additions & 34 deletions frontend/src/routes/content.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React, {useEffect, useState} from "react";
import {Layout, Spin, Flex} from "antd";
import {Layout, Spin, Flex, Result } from "antd";
import { SmileOutlined } from '@ant-design/icons';
import Post from "../components/post";
import {Comments} from "../components/comment";
import {PostImmutable} from "../declarations/feed/feed";
Expand Down Expand Up @@ -39,38 +40,69 @@ export const Content = React.memo((props: { contents?: PostImmutable[] }) => {
getAllCommentProfiles()
}, [postItem])

return <>
<Layout.Content className={"posts"} style={{
backgroundColor: "white",
overflowY: 'auto',
scrollbarWidth: 'thin',
width: '200px',
borderRight: '1px solid rgba(0,0,0,0.2)',
padding: "40px 20px"
}}>
{onLoading && <Flex align="center" justify="center">
<Spin size="large"/>
</Flex>}
{!onLoading && contents && contents.map((v, k) => {
return <Post setPostItem={setPostItem} content={v} key={k}
avatar={userProfileArray?.[k] ? userProfileArray[k].avatarUrl : ""}
name={userProfileArray?.[k] ? userProfileArray[k].name : ""}/>
})}
</Layout.Content>
<Layout.Content className={"posts"} style={{
backgroundColor: 'white',
overflowY: 'auto',
scrollbarWidth: 'thin',
padding: "40px 20px"
}}>
{postItem ? !commentLoading ? postItem.comment.map((v, k) => {
return <Comments avatar={commentProfiles?.[k] ? commentProfiles [k]?.avatarUrl : ""}
name={commentProfiles?.[k] ? commentProfiles [k]?.name : ""}
content={v} key={k}/>
}) : <Flex align="center" justify="center">
<Spin size="large"/>
</Flex> : <></>}
</Layout.Content>
</>
if(contents !== undefined && contents?.length > 0) {
return <>
<Layout.Content className={"posts"} style={{
backgroundColor: "white",
overflowY: 'auto',
scrollbarWidth: 'thin',
width: '200px',
borderRight: '1px solid rgba(0,0,0,0.2)',
padding: "40px 20px"
}}>
{onLoading && <Flex align="center" justify="center">
<Spin size="large"/>
</Flex>}
{!onLoading && contents && contents.map((v, k) => {
return <Post setPostItem={setPostItem} content={v} key={k}
avatar={userProfileArray?.[k] ? userProfileArray[k].avatarUrl : ""}
name={userProfileArray?.[k] ? userProfileArray[k].name : ""}/>
})}
</Layout.Content>
<Layout.Content className={"posts"} style={{
backgroundColor: 'white',
overflowY: 'auto',
scrollbarWidth: 'thin',
padding: "40px 20px"
}}>
{postItem ? !commentLoading ? postItem.comment.map((v, k) => {
return <Comments avatar={commentProfiles?.[k] ? commentProfiles [k]?.avatarUrl : ""}
name={commentProfiles?.[k] ? commentProfiles [k]?.name : ""}
content={v} key={k}/>
}) : <Flex align="center" justify="center">
<Spin size="large"/>
</Flex> : <></>}
</Layout.Content>
</>
} else {
return (
<>
<Layout.Content className={"posts"} style={{
backgroundColor: "white",
overflowY: 'auto',
scrollbarWidth: 'thin',
width: '200px',
borderRight: '1px solid rgba(0,0,0,0.2)',
padding: "40px 20px",
}}>
<Result
icon={<SmileOutlined />}
title="There Is No Feed !"
subTitle="Please Follow SomeOne To Get Feed Or Refresh The Website"
style={{
backgroundColor: 'white'
}}
/>
</Layout.Content>
<Layout.Content className={"posts"} style={{
backgroundColor: 'white',
overflowY: 'auto',
scrollbarWidth: 'thin',
padding: "40px 20px"
}}>

</Layout.Content>
</>
)
}
})
32 changes: 1 addition & 31 deletions frontend/src/routes/explore.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,35 +20,5 @@ export default function Explore() {
fetch()
}, [])

if(contents.length > 0) {
return <Content contents={contents}/>
} else {
return (
<>
<Layout.Content className={"posts"} style={{
backgroundColor: "white",
overflowY: 'auto',
scrollbarWidth: 'thin',
width: '200px',
borderRight: '1px solid rgba(0,0,0,0.2)',
padding: "40px 20px",
}}>
<Result
icon={<SmileOutlined />}
title="There Is No Feed !"
subTitle="Please Refresh The Website"
style={{
backgroundColor: 'white'
}}
/>
</Layout.Content>
<Layout.Content className={"posts"} style={{
backgroundColor: 'white',
overflowY: 'auto',
scrollbarWidth: 'thin',
padding: "40px 20px"
}}>
</Layout.Content>
</>)
}
return <Content contents={contents}/>
}
39 changes: 2 additions & 37 deletions frontend/src/routes/home.tsx
Original file line number Diff line number Diff line change
@@ -1,45 +1,10 @@
import React from "react";
import {Content} from "./content";
import {useAllDataStore} from "../redux";
import { useAuth } from "../utils/useAuth";
import { SmileOutlined } from '@ant-design/icons';
import { Layout, Result } from 'antd';


export const Home = React.memo(() => {
const {allFeed} = useAllDataStore()

if(allFeed?.length === 0 || allFeed === undefined) {
return (
<>
<Layout.Content className={"posts"} style={{
backgroundColor: "white",
overflowY: 'auto',
scrollbarWidth: 'thin',
width: '200px',
borderRight: '1px solid rgba(0,0,0,0.2)',
padding: "40px 20px",
}}>
<Result
icon={<SmileOutlined />}
title="There Is No Feed !"
subTitle="Please Follow SomeOne To Get Feed"
style={{
backgroundColor: 'white'
}}
/>
</Layout.Content>
<Layout.Content className={"posts"} style={{
backgroundColor: 'white',
overflowY: 'auto',
scrollbarWidth: 'thin',
padding: "40px 20px"
}}>

</Layout.Content>
</>
)

} else {
return <Content contents={allFeed}/>
};
return <Content contents={allFeed}/>
})

0 comments on commit 3746888

Please sign in to comment.