Skip to content

Commit

Permalink
notification
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaoyuanxun committed Dec 13, 2023
1 parent 7c94cf9 commit 20e1f2d
Showing 1 changed file with 54 additions and 3 deletions.
57 changes: 54 additions & 3 deletions frontend/src/components/post.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import {Avatar, message, Modal, Space, Typography} from "antd";
import {Avatar, message, Modal, Space, Typography, notification} from "antd";
import {
CommentOutlined,
RedoOutlined,
HeartOutlined
HeartOutlined,
LoadingOutlined,
CheckOutlined,
CloseOutlined
} from '@ant-design/icons';
import {PostImmutable} from "../declarations/feed/feed";
import {useAuth} from "../utils/useAuth";
Expand All @@ -17,6 +20,9 @@ export default function Post(props: { content: PostImmutable, setPostItem?: Func
const [open, setOpen] = useState(false)
const [data, setData] = useState<any>()
const {pathname} = useLocation()
const [open, setOpen] = useState(false)
const [data, setData] = useState<any>()
const [api, contextHolder] = notification.useNotification();

useEffect(() => {
setData(content)
Expand All @@ -26,7 +32,7 @@ export default function Post(props: { content: PostImmutable, setPostItem?: Func

const feedApi = React.useMemo(() => {
return new Feed(content.feedCanister)
}, [])
}, [content])

const tip = () => message.warning("please login first")

Expand All @@ -45,13 +51,57 @@ export default function Post(props: { content: PostImmutable, setPostItem?: Func

const repost = async () => {
if (!isAuth) return tip()
if (!feedApi) {
api.error({
message: 'Create Repost Error !',
key: 'createRepost',
description: 'Please Login !',
icon: <CloseOutlined />
});
return tip();
}
api.info({
message: 'Create Repost ing ...',
key: 'createRepost',
duration: null,
description: '',
icon: <LoadingOutlined />
});
await feedApi.createRepost(data.postId)
api.success({
message: 'Create Repost Successful !',
key: 'createRepost',
description: '',
icon: <CheckOutlined />
})
update().then()
}

const like = async () => {
if (!isAuth) return tip()
if (!feedApi) {
api.error({
message: 'Create Like Error !',
key: 'createLike',
description: 'Please Login !',
icon: <CloseOutlined />
});
return tip()
}
api.info({
message: 'Create Like ing ...',
key: 'createLike',
duration: null,
description: '',
icon: <LoadingOutlined />
});
await feedApi.createLike(data.postId)
api.success({
message: 'Create Like Successful !',
key: 'createLike',
description: '',
icon: <CheckOutlined />
})
update().then()
}

Expand All @@ -62,6 +112,7 @@ export default function Post(props: { content: PostImmutable, setPostItem?: Func
borderRadius: "20px",
marginBottom: "20px",
}}>
{contextHolder}
<div style={{
cursor: "pointer"
}} onClick={() => setPostItem?.(data)}>
Expand Down

0 comments on commit 20e1f2d

Please sign in to comment.