// SPDX-License-Identifier: MIT // Copyright (c) 2021 The Pybricks Authors // The license dialog import { Button, ButtonGroup, Callout, Card, Classes, Dialog, NonIdealState, } from '@blueprintjs/core'; import { WithI18nProps, withI18n } from '@shopify/react-i18n'; import React from 'react'; import { connect } from 'react-redux'; import { Action, Dispatch } from '../actions'; import { closeLicenseDialog } from '../actions/app'; import { select } from '../actions/license'; import { RootState } from '../reducers'; import { LicenseInfo, LicenseList } from '../reducers/license'; import { appName } from '../settings/ui'; import { LicenseStringId } from './license-i18n'; import en from './license-i18n.en.json'; import './license.scss'; type StateProps = { showLicenseDialog: boolean; licenseList: LicenseList | null; licenseInfo: LicenseInfo | null; }; type DispatchProps = { onClose: () => void; onSelectPackage: (info: LicenseInfo) => void; }; type LicenseDialogProps = StateProps & DispatchProps & WithI18nProps; class LicenseDialog extends React.Component { render(): JSX.Element { const infoDiv = React.createRef(); const { i18n, showLicenseDialog, onClose, licenseList, licenseInfo, onSelectPackage, } = this.props; return ( onClose()} className="pb-license-dialog" >
{i18n.translate(LicenseStringId.Description, { name: appName, })}
{licenseList === null ? ( // TODO: this should be translated and hooked to // state indicating if download is in progress // or there was an actual failure. Failed to load license data. ) : ( {licenseList.map((info) => ( ))} )}
{licenseInfo == null ? ( {i18n.translate(LicenseStringId.SelectPackageHelp)} ) : (

{i18n.translate( LicenseStringId.PackageLabel, )} {' '} {licenseInfo.name}{' '} v{licenseInfo.version}

{licenseInfo.author && (

{' '} {i18n.translate( LicenseStringId.AuthorLabel, )} {' '} {licenseInfo.author}

)}

{' '} {i18n.translate( LicenseStringId.LicenseLabel, )} {' '} {licenseInfo.license}

{licenseInfo.licenseText}
)}
); } } const mapStateToProps = (state: RootState): StateProps => ({ showLicenseDialog: state.app.showLicenseDialog, licenseList: state.license.list, licenseInfo: state.license.selected, }); const mapDispatchToProps = (dispatch: Dispatch): DispatchProps => ({ onClose: (): Action => dispatch(closeLicenseDialog()), onSelectPackage: (info): Action => dispatch(select(info)), }); export default connect( mapStateToProps, mapDispatchToProps, )(withI18n({ id: 'license', fallback: en, translations: { en } })(LicenseDialog));