Skip to content

Commit 4d05c75

Browse files
authored
fix: Stop Back Action at audiofolder root level (#2293)
* bugfix: Stop Back Action at audiofolder root level This also allows to go back when folder is empty Fixes #2224 * fix: Flake8 issue * Remove some minor issues
1 parent c5e58d5 commit 4d05c75

File tree

8 files changed

+43
-33
lines changed

8 files changed

+43
-33
lines changed

src/jukebox/jukebox/playlistgenerator.py

+7-2
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,12 @@ def get_directory_content(self, path='.'):
275275
logger.error(f" {e.__class__.__name__}: {e}")
276276
else:
277277
for m in content:
278-
self.playlist.append({'type': TYPE_DECODE[m.filetype], 'name': m.name, 'path': m.path})
278+
self.playlist.append({
279+
'type': TYPE_DECODE[m.filetype],
280+
'name': m.name,
281+
'path': m.path,
282+
'relpath': os.path.relpath(m.path, self._music_library_base_path)
283+
})
279284

280285
def _parse_nonrecusive(self, path='.'):
281286
return [x.path for x in self._get_directory_content(path) if x.filetype != TYPE_DIR]
@@ -294,7 +299,7 @@ def _parse_recursive(self, path='.'):
294299
return recursive_playlist
295300

296301
def parse(self, path='.', recursive=False):
297-
"""Parse the folder ``path`` and create a playlist from it's content
302+
"""Parse the folder ``path`` and create a playlist from its content
298303
299304
:param path: Path to folder **relative** to ``music_library_base_path``
300305
:param recursive: Parse folder recursivley, or stay in top-level folder

src/webapp/public/locales/de/translation.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -138,8 +138,8 @@
138138
"title": "Wähle ein Album, einen Ordner oder einen Song aus"
139139
},
140140
"folders": {
141-
"no-music": "Keine Musik vorhanden!",
142-
"empty-folder": "Dieser Ordner ist leer!",
141+
"no-music": "☝️ Keine Musik vorhanden!",
142+
"empty-folder": "Dieser Ordner ist leer! 🙈",
143143
"show-folder-content": "Zeige den Ordnerinhalt an",
144144
"back-button-label": "Zurück"
145145
},

src/webapp/public/locales/en/translation.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -138,8 +138,8 @@
138138
"title": "Select an album, folder or song"
139139
},
140140
"folders": {
141-
"no-music": "No music found!",
142-
"empty-folder": "This folder is empty!",
141+
"no-music": "☝️ No music found!",
142+
"empty-folder": "This folder is empty! 🙈",
143143
"show-folder-content": "Show folder content",
144144
"back-button-label": "Back"
145145
},

