From 643057676186d32d912ac80fbd804ecb57868103 Mon Sep 17 00:00:00 2001 From: Pig Fang Date: Sun, 2 Feb 2020 15:48:14 +0800 Subject: [PATCH] simplify code --- resources/assets/src/components/Viewer.tsx | 6 ++--- .../views/admin/PluginsManagement/InfoBox.tsx | 25 ++++++++----------- .../views/admin/PluginsManagement/index.tsx | 14 +++++------ .../src/views/user/Dashboard/SignButton.tsx | 14 +++++------ 4 files changed, 26 insertions(+), 33 deletions(-) diff --git a/resources/assets/src/components/Viewer.tsx b/resources/assets/src/components/Viewer.tsx index 74b68d85..cd5febc3 100644 --- a/resources/assets/src/components/Viewer.tsx +++ b/resources/assets/src/components/Viewer.tsx @@ -1,4 +1,4 @@ -import React, { useState, useEffect, useMemo, useRef } from 'react' +import React, { useState, useEffect, useRef } from 'react' import * as skinview3d from 'skinview3d' import { trans } from '../scripts/i18n' import styles from './Viewer.scss' @@ -39,7 +39,7 @@ const Viewer: React.FC = props => { const [paused, setPaused] = useState(false) const [reset, setReset] = useState(0) - const indicator = useMemo(() => { + const indicator = (() => { const { skin, cape } = props if (skin && cape) { return `${trans('general.skin')} & ${trans('general.cape')}` @@ -49,7 +49,7 @@ const Viewer: React.FC = props => { return trans('general.cape') } return '' - }, [props.skin, props.cape]) + })() useEffect(() => { const container = containerRef.current! diff --git a/resources/assets/src/views/admin/PluginsManagement/InfoBox.tsx b/resources/assets/src/views/admin/PluginsManagement/InfoBox.tsx index 54afeaf9..831554a3 100644 --- a/resources/assets/src/views/admin/PluginsManagement/InfoBox.tsx +++ b/resources/assets/src/views/admin/PluginsManagement/InfoBox.tsx @@ -1,4 +1,4 @@ -import React, { useCallback } from 'react' +import React from 'react' import { trans } from '../../../scripts/i18n' import { Plugin } from './types' import styles from './InfoBox.scss' @@ -14,22 +14,17 @@ interface Props { const InfoBox: React.FC = props => { const { plugin } = props - const handleChange = useCallback( - (event: React.ChangeEvent) => { - event.preventDefault() + const handleChange = (event: React.ChangeEvent) => { + event.preventDefault() - if (event.target.checked) { - props.onEnable(plugin) - } else { - props.onDisable(plugin) - } - }, - [plugin], - ) + if (event.target.checked) { + props.onEnable(plugin) + } else { + props.onDisable(plugin) + } + } - const handleDelete = useCallback(() => { - props.onDelete(plugin) - }, [plugin]) + const handleDelete = () => props.onDelete(plugin) return (
diff --git a/resources/assets/src/views/admin/PluginsManagement/index.tsx b/resources/assets/src/views/admin/PluginsManagement/index.tsx index f09b1911..404026b1 100644 --- a/resources/assets/src/views/admin/PluginsManagement/index.tsx +++ b/resources/assets/src/views/admin/PluginsManagement/index.tsx @@ -1,4 +1,4 @@ -import React, { useState, useEffect, useCallback } from 'react' +import React, { useState, useEffect } from 'react' import { hot } from 'react-hot-loader/root' import { trans } from '../../../scripts/i18n' import * as fetch from '../../../scripts/net' @@ -20,7 +20,7 @@ const PluginsManagement: React.FC = () => { getPlugins() }, []) - const handleEnable = useCallback(async (plugin: Plugin, i: number) => { + const handleEnable = async (plugin: Plugin, i: number) => { const { code, message, @@ -40,9 +40,9 @@ const PluginsManagement: React.FC = () => { } else { alertUnresolved(message, reason) } - }, []) + } - const handleDisable = useCallback(async (plugin: Plugin, i: number) => { + const handleDisable = async (plugin: Plugin, i: number) => { const { code, message } = await fetch.post('/admin/plugins/manage', { action: 'disable', name: plugin.name, @@ -56,9 +56,9 @@ const PluginsManagement: React.FC = () => { } else { toast.error(message) } - }, []) + } - const handleDelete = useCallback(async (plugin: Plugin) => { + const handleDelete = async (plugin: Plugin) => { try { await showModal({ title: plugin.title, @@ -80,7 +80,7 @@ const PluginsManagement: React.FC = () => { } else { toast.error(message) } - }, []) + } return loading ? ( diff --git a/resources/assets/src/views/user/Dashboard/SignButton.tsx b/resources/assets/src/views/user/Dashboard/SignButton.tsx index 43e61b4e..f8c6df4f 100644 --- a/resources/assets/src/views/user/Dashboard/SignButton.tsx +++ b/resources/assets/src/views/user/Dashboard/SignButton.tsx @@ -1,4 +1,4 @@ -import React, { useMemo } from 'react' +import React from 'react' import { trans } from '../../../scripts/i18n' import * as scoreUtils from './scoreUtils' @@ -12,14 +12,12 @@ interface Props { const SignButton: React.FC = props => { const { lastSign, signGap, canSignAfterZero } = props - const remainingTime = useMemo( - () => scoreUtils.remainingTime(lastSign, signGap, canSignAfterZero), - [lastSign, signGap, canSignAfterZero], - ) - const remainingTimeText = useMemo( - () => scoreUtils.remainingTimeText(remainingTime), - [remainingTime], + const remainingTime = scoreUtils.remainingTime( + lastSign, + signGap, + canSignAfterZero, ) + const remainingTimeText = scoreUtils.remainingTimeText(remainingTime) const canSign = remainingTime <= 0 return (