一些检查失败了
automerge / automerge (push) Has been cancelled
react-native-android-build-apk / AssembleRelease (push) Has been cancelled
Build macOS M1 / Main (push) Has been cancelled
Joplin Continuous Integration / Main (macos-15-intel) (push) Has been cancelled
Joplin Continuous Integration / Main (ubuntu-22.04) (push) Has been cancelled
Joplin Continuous Integration / Main (ubuntu-22.04-arm) (push) Has been cancelled
Joplin Continuous Integration / Main (windows-11-vs2026-arm) (push) Has been cancelled
Joplin Continuous Integration / Main (windows-2025) (push) Has been cancelled
Joplin Continuous Integration / ServerDockerImage (ubuntu-22.04) (push) Has been cancelled
Joplin Continuous Integration / ServerDockerImage (ubuntu-22.04-arm) (push) Has been cancelled
Joplin UI tests / Main (ubuntu-22.04) (push) Has been cancelled
Joplin UI tests / Main (windows-2025) (push) Has been cancelled
Joplin UI tests / Mobile (push) Has been cancelled
Close stale issues / ProcessStaleIssues (push) Has been cancelled
49 行
1.2 KiB
TypeScript
49 行
1.2 KiB
TypeScript
import * as React from 'react';
|
|
import Setting, { SettingButtonStyle } from '@joplin/lib/models/Setting';
|
|
import Button, { ButtonLevel } from '../../Button/Button';
|
|
import { useCallback, useState } from 'react';
|
|
import Logger from '@joplin/utils/Logger';
|
|
|
|
const logger = Logger.create('SettingButton');
|
|
|
|
interface Props {
|
|
settingKey: string;
|
|
onSettingButtonClick: (key: string)=> Promise<void>;
|
|
}
|
|
|
|
const SettingButton: React.FC<Props> = ({
|
|
settingKey, onSettingButtonClick,
|
|
}) => {
|
|
const key = settingKey;
|
|
const md = Setting.settingMetadata(key);
|
|
|
|
const [loading, setLoading] = useState(false);
|
|
const [error, setError] = useState<string|null>(null);
|
|
|
|
const onClick = useCallback(async () => {
|
|
setError(null);
|
|
setLoading(true);
|
|
|
|
try {
|
|
await onSettingButtonClick(key);
|
|
} catch (error) {
|
|
logger.warn('Failed to run command for button', key, error);
|
|
setError(String(error));
|
|
} finally {
|
|
setLoading(false);
|
|
}
|
|
}, [key, onSettingButtonClick]);
|
|
|
|
return <>
|
|
<Button
|
|
level={md.buttonStyle === SettingButtonStyle.Highlighted ? ButtonLevel.Primary : ButtonLevel.Secondary}
|
|
title={md.label()}
|
|
onClick={onClick}
|
|
disabled={loading}
|
|
/>
|
|
{error && <span className='error'>{error}</span>}
|
|
</>;
|
|
};
|
|
|
|
export default SettingButton;
|