mirror of
https://github.com/voideditor/void
synced 2026-05-24 09:58:23 +00:00
transfer button feedback
This commit is contained in:
parent
4968452003
commit
7bb0993249
2 changed files with 27 additions and 6 deletions
|
|
@ -567,8 +567,8 @@ export const VoidCodeEditor = ({ initValue, language, maxHeight, showScrollbars
|
|||
}
|
||||
|
||||
|
||||
export const VoidButton = ({ children, onClick }: { children: React.ReactNode; onClick: () => void }) => {
|
||||
return <button
|
||||
export const VoidButton = ({ children, disabled, onClick }: { children: React.ReactNode; disabled?:boolean; onClick: () => void }) => {
|
||||
return <button disabled={disabled}
|
||||
className='px-3 py-1 bg-black/10 dark:bg-gray-200/10 rounded-sm overflow-hidden'
|
||||
onClick={onClick}
|
||||
>{children}</button>
|
||||
|
|
|
|||
|
|
@ -498,24 +498,45 @@ const OneClickSwitch = () => {
|
|||
const accessor = useAccessor()
|
||||
const fileService = accessor.get('IFileService')
|
||||
|
||||
const [state, setState] = useState<{ type: 'done' | 'loading' | 'justfinished' } | { type: 'justerrored', error: string }>({ type: 'done' })
|
||||
|
||||
if (transferTheseFiles.length === 0)
|
||||
return <>
|
||||
<WarningBox text={transferError ?? `One-click transfer not available.`} />
|
||||
<WarningBox text={transferError ?? `One-click-switch not available.`} />
|
||||
</>
|
||||
|
||||
|
||||
|
||||
const onClick = async () => {
|
||||
|
||||
if (state.type !== 'done') return
|
||||
|
||||
setState({ type: 'loading' })
|
||||
|
||||
let errAcc = ''
|
||||
for (let { from, to } of transferTheseFiles) {
|
||||
console.log('transferring', from, to)
|
||||
// not sure if this can fail, just wrapping it with try/catch for now
|
||||
try { await fileService.copy(from, to, true) }
|
||||
catch (e) { console.error('Void Transfer Error:', e) }
|
||||
catch (e) { errAcc += e + '\n' }
|
||||
}
|
||||
const hadError = !!errAcc
|
||||
if (hadError) setState({ type: 'justerrored', error: errAcc })
|
||||
else setState({ type: 'justfinished' })
|
||||
|
||||
setTimeout(() => { setState({ type: 'done' }); }, hadError ? 5000 : 3000)
|
||||
}
|
||||
|
||||
return <>
|
||||
<VoidButton onClick={onClick}>
|
||||
Transfer Settings
|
||||
<VoidButton disabled={state.type !== 'done'} onClick={onClick}>
|
||||
{state.type === 'done' ? 'Transfer my Settings'
|
||||
: state.type === 'loading' ? 'Transferring...'
|
||||
: state.type === 'justfinished' ? 'Success!'
|
||||
: state.type === 'justerrored' ? `There was Error`
|
||||
: null
|
||||
}
|
||||
</VoidButton>
|
||||
{state.type === 'justerrored' && state.error}
|
||||
</>
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue