Skip to content

Commit

Permalink
[ENG-1619] Add spacedrop to the context menu (spacedriveapp#2119)
Browse files Browse the repository at this point in the history
add spacedrop to context menu
  • Loading branch information
niikeec committed Feb 22, 2024
1 parent dd0acad commit d007b55
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 18 deletions.
50 changes: 33 additions & 17 deletions interface/app/$libraryId/Explorer/ContextMenu/SharedItems.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { FileX, Share as ShareIcon } from '@phosphor-icons/react';
import { useMemo } from 'react';
import { useSelector } from '@sd/client';
import { useBridgeMutation, useDiscoveredPeers, useSelector } from '@sd/client';
import { ContextMenu, ModifierKeys } from '@sd/ui';
import { Menu } from '~/components/Menu';
import { useLocale, useOperatingSystem } from '~/hooks';
Expand All @@ -12,6 +12,7 @@ import { useExplorerContext } from '../Context';
import { getQuickPreviewStore } from '../QuickPreview/store';
import { RevealInNativeExplorerBase } from '../RevealInNativeExplorer';
import { explorerStore } from '../store';
import { getPaths } from '../useExplorerDnd';
import { useViewItemDoubleClick } from '../View/ViewItem';
import { Conditional, ConditionalItem } from './ConditionalItem';
import { useContextMenuContext } from './context';
Expand Down Expand Up @@ -200,21 +201,36 @@ export const Share = () => {
const { t } = useLocale();

return (
<>
<Menu.Item
label={t('share')}
icon={ShareIcon}
onClick={(e: { preventDefault: () => void }) => {
e.preventDefault();

navigator.share?.({
title: 'Spacedrive',
text: 'Check out this cool app',
url: 'https://spacedrive.com'
});
}}
disabled
/>
</>
<Menu.SubMenu label={t('share')} icon={ShareIcon}>
<Menu.SubMenu label="Spacedrop">
<SpacedropNodes />
</Menu.SubMenu>
</Menu.SubMenu>
);
};

const SpacedropNodes = () => {
const { t } = useLocale();
const explorer = useExplorerContext();
const discoveredPeers = useDiscoveredPeers();

const spacedrop = useBridgeMutation('p2p.spacedrop');

if (discoveredPeers.size === 0) {
return <p className="p-1 text-center text-sm">{t('no_nodes_found')}</p>;
}

return Array.from(discoveredPeers).map(([id, peer]) => (
<Menu.Item
key={id}
label={peer.name}
disabled={spacedrop.isLoading}
onClick={async () => {
spacedrop.mutateAsync({
identity: id,
file_path: await getPaths([...explorer.selectedItems])
});
}}
/>
));
};
2 changes: 1 addition & 1 deletion interface/app/$libraryId/Explorer/useExplorerDnd.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { explorerStore } from './store';
import { explorerDroppableSchema } from './useExplorerDroppable';
import { useExplorerSearchParams } from './util';

const getPaths = async (items: ExplorerItem[]) => {
export const getPaths = async (items: ExplorerItem[]) => {
const paths = items.map(async (item) => {
const filePath = getItemFilePath(item);
if (!filePath) return;
Expand Down

0 comments on commit d007b55

Please sign in to comment.