Fix: mutate freeze object

This commit is contained in:
Dreamacro 2021-09-25 22:06:22 +08:00
parent 8404781106
commit c21d9937fa
2 changed files with 7 additions and 4 deletions

View File

@ -224,7 +224,7 @@ export default function Connections () {
const conn = data.find(c => c.id === drawerState.selectedID)?.original const conn = data.find(c => c.id === drawerState.selectedID)?.original
if (conn) { if (conn) {
setDrawerState(d => { setDrawerState(d => {
d.connection = conn d.connection = { ...conn }
if (drawerState.selectedID === latestConntion.current.id) { if (drawerState.selectedID === latestConntion.current.id) {
d.connection.completed = latestConntion.current.completed d.connection.completed = latestConntion.current.completed
} }

View File

@ -1,3 +1,4 @@
import produce from 'immer'
import { useState, useMemo, useRef, useCallback } from 'react' import { useState, useMemo, useRef, useCallback } from 'react'
import * as API from '@lib/request' import * as API from '@lib/request'
@ -39,9 +40,11 @@ class Store {
} else { } else {
const connection = this.connections.get(id) const connection = this.connections.get(id)
if (connection != null) { if (connection != null) {
connection.completed = true this.connections.set(id, produce(connection, draft => {
connection.uploadSpeed = 0 draft.completed = true
connection.downloadSpeed = 0 draft.uploadSpeed = 0
draft.downloadSpeed = 0
}))
} }
} }
} }