From 3b52e4c386156568eadb863479695090f6f6ec94 Mon Sep 17 00:00:00 2001 From: wonderlandpark Date: Tue, 18 May 2021 11:16:48 +0900 Subject: [PATCH] types: improved component typing --- components/Advertisement.tsx | 2 +- components/Application.tsx | 17 ++- components/BotCard.tsx | 179 ++++++++++++++++---------------- components/Button.tsx | 37 +++---- components/Captcha.tsx | 2 +- components/ColorCard.tsx | 2 +- components/Container.tsx | 4 +- components/DeveloperLayout.tsx | 2 +- components/DiscordAvatar.tsx | 18 ++-- components/Divider.tsx | 6 +- components/Docs.tsx | 7 +- components/Footer.tsx | 2 +- components/Forbidden.tsx | 2 +- components/Form/CheckBox.tsx | 2 +- components/Form/CsrfToken.tsx | 2 +- components/Form/Input.tsx | 16 +-- components/Form/Label.tsx | 48 ++++----- components/Form/Select.tsx | 52 +++++----- components/Form/Selects.tsx | 2 +- components/Form/TextArea.tsx | 2 +- components/Hero.tsx | 2 +- components/Loader.tsx | 4 +- components/Login.tsx | 5 +- components/LongButton.tsx | 2 +- components/Markdown.tsx | 2 +- components/Message.tsx | 2 +- components/Modal.tsx | 2 +- components/NSFW.tsx | 2 +- components/Navbar.tsx | 12 ++- components/Notice.tsx | 2 +- components/Owner.tsx | 2 +- components/Paginator.tsx | 2 +- components/PlatformDisplay.tsx | 2 +- components/Redirect.tsx | 2 +- components/ResponsiveGrid.tsx | 4 +- components/SEO.tsx | 2 +- components/Search.tsx | 2 +- components/Segment.tsx | 2 +- components/SubmittedBotCard.tsx | 2 +- components/Tag.tsx | 4 +- components/Toggle.tsx | 2 +- components/Tooltip.tsx | 4 +- components/Wave.tsx | 2 +- 43 files changed, 236 insertions(+), 235 deletions(-) diff --git a/components/Advertisement.tsx b/components/Advertisement.tsx index 279c6f6..d770ecb 100644 --- a/components/Advertisement.tsx +++ b/components/Advertisement.tsx @@ -1,7 +1,7 @@ import { useEffect } from 'react' import Logger from '@utils/Logger' -const Advertisement = ({ size = 'short' }: AdvertisementProps): JSX.Element => { +const Advertisement: React.FC = ({ size = 'short' }) => { useEffect(() => { if (process.env.NODE_ENV === 'production') { window.adsbygoogle = window.adsbygoogle || [] diff --git a/components/Application.tsx b/components/Application.tsx index 60b17c8..9409bae 100644 --- a/components/Application.tsx +++ b/components/Application.tsx @@ -3,15 +3,14 @@ import Link from 'next/link' const DiscordAvatar = dynamic(() => import('@components/DiscordAvatar')) -const Application = ({ type, id, name }: ApplicationProps): JSX.Element => { - return ( - -
- -

{name}

-
- - ) +const Application: React.FC = ({ type, id, name }) => { + return +
+ +

{name}

+
+ + } interface ApplicationProps { diff --git a/components/BotCard.tsx b/components/BotCard.tsx index 4e00a2c..fd90048 100644 --- a/components/BotCard.tsx +++ b/components/BotCard.tsx @@ -9,115 +9,114 @@ const Divider = dynamic(() => import('@components/Divider')) const Tag = dynamic(() => import('@components/Tag')) const DiscordAvatar = dynamic(() => import('@components/DiscordAvatar')) -const BotCard = ({ manage = false, bot }: BotProps): JSX.Element => { - return ( -
-
-
-
-
- -
-
-
-
- -
- -
-

- - {Status[bot.status]?.text} -

-

{bot.name}

-
+const BotCard: React.FC = ({ manage = false, bot }) => { + return
+
+
+
+
+ +
+
+
+
+
-
- - {formatNumber(bot.votes)} - - } - dark - /> - {formatNumber(bot.servers)} 서버 : 'N/A'} - dark - /> + +
+

+ + {Status[bot.status]?.text} +

+

{bot.name}

-

- {bot.intro} -

-
-
- {bot.category.slice(0, 3).map(el => ( - - ))}{' '} - {bot.category.length > 3 && } -
+
+ + {formatNumber(bot.votes)} + + } + dark + /> + {formatNumber(bot.servers)} 서버 : 'N/A'} + dark + />
- - -
- ) +
+ } -interface BotProps { +interface BotCardProps { manage?: boolean bot: Bot } diff --git a/components/Button.tsx b/components/Button.tsx index 057efc9..7a588d9 100644 --- a/components/Button.tsx +++ b/components/Button.tsx @@ -1,25 +1,23 @@ import Link from 'next/link' import { ReactNode } from 'react' -const Button = ({ +const Button: React.FC = ({ type = 'button', className, children, href, disabled=false, onClick, -}: ButtonProps): JSX.Element => { - return href ? ( - - { + return href ? + - {children} - - - ) : onClick ? ( - - ) : ( - - ) + > + {children} + } interface ButtonProps { diff --git a/components/Captcha.tsx b/components/Captcha.tsx index 65288d2..b04755c 100644 --- a/components/Captcha.tsx +++ b/components/Captcha.tsx @@ -2,7 +2,7 @@ import { Ref } from 'react' import HCaptcha from '@hcaptcha/react-hcaptcha' -const Captcha = ({ dark, onVerify }:CaptchaProps):JSX.Element => { +const Captcha: React.FC = ({ dark, onVerify }) => { return } diff --git a/components/ColorCard.tsx b/components/ColorCard.tsx index 74cd15f..66f6c32 100644 --- a/components/ColorCard.tsx +++ b/components/ColorCard.tsx @@ -1,4 +1,4 @@ -const ColorCard = ({ header, first, second, className }: ColorCardProps): JSX.Element => { +const ColorCard: React.FC = ({ header, first, second, className }) => { return (

{header}

diff --git a/components/Container.tsx b/components/Container.tsx index 62c9f89..414be2f 100644 --- a/components/Container.tsx +++ b/components/Container.tsx @@ -1,11 +1,11 @@ import { ReactNode } from 'react' -const Container = ({ +const Container: React.FC = ({ ignoreColor, className, paddingTop = false, children, -}: ContainerProps): JSX.Element => { +}) => { return (
import('@components/Container')) const Divider = dynamic(() => import('@components/Divider')) const SEO = dynamic(() => import('@components/SEO')) -const DeveloperLayout = ({ children, enabled, docs, currentDoc }:DeveloperLayout):JSX.Element => { +const DeveloperLayout: React.FC = ({ children, enabled, docs, currentDoc }:DeveloperLayout) => { const [ navbarEnabled, setNavbarOpen ] = useState(false) return
diff --git a/components/DiscordAvatar.tsx b/components/DiscordAvatar.tsx index b175a71..d248950 100644 --- a/components/DiscordAvatar.tsx +++ b/components/DiscordAvatar.tsx @@ -3,12 +3,7 @@ import { KoreanbotsEndPoints } from '@utils/Constants' import { supportsWebP } from '@utils/Tools' import Logger from '@utils/Logger' -const DiscordAvatar = (props: { - alt?: string - userID: string - className?: string - size? : 128 | 256 | 512 -}) => { +const DiscordAvatar: React.FC = props => { const fallback = '/img/default.png' const [ webpUnavailable, setWebpUnavailable ] = useState() @@ -46,7 +41,12 @@ const DiscordAvatar = (props: { /> } -export default DiscordAvatar +interface DiscordAvatarProps { + alt?: string + userID: string + className?: string + size? : 128 | 256 | 512 +} interface ImageEvent extends Event { target: ImageTarget @@ -55,4 +55,6 @@ interface ImageEvent extends Event { interface ImageTarget extends EventTarget { src: string onerror: (event: SyntheticEvent) => void -} \ No newline at end of file +} + +export default DiscordAvatar diff --git a/components/Divider.tsx b/components/Divider.tsx index 9ffcc3c..1d116aa 100644 --- a/components/Divider.tsx +++ b/components/Divider.tsx @@ -1,4 +1,4 @@ -const Divider = ({ className }: { className?: string }) => { +const Divider: React.FC = ({ className }) => { return (
{ ) } +interface DividerProps { + className?: string +} + export default Divider diff --git a/components/Docs.tsx b/components/Docs.tsx index c28ac02..24acf54 100644 --- a/components/Docs.tsx +++ b/components/Docs.tsx @@ -2,7 +2,8 @@ import dynamic from 'next/dynamic' const Container = dynamic(() => import('@components/Container')) const SEO = dynamic(() => import('@components/SEO')) -const Docs = ({ title, header, description, subheader, children }: DocsProps): JSX.Element => { + +const Docs: React.FC = ({ title, header, description, subheader, children }) => { return ( <> import('@components/Container')) const Toggle = dynamic(() => import('@components/Toggle')) -const Footer = ({ theme, setTheme }: FooterProps): JSX.Element => { +const Footer: React.FC = ({ theme, setTheme }) => { return (
diff --git a/components/Forbidden.tsx b/components/Forbidden.tsx index d81badb..e9cefb2 100644 --- a/components/Forbidden.tsx +++ b/components/Forbidden.tsx @@ -6,7 +6,7 @@ import { ErrorText } from '@utils/Constants' const SEO = dynamic(() => import('@components/SEO')) const Button = dynamic(() => import('@components/Button')) -const Forbidden = ():JSX.Element => { +const Forbidden:React.FC = () => { const router = useRouter() return <> diff --git a/components/Form/CheckBox.tsx b/components/Form/CheckBox.tsx index 1f3a91f..f72350b 100644 --- a/components/Form/CheckBox.tsx +++ b/components/Form/CheckBox.tsx @@ -1,6 +1,6 @@ import { Field } from 'formik' -const CheckBox = ({ name, ...props }: CheckBoxProps): JSX.Element => { +const CheckBox: React.FC = ({ name, ...props }) => { return } diff --git a/components/Form/CsrfToken.tsx b/components/Form/CsrfToken.tsx index def88da..be1c609 100644 --- a/components/Form/CsrfToken.tsx +++ b/components/Form/CsrfToken.tsx @@ -1,6 +1,6 @@ import { Field } from 'formik' -const CsrfToken = ({ token }: CsrfTokenProps): JSX.Element => { +const CsrfToken: React.FC = ({ token }) => { return