2024-01-30 05:54:51 -05:00
|
|
|
import clsx from 'clsx';
|
2023-03-08 16:36:14 -05:00
|
|
|
import React, { useEffect, useRef, useState } from 'react'
|
2023-03-08 12:03:57 -05:00
|
|
|
import { useTranslation } from 'react-i18next';
|
2024-01-30 05:54:51 -05:00
|
|
|
import { useLog } from 'services/s3si';
|
2023-03-08 12:03:57 -05:00
|
|
|
import { Checkbox } from './Checkbox';
|
|
|
|
|
import { Loading } from './Loading';
|
2024-01-30 05:54:51 -05:00
|
|
|
import { useService } from 'services/useService';
|
|
|
|
|
import { useAppContext } from 'context/app'
|
2023-03-08 12:03:57 -05:00
|
|
|
|
2024-01-30 05:54:51 -05:00
|
|
|
type RunPanelProps = Record<string, never>
|
2023-03-08 12:03:57 -05:00
|
|
|
|
|
|
|
|
export const RunPanel: React.FC<RunPanelProps> = () => {
|
|
|
|
|
const { t } = useTranslation();
|
2024-01-30 05:54:51 -05:00
|
|
|
const { data: result } = useService('profile', 0)
|
2023-03-08 12:03:57 -05:00
|
|
|
const [exportBattle, setExportBattle] = useState(true);
|
|
|
|
|
const [exportCoop, setExportCoop] = useState(true);
|
2024-01-30 05:54:51 -05:00
|
|
|
const { exports } = useAppContext()
|
|
|
|
|
const disabled = !exports
|
|
|
|
|
const isExporting = exports?.isExporting ?? false
|
2023-03-08 12:03:57 -05:00
|
|
|
|
|
|
|
|
if (!result) {
|
|
|
|
|
return <Loading />
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return <>
|
2023-03-08 17:38:39 -05:00
|
|
|
<div className="tooltip" data-tip={disabled ? t('请先在设置中完成Nintendo Account登录和stat.ink的API密钥') : undefined}>
|
2024-01-30 05:54:51 -05:00
|
|
|
<Checkbox disabled={disabled || isExporting} value={exportBattle} onChange={setExportBattle}>{t('导出对战数据')}</Checkbox>
|
|
|
|
|
<Checkbox disabled={disabled || isExporting} value={exportCoop} onChange={setExportCoop}>{t('导出打工数据')}</Checkbox>
|
2023-03-08 16:36:14 -05:00
|
|
|
<button
|
2024-01-30 05:54:45 -05:00
|
|
|
type='button'
|
2024-01-30 05:54:51 -05:00
|
|
|
onClick={() => exports?.trigger({ exportBattle, exportCoop })}
|
|
|
|
|
className={clsx('btn btn-primary w-full', {
|
2023-03-08 16:36:14 -05:00
|
|
|
'btn-disabled': disabled || (!exportBattle && !exportCoop),
|
|
|
|
|
})}
|
2024-01-30 05:54:51 -05:00
|
|
|
disabled={isExporting}
|
|
|
|
|
>{isExporting ? <span className='loading' /> : t('导出')}</button>
|
2023-03-08 16:36:14 -05:00
|
|
|
</div>
|
2023-03-08 12:03:57 -05:00
|
|
|
</>
|
|
|
|
|
}
|
2023-03-08 16:36:14 -05:00
|
|
|
|
|
|
|
|
export type LogPanelProps = {
|
|
|
|
|
className?: string
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export const LogPanel: React.FC<LogPanelProps> = ({ className }) => {
|
|
|
|
|
const { renderedLogs } = useLog();
|
|
|
|
|
const div = useRef<HTMLDivElement>(null);
|
|
|
|
|
const { t } = useTranslation();
|
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
if (div.current) {
|
|
|
|
|
div.current.scrollTop = div.current.scrollHeight;
|
|
|
|
|
}
|
|
|
|
|
}, [renderedLogs])
|
|
|
|
|
|
2023-03-09 06:33:32 -05:00
|
|
|
return <div ref={div} className={`bg-neutral text-neutral-content overflow-auto rounded p-4 ${className}`}>
|
2023-03-08 16:36:14 -05:00
|
|
|
{renderedLogs.length === 0 && <pre><code>{t('欢迎! 请点击"导出"按钮开始使用.')}</code></pre>}
|
|
|
|
|
{renderedLogs.map((line, i) => <pre key={i}><code>{line}</code></pre>)}
|
|
|
|
|
</div>
|
|
|
|
|
}
|