chore: fix set state

This commit is contained in:
Steven 2024-03-05 22:26:52 +08:00
parent 87d626cd1d
commit 29043f63b6
2 changed files with 14 additions and 14 deletions

View File

@ -51,6 +51,13 @@ const CreateCollectionDrawer: React.FC<Props> = (props: Props) => {
}) })
.filter((shortcut) => !selectedShortcuts.find((selectedShortcut) => selectedShortcut.id === shortcut.id)); .filter((shortcut) => !selectedShortcuts.find((selectedShortcut) => selectedShortcut.id === shortcut.id));
const setPartialState = (partialState: Partial<State>) => {
setState({
...state,
...partialState,
});
};
useEffect(() => { useEffect(() => {
if (workspaceStore.setting.defaultVisibility !== Visibility.VISIBILITY_UNSPECIFIED) { if (workspaceStore.setting.defaultVisibility !== Visibility.VISIBILITY_UNSPECIFIED) {
setPartialState({ setPartialState({
@ -87,13 +94,6 @@ const CreateCollectionDrawer: React.FC<Props> = (props: Props) => {
return null; return null;
} }
const setPartialState = (partialState: Partial<State>) => {
setState({
...state,
...partialState,
});
};
const handleNameInputChange = (e: React.ChangeEvent<HTMLInputElement>) => { const handleNameInputChange = (e: React.ChangeEvent<HTMLInputElement>) => {
setPartialState({ setPartialState({
collectionCreate: Object.assign(state.collectionCreate, { collectionCreate: Object.assign(state.collectionCreate, {

View File

@ -59,6 +59,13 @@ const CreateShortcutDrawer: React.FC<Props> = (props: Props) => {
const loadingState = useLoading(!isCreating); const loadingState = useLoading(!isCreating);
const requestState = useLoading(false); const requestState = useLoading(false);
const setPartialState = (partialState: Partial<State>) => {
setState({
...state,
...partialState,
});
};
useEffect(() => { useEffect(() => {
if (workspaceStore.setting.defaultVisibility !== Visibility.VISIBILITY_UNSPECIFIED) { if (workspaceStore.setting.defaultVisibility !== Visibility.VISIBILITY_UNSPECIFIED) {
setPartialState({ setPartialState({
@ -94,13 +101,6 @@ const CreateShortcutDrawer: React.FC<Props> = (props: Props) => {
return null; return null;
} }
const setPartialState = (partialState: Partial<State>) => {
setState({
...state,
...partialState,
});
};
const handleNameInputChange = (e: React.ChangeEvent<HTMLInputElement>) => { const handleNameInputChange = (e: React.ChangeEvent<HTMLInputElement>) => {
setPartialState({ setPartialState({
shortcutCreate: Object.assign(state.shortcutCreate, { shortcutCreate: Object.assign(state.shortcutCreate, {