import { useQuery } from '@tanstack/react-query';
import { Suspense } from 'react';
import { FilePath, useLibraryContext } from '@sd/client';
import { ContextMenu } from '@sd/ui';
import { showAlertDialog } from '~/components';
import { Platform, usePlatform } from '~/util/Platform';
export default (props: { filePath: FilePath }) => {
const { getFilePathOpenWithApps, openFilePathWith } = usePlatform();
if (!getFilePathOpenWithApps || !openFilePathWith) return null;
if (props.filePath.is_dir) return null;
return (
);
};
const Items = ({
filePath,
actions
}: {
filePath: FilePath;
actions: Required>;
}) => {
const { library } = useLibraryContext();
const items = useQuery(
['openWith', filePath.id],
() => actions.getFilePathOpenWithApps(library.uuid, [filePath.id]),
{ suspense: true }
);
return (
<>
{Array.isArray(items.data) && items.data.length > 0 ? (
items.data.map((data, id) => (
{
try {
await actions.openFilePathWith(library.uuid, [
[filePath.id, data.url]
]);
} catch (e) {
console.error(e);
showAlertDialog({
title: 'Error',
value: `Failed to open file, with: ${data.url}`
});
}
}}
>
{data.name}
))
) : (
No apps available
)}
>
);
};