extract buildReadablePath

This commit is contained in:
FTCHD
2025-08-05 05:24:22 +03:00
parent 58ca8a92fa
commit b3d6d49975
2 changed files with 15 additions and 15 deletions
+14
View File
@@ -30,3 +30,17 @@ export function getRemoteName(path?: string) {
if (!path?.includes(':')) return null // Return null for local paths if (!path?.includes(':')) return null // Return null for local paths
return path.split(':')[0] return path.split(':')[0]
} }
export function buildReadablePath(path: string, type: 'short' | 'long' = 'long') {
if (!path) {
return ''
}
const lastSegment = path.split('\\').slice(-1).join('').split('/').slice(-1).join('')
if (type === 'short') {
return lastSegment
}
return `${path.split(':')[0]}:/.../${lastSegment}`
}
+1 -15
View File
@@ -5,7 +5,7 @@ import { ask } from '@tauri-apps/plugin-dialog'
import { Trash2Icon } from 'lucide-react' import { Trash2Icon } from 'lucide-react'
import { useCallback, useEffect } from 'react' import { useCallback, useEffect } from 'react'
import { useState } from 'react' import { useState } from 'react'
import { formatBytes } from '../../lib/format' import { buildReadablePath, formatBytes } from '../../lib/format'
import { listJobs, stopJob } from '../../lib/rclone/api' import { listJobs, stopJob } from '../../lib/rclone/api'
export default function Jobs() { export default function Jobs() {
@@ -29,20 +29,6 @@ export default function Jobs() {
setIsInitialLoad(false) setIsInitialLoad(false)
}, []) }, [])
const buildReadablePath = useCallback((path: string, type: 'short' | 'long' = 'long') => {
if (!path) {
return ''
}
const lastSegment = path.split('\\').slice(-1).join('').split('/').slice(-1).join('')
if (type === 'short') {
return lastSegment
}
return `${path.split(':')[0]}:/.../${lastSegment}`
}, [])
useEffect(() => { useEffect(() => {
fetchJobs() fetchJobs()