Skip to content

🎧 Your Personal Streaming Service

Add Share to Context menus, also share artist

Deluan433da37982a6
diff --git a/core/share.go b/core/share.go
index c6b97b245..aa87015f5 100644
--- a/core/share.go
+++ b/core/share.go
@@ -100,6 +100,9 @@ func (r *shareRepositoryWrapper) Save(entity interface{}) (string, error) {
return "", err
}
switch v.(type) {
+ case *model.Artist:
+ s.ResourceType = "artist"
+ s.Contents = r.contentsLabelFromArtist(s.ID, s.ResourceIDs)
case *model.Album:
s.ResourceType = "album"
s.Contents = r.contentsLabelFromAlbums(s.ID, s.ResourceIDs)
@@ -131,6 +134,16 @@ func (r *shareRepositoryWrapper) Update(id string, entity interface{}, _ ...stri
return r.Persistable.Update(id, entity, cols...)
}
+func (r *shareRepositoryWrapper) contentsLabelFromArtist(shareID string, ids string) string {
+ idList := strings.SplitN(ids, ",", 2)
+ a, err := r.ds.Artist(r.ctx).Get(idList[0])
+ if err != nil {
+ log.Error(r.ctx, "Error retrieving artist name for share", "share", shareID, err)
+ return ""
+ }
+ return a.Name
+}
+
func (r *shareRepositoryWrapper) contentsLabelFromAlbums(shareID string, ids string) string {
idList := strings.Split(ids, ",")
all, err := r.ds.Album(r.ctx).GetAll(model.QueryOptions{Filters: squirrel.Eq{"id": idList}})
@@ -158,6 +171,10 @@ func (r *shareRepositoryWrapper) contentsLabelFromMediaFiles(shareID string, ids
return ""
}
+ if len(mfs) == 1 {
+ return mfs[0].Title
+ }
+
albums := slice.Group(mfs, func(mf model.MediaFile) string {
return mf.Album
})
diff --git a/persistence/share_repository.go b/persistence/share_repository.go
index d52fb2775..ac586e6be 100644
--- a/persistence/share_repository.go
+++ b/persistence/share_repository.go
@@ -78,6 +78,15 @@ func (r *shareRepository) loadMedia(share *model.Share) error {
return nil
}
switch share.ResourceType {
+ case "artist":
+ albumRepo := NewAlbumRepository(r.ctx, r.ormer)
+ share.Albums, err = albumRepo.GetAll(model.QueryOptions{Filters: Eq{"album_artist_id": ids}, Sort: "artist"})
+ if err != nil {
+ return err
+ }
+ mfRepo := NewMediaFileRepository(r.ctx, r.ormer)
+ share.Tracks, err = mfRepo.GetAll(model.QueryOptions{Filters: Eq{"album_artist_id": ids}, Sort: "artist"})
+ return err
case "album":
albumRepo := NewAlbumRepository(r.ctx, r.ormer)
share.Albums, err = albumRepo.GetAll(model.QueryOptions{Filters: Eq{"id": ids}})
diff --git a/ui/src/common/ContextMenus.js b/ui/src/common/ContextMenus.js
index 4514e7683..14f952389 100644
--- a/ui/src/common/ContextMenus.js
+++ b/ui/src/common/ContextMenus.js
@@ -18,6 +18,7 @@ import {
openExtendedInfoDialog,
DOWNLOAD_MENU_ALBUM,
DOWNLOAD_MENU_ARTIST,
+ openShareMenu,
} from '../actions'
import { LoveButton } from './LoveButton'
import config from '../config'
@@ -79,12 +80,18 @@ const ContextMenu = ({
label: translate('resources.album.actions.addToPlaylist'),
action: (data, ids) => dispatch(openAddToPlaylist({ selectedIds: ids })),
},
+ share: {
+ enabled: config.devEnableShare,
+ needData: false,
+ label: translate('ra.action.share'),
+ action: (record) => {
+ dispatch(openShareMenu([record.id], resource, record.name))
+ },
+ },
download: {
enabled: config.enableDownloads && record.size,
needData: false,
- label: `${translate('resources.album.actions.download')} (${formatBytes(
- record.size
- )})`,
+ label: `${translate('ra.action.download')} (${formatBytes(record.size)})`,
action: () => {
dispatch(
openDownloadMenu(
@@ -141,7 +148,7 @@ const ContextMenu = ({
notify('ra.page.error', 'warning')
})
} else {
- options[key].action()
+ options[key].action(record)
}
e.stopPropagation()
diff --git a/ui/src/common/SongContextMenu.js b/ui/src/common/SongContextMenu.js
index 776718086..ef5d3e0f6 100644
--- a/ui/src/common/SongContextMenu.js
+++ b/ui/src/common/SongContextMenu.js
@@ -14,6 +14,7 @@ import {
openExtendedInfoDialog,
openDownloadMenu,
DOWNLOAD_MENU_SONG,
+ openShareMenu,
} from '../actions'
import { LoveButton } from './LoveButton'
import config from '../config'
@@ -63,11 +64,16 @@ export const SongContextMenu = ({
})
),
},
+ share: {
+ enabled: config.devEnableShare,
+ label: translate('ra.action.share'),
+ action: (record) => {
+ dispatch(openShareMenu([record.id], 'song', record.title))
+ },
+ },
download: {
enabled: config.enableDownloads,
- label: `${translate('resources.song.actions.download')} (${formatBytes(
- record.size
- )})`,
+ label: `${translate('ra.action.download')} (${formatBytes(record.size)})`,
action: (record) => {
dispatch(openDownloadMenu(record, DOWNLOAD_MENU_SONG))
},
diff --git a/ui/src/dialogs/ShareDialog.js b/ui/src/dialogs/ShareDialog.js
index 8ac2c4f70..ccef4ed11 100644
--- a/ui/src/dialogs/ShareDialog.js
+++ b/ui/src/dialogs/ShareDialog.js
@@ -12,7 +12,7 @@ import {
useNotify,
useTranslate,
} from 'react-admin'
-import { useState } from 'react'
+import { useEffect, useState } from 'react'
import { shareUrl } from '../utils'
import { useTranscodingOptions } from './useTranscodingOptions'
import { useDispatch, useSelector } from 'react-redux'
@@ -26,6 +26,9 @@ export const ShareDialog = () => {
const notify = useNotify()
const translate = useTranslate()
const [description, setDescription] = useState('')
+ useEffect(() => {
+ setDescription('')
+ }, [ids])
const { TranscodingOptionsInput, format, maxBitRate, originalFormat } =
useTranscodingOptions()
const [createShare] = useCreate(