mirror of
https://github.com/pybricks/pybricks-code.git
synced 2026-09-12 01:23:52 +00:00
The redux store should not have non-serializable objects like the editor in it.
40 lines
1.2 KiB
TypeScript
40 lines
1.2 KiB
TypeScript
// SPDX-License-Identifier: MIT
|
|
// Copyright (c) 2020-2022 The Pybricks Authors
|
|
|
|
import React, { useContext } from 'react';
|
|
import { useDispatch } from 'react-redux';
|
|
import * as notificationActions from '../notifications/actions';
|
|
import OpenFileButton, { OpenFileButtonProps } from '../toolbar/OpenFileButton';
|
|
import { TooltipId } from '../toolbar/i18n';
|
|
import { EditorContext } from './Editor';
|
|
import * as editorActions from './actions';
|
|
import openIcon from './open.svg';
|
|
|
|
type OpenButtonProps = Pick<OpenFileButtonProps, 'id'>;
|
|
|
|
const OpenButton: React.FunctionComponent<OpenButtonProps> = (props) => {
|
|
const { editor } = useContext(EditorContext);
|
|
const dispatch = useDispatch();
|
|
|
|
return (
|
|
<OpenFileButton
|
|
fileExtension=".py"
|
|
tooltip={TooltipId.Open}
|
|
icon={openIcon}
|
|
enabled={editor !== null}
|
|
onFile={(data) => dispatch(editorActions.open(data))}
|
|
onReject={(file) =>
|
|
dispatch(
|
|
notificationActions.add(
|
|
'error',
|
|
`'${file.name}' is not a valid python file.`,
|
|
),
|
|
)
|
|
}
|
|
{...props}
|
|
/>
|
|
);
|
|
};
|
|
|
|
export default OpenButton;
|