import Taro from '@tarojs/taro'
import { Text, View } from '@tarojs/components'
import Button from '@taroify/core/button'
import '@taroify/core/button/style'
import type { PracticeRecord } from '../services/practice'
import { duration } from '../utils/dates'
export { Button }
export function FormActions({ busy, cancelDisabled, saveDisabled, saveLabel = '保存', onCancel, onSave }: {
busy: boolean
cancelDisabled?: boolean
saveDisabled?: boolean
saveLabel?: string
onCancel: () => unknown
onSave: () => unknown
}) {
return
}
export function LoadState({ loading, error, retry }: { loading: boolean; error: string; retry: () => unknown }) {
if (!loading && !error) return null
return {loading ? '正在读取你的练习…' : error}{error && }
}
export function Empty({ title }: { title: string }) {
return {title}
}
export function RecordCards({ records }: { records: PracticeRecord[] }) {
return {records.map(record =>
{record.projectName}{duration(record.minutes)}
{record.date}{record.archived ? ' · 已归档项目' : ''}
{record.note && {record.note}}
)}
}
/** Return to the actual originating page; deep-entry forms fall back to records. */
export async function returnToSource(message?: string) {
if (Taro.getCurrentPages().length > 1) await Taro.navigateBack()
else await Taro.switchTab({ url: '/pages/index/index' })
if (message) void Taro.showToast({ title: message, icon: 'none' })
}