一些检查失败了
automerge / automerge (push) Has been cancelled
react-native-android-build-apk / AssembleRelease (push) Has been cancelled
Build macOS M1 / Main (push) Has been cancelled
Joplin Continuous Integration / Main (macos-15-intel) (push) Has been cancelled
Joplin Continuous Integration / Main (ubuntu-22.04) (push) Has been cancelled
Joplin Continuous Integration / Main (ubuntu-22.04-arm) (push) Has been cancelled
Joplin Continuous Integration / Main (windows-11-vs2026-arm) (push) Has been cancelled
Joplin Continuous Integration / Main (windows-2025) (push) Has been cancelled
Joplin Continuous Integration / ServerDockerImage (ubuntu-22.04) (push) Has been cancelled
Joplin Continuous Integration / ServerDockerImage (ubuntu-22.04-arm) (push) Has been cancelled
Joplin UI tests / Main (ubuntu-22.04) (push) Has been cancelled
Joplin UI tests / Main (windows-2025) (push) Has been cancelled
Joplin UI tests / Mobile (push) Has been cancelled
Close stale issues / ProcessStaleIssues (push) Has been cancelled
50 行
1.9 KiB
TypeScript
50 行
1.9 KiB
TypeScript
import { useEffect, useRef } from 'react';
|
|
import { DialogState } from '../types';
|
|
import { Dispatch } from 'redux';
|
|
|
|
// Syncs whether dialogs are open/closed with the global reducer state.
|
|
const useSyncDialogState = (dialogState: DialogState, dispatch: Dispatch) => {
|
|
const lastDialogStateRef = useRef(dialogState);
|
|
useEffect(() => {
|
|
const prevState = lastDialogStateRef.current;
|
|
const state = dialogState;
|
|
if (state.notePropertiesDialogOptions !== prevState.notePropertiesDialogOptions) {
|
|
dispatch({
|
|
type: state.notePropertiesDialogOptions && state.notePropertiesDialogOptions.visible ? 'VISIBLE_DIALOGS_ADD' : 'VISIBLE_DIALOGS_REMOVE',
|
|
name: 'noteProperties',
|
|
});
|
|
}
|
|
|
|
if (state.noteContentPropertiesDialogOptions !== prevState.noteContentPropertiesDialogOptions) {
|
|
dispatch({
|
|
type: state.noteContentPropertiesDialogOptions && state.noteContentPropertiesDialogOptions.visible ? 'VISIBLE_DIALOGS_ADD' : 'VISIBLE_DIALOGS_REMOVE',
|
|
name: 'noteContentProperties',
|
|
});
|
|
}
|
|
|
|
if (state.shareNoteDialogOptions !== prevState.shareNoteDialogOptions) {
|
|
dispatch({
|
|
type: state.shareNoteDialogOptions && state.shareNoteDialogOptions.visible ? 'VISIBLE_DIALOGS_ADD' : 'VISIBLE_DIALOGS_REMOVE',
|
|
name: 'shareNote',
|
|
});
|
|
}
|
|
|
|
if (state.shareFolderDialogOptions !== prevState.shareFolderDialogOptions) {
|
|
dispatch({
|
|
type: state.shareFolderDialogOptions && state.shareFolderDialogOptions.visible ? 'VISIBLE_DIALOGS_ADD' : 'VISIBLE_DIALOGS_REMOVE',
|
|
name: 'shareFolder',
|
|
});
|
|
}
|
|
|
|
if (state.publishFolderDialogOptions !== prevState.publishFolderDialogOptions) {
|
|
dispatch({
|
|
type: state.publishFolderDialogOptions && state.publishFolderDialogOptions.visible ? 'VISIBLE_DIALOGS_ADD' : 'VISIBLE_DIALOGS_REMOVE',
|
|
name: 'publishFolder',
|
|
});
|
|
}
|
|
lastDialogStateRef.current = dialogState;
|
|
}, [dialogState, dispatch]);
|
|
};
|
|
|
|
export default useSyncDialogState;
|