-
-
Notifications
You must be signed in to change notification settings - Fork 831
/
CopyAsPath.tsx
36 lines (32 loc) · 892 Bytes
/
CopyAsPath.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import { ClipboardText } from '@phosphor-icons/react';
import { toast } from '@sd/ui';
import { Menu } from '~/components/Menu';
import { useLocale } from '~/hooks';
export const CopyAsPathBase = (
props: { path: string } | { getPath: () => Promise<string | null> }
) => {
const { t } = useLocale();
return (
<Menu.Item
label={t('copy_as_path')}
icon={ClipboardText}
onClick={async () => {
try {
const path = 'path' in props ? props.path : await props.getPath();
{
/* 'path' in props
? props.path
: await libraryClient.query(['files.getPath', props.filePath.id]); */
}
if (path == null) throw new Error('No file path available');
navigator.clipboard.writeText(path);
} catch (error) {
toast.error({
title: t('failed_to_copy_file_path'),
body: t('error_message', { error })
});
}
}}
/>
);
};