|
|
@@ -14,6 +14,8 @@ import { NodeComponentProps, NodePublicState } from 'react-vtree/dist/es/Tree';
|
|
|
import { useArtistsAlbumsAndSongs } from '../../../../hooks/fetch/artists';
|
|
|
import { artistAlbumsLoaded, artistSongsLoaded } from '../actions';
|
|
|
import { CmusUIDispatchContext, CmusUIStateContext } from '../reducer';
|
|
|
+import { NoWrapFill } from '../styled/layout';
|
|
|
+import { AsciiSpinner } from '../styled/spinner';
|
|
|
import { CmusUIState } from '../types';
|
|
|
import { getScrollIndex } from '../utils/scroll';
|
|
|
|
|
|
@@ -28,6 +30,7 @@ type TreeNode = {
|
|
|
id: string;
|
|
|
focused: boolean;
|
|
|
active: boolean;
|
|
|
+ loading?: boolean;
|
|
|
shouldBeOpen?: boolean;
|
|
|
children?: TreeNode[];
|
|
|
};
|
|
|
@@ -53,6 +56,7 @@ function useTreeWalker(
|
|
|
focused,
|
|
|
active: activeArtist === artist && activeAlbum === null,
|
|
|
shouldBeOpen: expandedArtists.includes(artist),
|
|
|
+ loading: !(artist in artistAlbums),
|
|
|
children:
|
|
|
artistAlbums[artist]?.map<TreeNode>((album) => ({
|
|
|
name: album,
|
|
|
@@ -73,6 +77,7 @@ function useTreeWalker(
|
|
|
active: node.active,
|
|
|
shouldBeOpen: node.shouldBeOpen,
|
|
|
isOpenByDefault: !!node.shouldBeOpen,
|
|
|
+ loading: node.loading,
|
|
|
isArtist,
|
|
|
},
|
|
|
node,
|
|
|
@@ -105,7 +110,7 @@ function useTreeWalker(
|
|
|
}
|
|
|
|
|
|
const Node: React.FC<NodeComponentProps<TreeData, NodePublicState<TreeData>>> = ({
|
|
|
- data: { name, isArtist, focused, active, shouldBeOpen },
|
|
|
+ data: { name, isArtist, focused, active, shouldBeOpen, loading },
|
|
|
isOpen,
|
|
|
setOpen,
|
|
|
style,
|
|
|
@@ -119,14 +124,15 @@ const Node: React.FC<NodeComponentProps<TreeData, NodePublicState<TreeData>>> =
|
|
|
if (isArtist) {
|
|
|
return (
|
|
|
<Styled.ArtistTitle active={active} parentActive={focused} style={style as CSSProperties}>
|
|
|
- <span>{name || 'Unknown Artist'}</span>
|
|
|
+ {loading && shouldBeOpen ? <AsciiSpinner /> : <> </>}
|
|
|
+ <NoWrapFill>{name || 'Unknown Artist'}</NoWrapFill>
|
|
|
</Styled.ArtistTitle>
|
|
|
);
|
|
|
}
|
|
|
|
|
|
return (
|
|
|
<Styled.AlbumTitle active={active} parentActive={focused} style={style as CSSProperties}>
|
|
|
- <span>{name || 'Unknown Album'}</span>
|
|
|
+ <NoWrapFill>{name || 'Unknown Album'}</NoWrapFill>
|
|
|
</Styled.AlbumTitle>
|
|
|
);
|
|
|
};
|