SuggestionButton.tsx 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. import { Space, Tooltip } from "antd";
  2. import type { ISentence } from "../SentEdit"
  3. import { HandOutlinedIcon } from "../../../assets/icon";
  4. import SuggestionPopover from "./SuggestionPopover";
  5. import store from "../../../store";
  6. import { openPanel } from "../../../reducers/right-panel";
  7. import { show } from "../../../reducers/discussion";
  8. export const prOpen = (data: ISentence) => {
  9. store.dispatch(
  10. show({
  11. type: "pr",
  12. sent: data,
  13. })
  14. );
  15. store.dispatch(openPanel("suggestion"));
  16. };
  17. interface IWidget {
  18. data: ISentence;
  19. hideCount?: boolean;
  20. hideInZero?: boolean;
  21. }
  22. const SuggestionButton = ({
  23. data,
  24. hideCount = false,
  25. hideInZero = false,
  26. }: IWidget) => {
  27. const prNumber = data.suggestionCount?.suggestion;
  28. return hideInZero && prNumber === 0 ? (
  29. <></>
  30. ) : (
  31. <Space
  32. style={{
  33. cursor: "pointer",
  34. color: prNumber && prNumber > 0 ? "#1890ff" : "unset",
  35. }}
  36. onClick={(_event) => {
  37. prOpen(data);
  38. }}
  39. >
  40. <Tooltip title="修改建议">
  41. <HandOutlinedIcon />
  42. </Tooltip>
  43. <SuggestionPopover
  44. book={data.book}
  45. para={data.para}
  46. start={data.wordStart}
  47. end={data.wordEnd}
  48. channelId={data.channel.id}
  49. />
  50. {hideCount ? <></> : prNumber}
  51. </Space>
  52. );
  53. };
  54. export default SuggestionButton;