Add Share to Context menus, also share artist

This commit is contained in:
Deluan 2023-01-24 13:35:51 -05:00
parent 051e9c556d
commit 433da37982
5 changed files with 50 additions and 8 deletions

View File

@ -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
})

View File

@ -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}})

View File

@ -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()

View File

@ -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))
},

View File

@ -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(