|
|
|
@ -8,7 +8,7 @@ import AppBar, { ActiveTab as AppBarActiveTab } from './components/AppBar'; |
|
|
|
|
import ItemList from './components/ItemList'; |
|
|
|
|
import ItemListItem from './components/ItemListItem'; |
|
|
|
|
import FilterControl from './components/FilterControl'; |
|
|
|
|
import { SongQuery, toApiQuery } from './types/Query'; |
|
|
|
|
import { SongQuery, toApiQuery, isSongQuery } from './types/Query'; |
|
|
|
|
import { SongDisplayItem, ArtistDisplayItem } from './types/DisplayItem'; |
|
|
|
|
import { ReactComponent as GooglePlayIcon } from './assets/googleplaymusic_icon.svg'; |
|
|
|
|
|
|
|
|
@ -17,9 +17,11 @@ import { |
|
|
|
|
Switch, |
|
|
|
|
Route, |
|
|
|
|
useHistory, |
|
|
|
|
useLocation, |
|
|
|
|
Redirect |
|
|
|
|
} from "react-router-dom"; |
|
|
|
|
import { timeLog } from 'console'; |
|
|
|
|
|
|
|
|
|
const JSURL = require('jsurl'); |
|
|
|
|
|
|
|
|
|
interface SongItemProps { |
|
|
|
|
song: serverApi.SongDetails, |
|
|
|
@ -46,13 +48,12 @@ function SongItem(props: SongItemProps) { |
|
|
|
|
tagNames: props.song.tags && props.song.tags.map((tag: serverApi.TagDetails) => { |
|
|
|
|
return tag.name; |
|
|
|
|
}) || [], |
|
|
|
|
storeLinks: [] |
|
|
|
|
// json.storeLinks.map((url: String) => {
|
|
|
|
|
// return {
|
|
|
|
|
// icon: getStoreIcon(url),
|
|
|
|
|
// url: url
|
|
|
|
|
// }
|
|
|
|
|
// })
|
|
|
|
|
storeLinks: props.song.storeLinks && props.song.storeLinks.map((url: String) => { |
|
|
|
|
return { |
|
|
|
|
icon: getStoreIcon(url), |
|
|
|
|
url: url |
|
|
|
|
} |
|
|
|
|
}) || [], |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return <ItemListItem item={displayItem} />; |
|
|
|
@ -137,18 +138,57 @@ function ArtistList() { |
|
|
|
|
|
|
|
|
|
function AppBody() { |
|
|
|
|
const history = useHistory(); |
|
|
|
|
const [songQuery, setSongQuery] = useState<SongQuery>({ |
|
|
|
|
'titleLike': '' |
|
|
|
|
}); |
|
|
|
|
const location = useLocation(); |
|
|
|
|
const queryParams = new URLSearchParams(location.search); |
|
|
|
|
|
|
|
|
|
// If we have an invalid query, change to the default one.
|
|
|
|
|
const songQuery: SongQuery | undefined = JSURL.tryParse(queryParams.get('query'), undefined); |
|
|
|
|
|
|
|
|
|
const [songs, setSongs] = useState<serverApi.SongDetails[]>([]); |
|
|
|
|
const offset: number | undefined = queryParams.get('offset') ? parseInt(queryParams.get('offset') || '0') : undefined; |
|
|
|
|
const limit: number | undefined = queryParams.get('limit') ? parseInt(queryParams.get('limit') || '0') : undefined; |
|
|
|
|
|
|
|
|
|
React.useEffect(() => { |
|
|
|
|
const query = songQuery; |
|
|
|
|
const fixQueryParams = () => { |
|
|
|
|
var fixed = false; |
|
|
|
|
if (!isSongQuery(songQuery)) { |
|
|
|
|
console.log("query"); |
|
|
|
|
queryParams.set('query', JSURL.stringify({ |
|
|
|
|
'titleLike': '' |
|
|
|
|
})); |
|
|
|
|
fixed = true; |
|
|
|
|
} |
|
|
|
|
if (offset == undefined) { |
|
|
|
|
console.log("offset", offset); |
|
|
|
|
queryParams.set('offset', '0'); |
|
|
|
|
fixed = true; |
|
|
|
|
} |
|
|
|
|
if (limit == undefined) { |
|
|
|
|
console.log("limit"); |
|
|
|
|
queryParams.set('limit', '20'); |
|
|
|
|
fixed = true; |
|
|
|
|
} |
|
|
|
|
console.log("fixed", fixed); |
|
|
|
|
return fixed; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const pushQueryParams = () => { |
|
|
|
|
history.push({ |
|
|
|
|
search: "?" + queryParams.toString() |
|
|
|
|
}) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
useEffect(() => { |
|
|
|
|
if (fixQueryParams()) { |
|
|
|
|
pushQueryParams(); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const query: SongQuery = songQuery || { 'titleLike': '' }; |
|
|
|
|
setSongs([]); |
|
|
|
|
const request: serverApi.QuerySongsRequest = { |
|
|
|
|
query: toApiQuery(query), |
|
|
|
|
offset: 0, |
|
|
|
|
limit: 20, |
|
|
|
|
offset: offset || 0, |
|
|
|
|
limit: limit || 0, |
|
|
|
|
} |
|
|
|
|
const requestOpts = { |
|
|
|
|
method: 'POST', |
|
|
|
@ -160,7 +200,7 @@ function AppBody() { |
|
|
|
|
.then((json: any) => { |
|
|
|
|
'songs' in json && query === songQuery && setSongs(json.songs); |
|
|
|
|
}); |
|
|
|
|
}, [songQuery]); |
|
|
|
|
}, [location]); |
|
|
|
|
|
|
|
|
|
const onAppBarTabChange = (value: AppBarActiveTab) => { |
|
|
|
|
switch (value) { |
|
|
|
@ -178,12 +218,17 @@ function AppBody() { |
|
|
|
|
return ( |
|
|
|
|
<div style={{ maxWidth: '100%' }}> |
|
|
|
|
<Switch> |
|
|
|
|
<Redirect exact from='/' to='/songs' /> |
|
|
|
|
<Redirect exact from='/' to="/songs" /> |
|
|
|
|
<Route path='/songs'> |
|
|
|
|
<AppBar activeTab={AppBarActiveTab.Songs} onActiveTabChange={onAppBarTabChange} /> |
|
|
|
|
<FilterControl |
|
|
|
|
query={songQuery} |
|
|
|
|
onChangeQuery={(query: SongQuery) => { setSongQuery(query); }} |
|
|
|
|
onChangeQuery={(squery: SongQuery) => { |
|
|
|
|
if (squery != songQuery) { |
|
|
|
|
queryParams.set('query', JSURL.stringify(squery)); |
|
|
|
|
pushQueryParams(); |
|
|
|
|
} |
|
|
|
|
}} |
|
|
|
|
/> |
|
|
|
|
<Paper> |
|
|
|
|
<SongList songs={songs} /> |
|
|
|
|