Files
spacedrive/interface/app/$libraryId/Explorer/ContextMenu/FilePath/OpenWith.tsx
nikec 717e01ef1f [ENG-300] Explorer multi-select (#1197)
* grid

* Improved multi-select, grid list & view offset. Added gap option & app frame.

* List view multi-select

* Include multi-select in overview, fix page ref type

* Add gap to options panel

* Fix drag

* Update categories z-index

* going pretty well

* fix a couple bugs

* fix another bug :)

* minor improvements

* Separate grid activeItem

* extra comments

* um akshully don't ref during render

* show thumbnails yay

* cleanup

* Clean up

* Fix ranges

* here it is

* fix cols drag

* don't enforce selecto context

* explorer view selectable

* Update index.tsx

* Context menu support for multi-select (#1187)

* here it is

* stopPropagation

* cut copy multiple

---------

Co-authored-by: nikec <nikec.job@gmail.com>

* explorer view selectable

* Update index.tsx

* items Map

* fix renamable

* Update inspector

* Hide tag assign if empty

* fix merge

* cleanup

* fix un-rendered drag select

* fix double click quick preview

* update thumbnail

* mostly handle multiple select in keybindings

* fix ts

* remove another todo

* move useItemAs hooks to @sd/client

* fix thumb controls

* multi-select double click

* cleaner?

* smaller gap

---------

Co-authored-by: Jamie Pine <ijamespine@me.com>
Co-authored-by: Brendan Allan <brendonovich@outlook.com>
Co-authored-by: Jamie Pine <32987599+jamiepine@users.noreply.github.com>
Co-authored-by: Utku <74243531+utkubakir@users.noreply.github.com>
Co-authored-by: Ericson "Fogo" Soares <ericson.ds999@gmail.com>
2023-08-15 08:23:41 +00:00

81 lines
2.0 KiB
TypeScript

import { useQuery } from '@tanstack/react-query';
import { Suspense } from 'react';
import { useLibraryContext } from '@sd/client';
import { ContextMenu } from '@sd/ui';
import { showAlertDialog } from '~/components';
import { Platform, usePlatform } from '~/util/Platform';
import { ConditionalItem } from '../ConditionalItem';
import { useContextMenuContext } from '../context';
export default new ConditionalItem({
useCondition: () => {
const { selectedFilePaths } = useContextMenuContext();
const { getFilePathOpenWithApps, openFilePathWith } = usePlatform();
if (!getFilePathOpenWithApps || !openFilePathWith) return null;
if (selectedFilePaths.some((p) => p.is_dir)) return null;
return { getFilePathOpenWithApps, openFilePathWith };
},
Component: ({ getFilePathOpenWithApps, openFilePathWith }) => (
<ContextMenu.SubMenu label="Open with">
<Suspense>
<Items
actions={{
getFilePathOpenWithApps,
openFilePathWith
}}
/>
</Suspense>
</ContextMenu.SubMenu>
)
});
const Items = ({
actions
}: {
actions: Required<Pick<Platform, 'getFilePathOpenWithApps' | 'openFilePathWith'>>;
}) => {
const { selectedFilePaths } = useContextMenuContext();
const { library } = useLibraryContext();
const ids = selectedFilePaths.map((obj) => obj.id);
const items = useQuery<unknown>(
['openWith', ids],
() => actions.getFilePathOpenWithApps(library.uuid, ids),
{ suspense: true }
);
return (
<>
{Array.isArray(items.data) && items.data.length > 0 ? (
items.data.map((data, id) => (
<ContextMenu.Item
key={id}
onClick={async () => {
try {
await actions.openFilePathWith(
library.uuid,
ids.map((id) => [id, data.url])
);
} catch (e) {
console.error(e);
showAlertDialog({
title: 'Error',
value: `Failed to open file, with: ${data.url}`
});
}
}}
>
{data.name}
</ContextMenu.Item>
))
) : (
<p className="w-full text-center text-sm text-gray-400"> No apps available </p>
)}
</>
);
};