import React from "react"; import classnames from "classnames"; import PropTypes from "prop-types"; import { Divider, Popconfirm } from "antd"; import IconFont from "./ScheduleIconFont"; import { CollapseBtn } from "./CollapseBtn"; import { getActionAuth, AuthType } from "../utils"; import styles from "./ItemToolBar.less"; import { LoadingOutlined } from "@ant-design/icons"; export enum TOOL_ACTION_TYPE { REPLY = "reply", FAVOR = "favor", EDIT = "edit", DELETE = "delete", } interface ItemToolBarProps { replyCount: number; authType: AuthType; handleReplyClick(): boolean; handlePrivateClick(actionType: string): Promise | boolean; handleNormalClick(actionType: string): Promise | boolean; favorCount: number; favored: boolean; } interface ItemToolBarState { favorAjaxLoading: boolean; } class ItemToolBar extends React.Component { constructor(props: ItemToolBarProps) { super(props); this.state = { favorAjaxLoading: false, }; } renderPrivateTool = () => { const { authType, replyCount, handleReplyClick, handlePrivateClick, } = this.props; const showReplyCollapse = replyCount > 0; const showEdit = getActionAuth(authType, TOOL_ACTION_TYPE.EDIT); const showDelete = getActionAuth(authType, TOOL_ACTION_TYPE.DELETE); const notShowPrivate = [showReplyCollapse, showEdit, showDelete].reduce( (a, b) => Number(a) + Number(b), 0 ) === 0; console.log("notShowPrivate: ", notShowPrivate); if (notShowPrivate) return null; return ( <> {showReplyCollapse && ( )} {showEdit && ( { handlePrivateClick("edit"); }} > )} {showDelete && ( { handlePrivateClick("delete"); }} > )} ); }; renderNormalTool = () => { const { favorAjaxLoading } = this.state; const { favorCount, favored, handleNormalClick } = this.props; return ( <> { e.preventDefault(); if (!favorAjaxLoading) { this.setState({ favorAjaxLoading: true }); await handleNormalClick(TOOL_ACTION_TYPE.FAVOR); this.setState({ favorAjaxLoading: false }); } }} > {favorAjaxLoading ? ( ) : ( )} {favorCount} { e.preventDefault(); handleNormalClick(TOOL_ACTION_TYPE.REPLY); }} > 回复 ); }; render() { return (
{this.renderPrivateTool()} {this.renderNormalTool()}
); } } export default ItemToolBar;