simplify code
This commit is contained in:
parent
f0599d5a88
commit
6430576761
|
|
@ -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!
|
||||
|
|
|
|||
|
|
@ -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}`}>
|
||||
|
|
|
|||
|
|
@ -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 />
|
||||
|
|
|
|||
|
|
@ -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 (
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user