Skip to content

Commit

Permalink
发推和评论
Browse files Browse the repository at this point in the history
  • Loading branch information
Shuaige1234567 committed Dec 12, 2023
1 parent ca70044 commit 47b495b
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 28 deletions.
8 changes: 4 additions & 4 deletions frontend/src/components/Modal/EditModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ const tailFormItemLayout = {
};


export function EditModal(props: { onFinish: (values: any) => void, form: FormInstance<any> | undefined }) {
const {onFinish, form} = props
export function EditModal(props: { isComment: boolean, onFinish: (values: any) => void, form: FormInstance<any> | undefined }) {
const {onFinish, form, isComment} = props

return (
<Form
Expand All @@ -48,12 +48,12 @@ export function EditModal(props: { onFinish: (values: any) => void, form: FormIn
style={{maxWidth: 600}}
scrollToFirstError
>
<Form.Item
{!isComment ? <Form.Item
name="title"
label="Title"
>
<Input/>
</Form.Item>
</Form.Item> : <></>}

<Form.Item
name="content"
Expand Down
6 changes: 3 additions & 3 deletions frontend/src/components/Modal/commentForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,20 @@ import {useAuth} from "../../utils/useAuth";
import Feed from "../../actors/feed";
import {EditModal} from "./EditModal";

export function CommentForm(props: { setOpen: Function }) {
export function CommentForm(props: {postId:string, setOpen: Function }) {
const {userFeedCai} = useAuth()
const [form] = Form.useForm();

const onFinish = async (values: { title: string, content: string }) => {
if (!userFeedCai) return
const feedApi = new Feed(userFeedCai)
await feedApi.createComment(values.title, values.content)
await feedApi.createComment(props.postId, values.content)
await feedApi.getAllPost()
form.resetFields()
props.setOpen(false)
};

return (
<EditModal form={form} onFinish={onFinish}/>
<EditModal isComment={true} form={form} onFinish={onFinish}/>
);
};
2 changes: 1 addition & 1 deletion frontend/src/components/Modal/postForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@ export function PostForm(props: { setOpen: Function }) {
};

return (
<EditModal form={form} onFinish={onFinish}/>
<EditModal isComment={false} form={form} onFinish={onFinish}/>
);
};
1 change: 1 addition & 0 deletions frontend/src/components/comment.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export function Comments(props: { content: Comment }) {
<Flex
vertical
className={"content"}
style={{padding: "0 20px"}}
>
<Space>
<Avatar
Expand Down
39 changes: 21 additions & 18 deletions frontend/src/components/post.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,23 +44,26 @@ export default function Post(props: { content: PostImmutable, setPostItem?: Func
border: "1px solid rgba(0,0,0,0.2)",
borderRadius: "20px",
marginBottom: "20px",
cursor: "pointer"
}} onClick={() => setPostItem?.(content)}>
<Space>
<Avatar
size={32}
src="https://avatars.githubusercontent.com/u/120618331?s=200&v=4"
style={{
border: '1px solid #D3D540',
}}
/>
<p>NeutronStarDAO</p>
</Space>
<Typography.Paragraph style={{
paddingLeft: '12px'
}}>
{content.content}
</Typography.Paragraph>
}}>
<div style={{
cursor: "pointer"
}} onClick={() => setPostItem?.(content)}>
<Space>
<Avatar
size={32}
src="https://avatars.githubusercontent.com/u/120618331?s=200&v=4"
style={{
border: '1px solid #D3D540',
}}
/>
<p>NeutronStarDAO</p>
</Space>
<Typography.Paragraph style={{
paddingLeft: '12px'
}}>
{content.content}
</Typography.Paragraph>
</div>
<Space
size={140}
style={{
Expand All @@ -73,7 +76,7 @@ export default function Post(props: { content: PostImmutable, setPostItem?: Func
footer={null}
onCancel={() => setOpen(false)}
>
<CommentForm setOpen={setOpen}/>
<CommentForm postId={content.postId} setOpen={setOpen}/>
</Modal>
<div style={{cursor: "pointer"}} onClick={() => setOpen(true)}>
<CommentOutlined/> &nbsp;
Expand Down
13 changes: 11 additions & 2 deletions frontend/src/routes/profile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,16 @@ import {Profile} from '../declarations/user/user';
import {useAuth} from "../utils/useAuth";
import {useAllDataStore} from "../redux";
import ProfileForm from "../components/Modal/form";
import {Comments} from "../components/comment";
import {PostImmutable} from "../declarations/feed/feed";

type NotificationType = 'success' | 'info' | 'warning' | 'error';

export default function UserProfile() {
const {principal} = useAuth()
const [isModalOpen, setIsModalOpen] = useState(false);
const [userProfile, setUserProfile] = useState<Profile | undefined>();
const [postItem, setPostItem] = useState<PostImmutable>()
const [following, setFollowing] = useState(0)
const [followers, setFollowers] = useState(0)
const {allPost} = useAllDataStore()
Expand Down Expand Up @@ -113,13 +116,19 @@ export default function UserProfile() {
</Space>
</div>
{allPost && allPost.map((v, k) => {
return <Post content={v} key={k}/>
return <Post setPostItem={setPostItem} content={v} key={k}/>
})}
</Layout.Content>

<Layout.Content style={{
<Layout.Content className={"posts"} style={{
backgroundColor: 'white',
overflowY: 'auto',
scrollbarWidth: 'thin',
padding: "40px 20px"
}}>
{postItem && postItem.comment.map((v, k) => {
return <Comments content={v} key={k}/>
})}
</Layout.Content>
</>
)
Expand Down

0 comments on commit 47b495b

Please sign in to comment.