import * as React from 'react';
import { Icon, Button, Card, Chip } from 'react-native-paper';
import { _ } from '@joplin/lib/locale';
import { View } from 'react-native';
import { ItemEvent, PluginItem } from '@joplin/lib/components/shared/config/plugins/types';
export enum InstallState {
NotInstalled,
Installing,
Installed,
}
export enum UpdateState {
Idle = 1,
CanUpdate = 2,
Updating = 3,
HasBeenUpdated = 4,
}
type PluginCallback = (event: ItemEvent)=> void;
interface Props {
item: PluginItem;
isCompatible: boolean;
hasErrors?: boolean;
installState?: InstallState;
updateState?: UpdateState;
onInstall?: PluginCallback;
onUpdate?: PluginCallback;
onDelete?: PluginCallback;
onToggle?: PluginCallback;
onAboutPress?: PluginCallback;
onShowPluginLog?: PluginCallback;
}
const PluginIcon = (props: any) => ;
const PluginBox: React.FC = props => {
const manifest = props.item.manifest;
const item = props.item;
const installButtonTitle = () => {
if (props.installState === InstallState.Installing) return _('Installing...');
if (props.installState === InstallState.NotInstalled) return _('Install');
if (props.installState === InstallState.Installed) return _('Installed');
return `Invalid install state: ${props.installState}`;
};
const installButton = (
);
const updateButtonTitle = () => {
if (props.updateState === UpdateState.Updating) return _('Updating...');
if (props.updateState === UpdateState.HasBeenUpdated) return _('Updated');
return _('Update');
};
const updateButton = (
);
const deleteButton = (
);
const disableButton = ;
const enableButton = ;
const aboutButton = ;
const renderErrorsChip = () => {
if (!props.hasErrors) return null;
return (
props.onShowPluginLog({ item })}
>
Error
);
};
const renderRecommendedChip = () => {
if (!props.item.manifest._recommended) {
return null;
}
return {_('Recommended')};
};
const renderBuiltInChip = () => {
if (!props.item.builtIn) {
return null;
}
return {_('Built-in')};
};
const updateStateIsIdle = props.updateState !== UpdateState.Idle;
return (
{renderErrorsChip()}
{renderRecommendedChip()}
{renderBuiltInChip()}
{props.onAboutPress ? aboutButton : null}
{props.onInstall ? installButton : null}
{props.onDelete && !props.item.builtIn ? deleteButton : null}
{props.onUpdate && updateStateIsIdle ? updateButton : null}
{props.onToggle && props.item.enabled ? disableButton : null}
{props.onToggle && !props.item.enabled ? enableButton : null}
);
};
export default PluginBox;