~cytrogen/masto-fe

ref: f8dc013b0d81d5d463c086e291ce99ab1d796a9d masto-fe/app/javascript/mastodon/components/dismissable_banner.tsx -rw-r--r-- 1.1 KiB
f8dc013b — Cytrogen [feature] Add language selector to local settings 4 days ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import  { type PropsWithChildren } from "react";
import { useCallback, useState } from "react";

import { defineMessages, useIntl } from "react-intl";

import { bannerSettings } from "mastodon/settings";

import { IconButton } from "./icon_button";

const messages = defineMessages({
  dismiss: { id: "dismissable_banner.dismiss", defaultMessage: "Dismiss" },
});

interface Props {
  id: string,
}

export const DismissableBanner: React.FC<PropsWithChildren<Props>> = ({
  id,
  children,
}) => {
  const [visible, setVisible] = useState(!bannerSettings.get(id));
  const intl = useIntl();

  const handleDismiss = useCallback(() => {
    setVisible(false);
    bannerSettings.set(id, true);
  }, [id]);

  if (!visible) {
    return null;
  }

  return (
    <div className='dismissable-banner'>
      <div className='dismissable-banner__action'>
        <IconButton
          icon='times'
          title={intl.formatMessage(messages.dismiss)}
          onClick={handleDismiss}
        />
      </div>

      <div className='dismissable-banner__message'>{children}</div>
    </div>
  );
};