src/webapp/src/components/Cards/controls/actions/play-music/selected-folder.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import {
88

99
import NoMusicSelected from './no-music-selected';
1010
import FolderTypeAvatar from '../../../../Library/lists/folders/folder-type-avatar';
11-
import { DEFAULT_AUDIO_DIR } from '../../../../../config';
1211

1312
const SelectedFolder = ({ values: [folder] }) => {
1413
// TODO: Implement type correctly
@@ -19,7 +18,7 @@ const SelectedFolder = ({ values: [folder] }) => {
1918
<List sx={{ width: '100%', margin: '10px' }}>
2019
<ListItem disablePadding>
2120
<FolderTypeAvatar type={type} />
22-
<ListItemText primary={folder.replace(`${DEFAULT_AUDIO_DIR}/`, '')} />
21+
<ListItemText primary={folder} />
2322
</ListItem>
2423
</List>
2524
);

src/webapp/src/components/Library/lists/folders/folder-list-item.js

+6-7
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,19 @@ import NavigateNextIcon from '@mui/icons-material/NavigateNext';
1313
import request from '../../../../utils/request';
1414
import FolderLink from './folder-link';
1515
import FolderTypeAvatar from './folder-type-avatar';
16-
import { DEFAULT_AUDIO_DIR } from '../../../../config';
1716

1817
const FolderListItem = ({
1918
folder,
2019
isSelecting,
2120
registerMusicToCard,
2221
}) => {
2322
const { t } = useTranslation();
24-
const { type, name, path } = folder;
23+
const { type, name, relpath } = folder;
2524

2625
const playItem = () => {
2726
switch(type) {
28-
case 'directory': return request('play_folder', { folder: path, recursive: true });
29-
case 'file': return request('play_single', { song_url: path.replace(`${DEFAULT_AUDIO_DIR}/`, '') });
27+
case 'directory': return request('play_folder', { folder: relpath, recursive: true });
28+
case 'file': return request('play_single', { song_url: relpath });
3029
// TODO: Add missing Podcast
3130
// TODO: Add missing Stream
3231
default: return;
@@ -35,8 +34,8 @@ const FolderListItem = ({
3534

3635
const registerItemToCard = () => {
3736
switch(type) {
38-
case 'directory': return registerMusicToCard('play_folder', { folder: path, recursive: true });
39-
case 'file': return registerMusicToCard('play_single', { song_url: path.replace(`${DEFAULT_AUDIO_DIR}/`, '') });
37+
case 'directory': return registerMusicToCard('play_folder', { folder: relpath, recursive: true });
38+
case 'file': return registerMusicToCard('play_single', { song_url: relpath });
4039
// TODO: Add missing Podcast
4140
// TODO: Add missing Stream
4241
default: return;
@@ -50,7 +49,7 @@ const FolderListItem = ({
5049
type === 'directory'
5150
? <IconButton
5251
component={FolderLink}
53-
data={{ dir: path }}
52+
data={{ dir: relpath }}
5453
edge="end"
5554
aria-label={t('library.folders.show-folder-content')}
5655
>

src/webapp/src/components/Library/lists/folders/folder-list.js

+18-9
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,32 @@
11
import React, { memo } from 'react';
22
import { dropLast } from "ramda";
3+
import { useTranslation } from 'react-i18next';
34

4-
import { List } from '@mui/material';
5+
import {
6+
List,
7+
ListItem,
8+
Typography,
9+
} from '@mui/material';
510

611
import FolderListItem from './folder-list-item';
712
import FolderListItemBack from './folder-list-item-back';
813

9-
import { ROOT_DIRS } from '../../../../config';
14+
import { ROOT_DIR } from '../../../../config';
1015

1116
const FolderList = ({
1217
dir,
1318
folders,
1419
isSelecting,
1520
registerMusicToCard,
1621
}) => {
22+
const { t } = useTranslation();
23+
1724
const getParentDir = (dir) => {
18-
// TODO: ROOT_DIRS should be removed after paths are relative
1925
const decodedDir = decodeURIComponent(dir);
2026

21-
if (ROOT_DIRS.includes(decodedDir)) return undefined;
27+
if (decodedDir === ROOT_DIR) return undefined;
2228

23-
const parentDir = dropLast(1, decodedDir.split('/')).join('/');
29+
const parentDir = dropLast(1, decodedDir.split('/')).join('/') || ROOT_DIR;
2430
return parentDir;
2531
}
2632

@@ -29,11 +35,14 @@ const FolderList = ({
2935
return (
3036
<List sx={{ width: '100%' }}>
3137
{parentDir &&
32-
<FolderListItemBack
33-
dir={parentDir}
34-
/>
38+
<FolderListItemBack dir={parentDir} />
39+
}
40+
{folders.length === 0 &&
41+
<ListItem sx={{ justifyContent: 'center' }}>
42+
<Typography>{t('library.folders.empty-folder')}</Typography>
43+
</ListItem>
3544
}
36-
{folders.map((folder, key) =>
45+
{folders.length > 0 && folders.map((folder, key) =>
3746
<FolderListItem
3847
key={key}
3948
folder={folder}

src/webapp/src/components/Library/lists/folders/index.js

+5-4
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,15 @@ import {
1010
import request from '../../../../utils/request';
1111
import FolderList from "./folder-list";
1212

13+
import { ROOT_DIR } from '../../../../config';
14+
1315
const Folders = ({
1416
musicFilter,
1517
isSelecting,
1618
registerMusicToCard,
1719
}) => {
1820
const { t } = useTranslation();
19-
const { dir = './' } = useParams();
21+
const { dir = ROOT_DIR } = useParams();
2022
const [folders, setFolders] = useState([]);
2123
const [error, setError] = useState(null);
2224
const [isLoading, setIsLoading] = useState(true);
@@ -49,9 +51,8 @@ const Folders = ({
4951

5052
if (isLoading) return <CircularProgress />;
5153
if (error) return <Typography>{t('library.loading-error')}</Typography>;
52-
if (!filteredFolders.length) {
53-
if (musicFilter) return <Typography>{`☝️ ${t('library.folders.no-music')}`}</Typography>;
54-
return <Typography>{`${t('library.folders.empty-folder')} 🙈`}</Typography>;
54+
if (musicFilter && !filteredFolders.length) {
55+
return <Typography>{t('library.folders.no-music')}</Typography>;
5556
}
5657

5758
return (

src/webapp/src/config.js

+2-5
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,7 @@ const SUBSCRIPTIONS = [
1717
'volume.level',
1818
];
1919

20-
const DEFAULT_AUDIO_DIR = '../../shared/audiofolders';
21-
const ROOT_DIRS = ['./', DEFAULT_AUDIO_DIR];
22-
20+
const ROOT_DIR = './';
2321

2422
// TODO: The reason why thos commands are empty objects is due to a legacy
2523
// situation where titles associated with those commands were stored here
@@ -83,11 +81,10 @@ const JUKEBOX_ACTIONS_MAP = {
8381
const TIMER_STEPS = [0, 2, 5, 10, 15, 20, 30, 45, 60, 120, 180, 240];
8482

8583
export {
86-
DEFAULT_AUDIO_DIR,
8784
JUKEBOX_ACTIONS_MAP,
8885
PUBSUB_ENDPOINT,
8986
REQRES_ENDPOINT,
90-
ROOT_DIRS,
87+
ROOT_DIR,
9188
SUBSCRIPTIONS,
9289
TIMER_STEPS,
9390
}

0 commit comments

Comments
 (0)