Files
pybricks-code/src/explorer/deleteFileAlert/reducers.ts
T
David Lechner d238e68deb explorer: new delete alert dialog
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.
2022-04-08 12:53:12 -05:00

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 });