From 8b24085f8e614568712102d1a4844d2c0ab58dd6 Mon Sep 17 00:00:00 2001 From: Eugen Rochko Date: Wed, 22 Jan 2025 09:39:13 +0100 Subject: [PATCH] Refactor `` into TypeScript (#33680) --- .../account/components/domain_pill.jsx | 86 -------- .../account/components/domain_pill.tsx | 197 ++++++++++++++++++ 2 files changed, 197 insertions(+), 86 deletions(-) delete mode 100644 app/javascript/mastodon/features/account/components/domain_pill.jsx create mode 100644 app/javascript/mastodon/features/account/components/domain_pill.tsx diff --git a/app/javascript/mastodon/features/account/components/domain_pill.jsx b/app/javascript/mastodon/features/account/components/domain_pill.jsx deleted file mode 100644 index 0dadb947f9..0000000000 --- a/app/javascript/mastodon/features/account/components/domain_pill.jsx +++ /dev/null @@ -1,86 +0,0 @@ -import PropTypes from 'prop-types'; -import { useState, useRef, useCallback } from 'react'; - -import { FormattedMessage } from 'react-intl'; - -import classNames from 'classnames'; - -import Overlay from 'react-overlays/Overlay'; - - - -import AlternateEmailIcon from '@/material-icons/400-24px/alternate_email.svg?react'; -import BadgeIcon from '@/material-icons/400-24px/badge.svg?react'; -import GlobeIcon from '@/material-icons/400-24px/globe.svg?react'; -import { Icon } from 'mastodon/components/icon'; - -export const DomainPill = ({ domain, username, isSelf }) => { - const [open, setOpen] = useState(false); - const [expanded, setExpanded] = useState(false); - const triggerRef = useRef(null); - - const handleClick = useCallback(() => { - setOpen(!open); - }, [open, setOpen]); - - const handleExpandClick = useCallback(() => { - setExpanded(!expanded); - }, [expanded, setExpanded]); - - return ( - <> - - - - {({ props }) => ( -
-
-
-

-
- -
-
{isSelf ? : }
-
@{username}@{domain}
-
- -
-
-
- -
-
-

{isSelf ? : }

-
-
- -
-
- -
-
-

{isSelf ? : }

-
-
-
- -

{isSelf ? }} /> : }} />}

- - {expanded && ( - <> -

-

- - )} -
- )} -
- - ); -}; - -DomainPill.propTypes = { - username: PropTypes.string.isRequired, - domain: PropTypes.string.isRequired, - isSelf: PropTypes.bool, -}; diff --git a/app/javascript/mastodon/features/account/components/domain_pill.tsx b/app/javascript/mastodon/features/account/components/domain_pill.tsx new file mode 100644 index 0000000000..956afa19c3 --- /dev/null +++ b/app/javascript/mastodon/features/account/components/domain_pill.tsx @@ -0,0 +1,197 @@ +import { useState, useRef, useCallback } from 'react'; + +import { FormattedMessage } from 'react-intl'; + +import classNames from 'classnames'; + +import Overlay from 'react-overlays/Overlay'; + +import AlternateEmailIcon from '@/material-icons/400-24px/alternate_email.svg?react'; +import BadgeIcon from '@/material-icons/400-24px/badge.svg?react'; +import GlobeIcon from '@/material-icons/400-24px/globe.svg?react'; +import { Icon } from 'mastodon/components/icon'; + +export const DomainPill: React.FC<{ + domain: string; + username: string; + isSelf: boolean; +}> = ({ domain, username, isSelf }) => { + const [open, setOpen] = useState(false); + const [expanded, setExpanded] = useState(false); + const triggerRef = useRef(null); + + const handleClick = useCallback(() => { + setOpen(!open); + }, [open, setOpen]); + + const handleExpandClick = useCallback(() => { + setExpanded(!expanded); + }, [expanded, setExpanded]); + + return ( + <> + + + + {({ props }) => ( +
+
+
+ +
+

+ +

+
+ +
+
+ {isSelf ? ( + + ) : ( + + )} +
+
+ @{username}@{domain} +
+
+ +
+
+
+ +
+ +
+
+ +
+

+ {isSelf ? ( + + ) : ( + + )} +

+
+
+ +
+
+ +
+ +
+
+ +
+

+ {isSelf ? ( + + ) : ( + + )} +

+
+
+
+ +

+ {isSelf ? ( + ( + + ), + }} + /> + ) : ( + ( + + ), + }} + /> + )} +

+ + {expanded && ( + <> +

+ +

+

+ +

+ + )} +
+ )} +
+ + ); +};