1
0
Fork 0
mirror of https://github.com/morpheus65535/bazarr synced 2024-12-28 02:27:28 +00:00

Fix items are not updated when using mass editor

This commit is contained in:
LASER-Yi 2021-09-01 11:30:28 +08:00
parent ccd5473598
commit 60e2732f48
2 changed files with 7 additions and 13 deletions

View file

@ -6,7 +6,6 @@ import React, {
MouseEvent, MouseEvent,
PropsWithChildren, PropsWithChildren,
useCallback, useCallback,
useRef,
useState, useState,
} from "react"; } from "react";
import { Button } from "react-bootstrap"; import { Button } from "react-bootstrap";
@ -59,16 +58,13 @@ export function ContentHeaderAsyncButton<T extends () => Promise<any>>(
const [updating, setUpdate] = useState(false); const [updating, setUpdate] = useState(false);
const promiseRef = useRef(promise);
const successRef = useRef(onSuccess);
const click = useCallback(() => { const click = useCallback(() => {
setUpdate(true); setUpdate(true);
promiseRef.current().then((val) => { promise().then((val) => {
setUpdate(false); setUpdate(false);
successRef.current && successRef.current(val); onSuccess && onSuccess(val);
}); });
}, [successRef, promiseRef]); }, [onSuccess, promise]);
return ( return (
<ContentHeaderButton <ContentHeaderButton

View file

@ -26,17 +26,15 @@ export const Chips: FunctionComponent<ChipsProps> = ({
const input = useRef<HTMLInputElement>(null); const input = useRef<HTMLInputElement>(null);
const changeRef = useRef(onChange);
const addChip = useCallback( const addChip = useCallback(
(value: string) => { (value: string) => {
setChips((cp) => { setChips((cp) => {
const newChips = [...cp, value]; const newChips = [...cp, value];
changeRef.current && changeRef.current(newChips); onChange && onChange(newChips);
return newChips; return newChips;
}); });
}, },
[changeRef] [onChange]
); );
const removeChip = useCallback( const removeChip = useCallback(
@ -46,14 +44,14 @@ export const Chips: FunctionComponent<ChipsProps> = ({
if (index !== -1) { if (index !== -1) {
const newChips = [...cp]; const newChips = [...cp];
newChips.splice(index, 1); newChips.splice(index, 1);
changeRef.current && changeRef.current(newChips); onChange && onChange(newChips);
return newChips; return newChips;
} else { } else {
return cp; return cp;
} }
}); });
}, },
[changeRef] [onChange]
); );
const clearInput = useCallback(() => { const clearInput = useCallback(() => {