mirror of
https://github.com/pybricks/pybricks-code.git
synced 2026-09-12 01:23:52 +00:00
This replaces the delete notification with a new alert dialog. This makes for better keyboard interaction and forces the user to make a decision before doing anything else. Also fixes closing the editor before deleting the file.
37 lines
894 B
TypeScript
37 lines
894 B
TypeScript
// SPDX-License-Identifier: MIT
|
|
// Copyright (c) 2022 The Pybricks Authors
|
|
|
|
import { Reducer, combineReducers } from 'redux';
|
|
import {
|
|
deleteFileAlertDidAccept,
|
|
deleteFileAlertDidCancel,
|
|
deleteFileAlertShow,
|
|
} from './actions';
|
|
|
|
/** Controls the delete file alert dialog isOpen state. */
|
|
const isOpen: Reducer<boolean> = (state = false, action) => {
|
|
if (deleteFileAlertShow.matches(action)) {
|
|
return true;
|
|
}
|
|
|
|
if (
|
|
deleteFileAlertDidAccept.matches(action) ||
|
|
deleteFileAlertDidCancel.matches(action)
|
|
) {
|
|
return false;
|
|
}
|
|
|
|
return state;
|
|
};
|
|
|
|
/** Controls the file name displayed in the file alert dialog. */
|
|
const fileName: Reducer<string> = (state = '', action) => {
|
|
if (deleteFileAlertShow.matches(action)) {
|
|
return action.fileName;
|
|
}
|
|
|
|
return state;
|
|
};
|
|
|
|
export default combineReducers({ isOpen, fileName });
|