ChannelAlert.tsx 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. import { useIntl } from "react-intl";
  2. import { Alert, Button } from "antd";
  3. import ChannelPicker from "./ChannelPicker";
  4. import type { IChannel } from "./Channel"
  5. import store from "../../store";
  6. import { openPanel } from "../../reducers/right-panel";
  7. interface IWidget {
  8. channels?: string | null;
  9. onChannelChange?: Function;
  10. }
  11. const ChannelAlertWidget = ({ channels, onChannelChange }: IWidget) => {
  12. const intl = useIntl();
  13. // 获取浏览器宽度
  14. const browserWidth = window.innerWidth;
  15. let button = <></>;
  16. if (browserWidth < 580) {
  17. button = (
  18. <ChannelPicker
  19. trigger={
  20. <Button type="primary">
  21. {intl.formatMessage({
  22. id: "buttons.select.channel",
  23. })}
  24. </Button>
  25. }
  26. defaultOwner="my"
  27. onSelect={(channels: IChannel[]) => {
  28. if (typeof onChannelChange !== "undefined") {
  29. onChannelChange(channels);
  30. }
  31. }}
  32. />
  33. );
  34. } else {
  35. button = (
  36. <Button
  37. type="primary"
  38. onClick={() => {
  39. store.dispatch(openPanel("channel"));
  40. }}
  41. >
  42. {intl.formatMessage({
  43. id: "buttons.select.channel",
  44. })}
  45. </Button>
  46. );
  47. }
  48. return channels ? (
  49. <></>
  50. ) : (
  51. <Alert
  52. message={intl.formatMessage({
  53. id: "message.channel.empty.alert",
  54. })}
  55. type="warning"
  56. closable
  57. action={button}
  58. />
  59. );
  60. };
  61. export default ChannelAlertWidget;