Implement Navidrome sharing (#575)

* add share item feature

* take care of (mostly) everything

* bugfixes

* allow clicking on notification to open url

* readd the missing modal after router migration

* remove unnecessary extension

---------

Co-authored-by: Kendall Garner <17521368+kgarner7@users.noreply.github.com>
This commit is contained in:
Benjamin 2024-04-21 22:03:22 -05:00 committed by GitHub
parent 0d03b66fe5
commit cb2597d2c8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
14 changed files with 303 additions and 4 deletions

View file

@ -11,6 +11,8 @@ import {
import { closeAllModals, openContextModal, openModal } from '@mantine/modals';
import { AnimatePresence } from 'framer-motion';
import isElectron from 'is-electron';
import { ServerFeature } from '/@/renderer/api/features-types';
import { hasFeature } from '/@/renderer/api/utils';
import { useTranslation } from 'react-i18next';
import {
RiAddBoxFill,
@ -25,6 +27,7 @@ import {
RiPlayListAddFill,
RiStarFill,
RiCloseCircleLine,
RiShareForwardFill,
RiInformationFill,
} from 'react-icons/ri';
import { AnyLibraryItems, LibraryItem, ServerType, AnyLibraryItem } from '/@/renderer/api/types';
@ -78,7 +81,7 @@ const ContextMenuContext = createContext<ContextMenuContextProps>({
},
});
const JELLYFIN_IGNORED_MENU_ITEMS: ContextMenuItemType[] = ['setRating'];
const JELLYFIN_IGNORED_MENU_ITEMS: ContextMenuItemType[] = ['setRating', 'shareItem'];
// const NAVIDROME_IGNORED_MENU_ITEMS: ContextMenuItemType[] = [];
// const SUBSONIC_IGNORED_MENU_ITEMS: ContextMenuItemType[] = [];
@ -602,6 +605,22 @@ export const ContextMenuProvider = ({ children }: ContextMenuProviderProps) => {
}
}, [ctx.dataNodes, moveToTopOfQueue, playbackType]);
const handleShareItem = useCallback(() => {
if (!ctx.dataNodes && !ctx.data) return;
const uniqueIds = ctx.data.map((node) => node.id);
openContextModal({
innerProps: {
itemIds: uniqueIds,
resourceType: ctx.data[0].itemType,
},
modal: 'shareItem',
size: 'md',
title: t('page.contextMenu.shareItem', { postProcess: 'sentenceCase' }),
});
}, [ctx.data, ctx.dataNodes, t]);
const handleRemoveSelected = useCallback(() => {
const uniqueIds = ctx.dataNodes?.map((row) => row.data.uniqueId);
if (!uniqueIds?.length) return;
@ -787,6 +806,13 @@ export const ContextMenuProvider = ({ children }: ContextMenuProviderProps) => {
onClick: () => {},
rightIcon: <RiArrowRightSFill size="1.2rem" />,
},
shareItem: {
disabled: !hasFeature(server, ServerFeature.SHARING_ALBUM_SONG),
id: 'shareItem',
label: t('page.contextMenu.shareItem', { postProcess: 'sentenceCase' }),
leftIcon: <RiShareForwardFill size="1.1rem" />,
onClick: handleShareItem,
},
showDetails: {
disabled: ctx.data?.length !== 1 || !ctx.data[0].itemType,
id: 'showDetails',
@ -810,6 +836,8 @@ export const ContextMenuProvider = ({ children }: ContextMenuProviderProps) => {
handleOpenItemDetails,
handlePlay,
handleUpdateRating,
handleShareItem,
server,
]);
const mergedRef = useMergedRef(ref, clickOutsideRef);