simplify code

This commit is contained in:
Pig Fang 2020-02-02 15:48:14 +08:00
parent f0599d5a88
commit 6430576761
4 changed files with 26 additions and 33 deletions

View File

@ -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> = 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> = props => {
return trans('general.cape')
}
return ''
}, [props.skin, props.cape])
})()
useEffect(() => {
const container = containerRef.current!

View File

@ -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> = props => {
const { plugin } = props
const handleChange = useCallback(
(event: React.ChangeEvent<HTMLInputElement>) => {
event.preventDefault()
const handleChange = (event: React.ChangeEvent<HTMLInputElement>) => {
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 (
<div className={`info-box mr-3 ${styles.box}`}>

View File

@ -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 ? (
<Loading />

View File

@ -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> = 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 (