From b3d6d499758bc6d3ef69532c0f3df6d260077788 Mon Sep 17 00:00:00 2001 From: FTCHD <144691102+FTCHD@users.noreply.github.com> Date: Tue, 5 Aug 2025 05:24:22 +0300 Subject: [PATCH] extract buildReadablePath --- lib/format.ts | 14 ++++++++++++++ src/pages/Jobs.tsx | 16 +--------------- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/lib/format.ts b/lib/format.ts index c9bd072..4a20013 100644 --- a/lib/format.ts +++ b/lib/format.ts @@ -30,3 +30,17 @@ export function getRemoteName(path?: string) { if (!path?.includes(':')) return null // Return null for local paths 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}` +} diff --git a/src/pages/Jobs.tsx b/src/pages/Jobs.tsx index a32bd16..84c466d 100644 --- a/src/pages/Jobs.tsx +++ b/src/pages/Jobs.tsx @@ -5,7 +5,7 @@ import { ask } from '@tauri-apps/plugin-dialog' import { Trash2Icon } from 'lucide-react' import { useCallback, useEffect } from 'react' import { useState } from 'react' -import { formatBytes } from '../../lib/format' +import { buildReadablePath, formatBytes } from '../../lib/format' import { listJobs, stopJob } from '../../lib/rclone/api' export default function Jobs() { @@ -29,20 +29,6 @@ export default function Jobs() { 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(() => { fetchJobs()