|
|
|
@ -1,24 +1,13 @@ |
|
|
|
|
import React, { useEffect, useReducer } from 'react'; |
|
|
|
|
import { createMuiTheme, Box, LinearProgress } from '@material-ui/core'; |
|
|
|
|
import { QueryElem, toApiQuery, QueryLeafBy, QueryLeafOp } from '../../../lib/query/Query'; |
|
|
|
|
import React, { useEffect, useReducer, useCallback } from 'react'; |
|
|
|
|
import { Box, LinearProgress } from '@material-ui/core'; |
|
|
|
|
import { QueryElem, QueryLeafBy, QueryLeafOp } from '../../../lib/query/Query'; |
|
|
|
|
import QueryBuilder from '../../querybuilder/QueryBuilder'; |
|
|
|
|
import * as serverApi from '../../../api'; |
|
|
|
|
import SongTable from '../../tables/ResultsTable'; |
|
|
|
|
import { songGetters } from '../../../lib/songGetters'; |
|
|
|
|
import { queryArtists, querySongs, queryAlbums, queryTags } from '../../../lib/backend/queries'; |
|
|
|
|
import { grey } from '@material-ui/core/colors'; |
|
|
|
|
import { WindowState } from '../Windows'; |
|
|
|
|
var _ = require('lodash'); |
|
|
|
|
|
|
|
|
|
const darkTheme = createMuiTheme({ |
|
|
|
|
palette: { |
|
|
|
|
type: 'dark', |
|
|
|
|
primary: { |
|
|
|
|
main: grey[100], |
|
|
|
|
} |
|
|
|
|
}, |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
export interface ResultsForQuery { |
|
|
|
|
for: QueryElem, |
|
|
|
|
results: any[], |
|
|
|
@ -112,23 +101,23 @@ export function QueryWindowControlled(props: { |
|
|
|
|
state: QueryWindowState, |
|
|
|
|
dispatch: (action: any) => void, |
|
|
|
|
}) { |
|
|
|
|
let query = props.state.query; |
|
|
|
|
let editing = props.state.editingQuery; |
|
|
|
|
let resultsFor = props.state.resultsForQuery; |
|
|
|
|
let { query, editingQuery: editing, resultsForQuery: resultsFor } = props.state; |
|
|
|
|
let { dispatch } = props; |
|
|
|
|
|
|
|
|
|
let setQuery = (q: QueryElem | null) => { |
|
|
|
|
props.dispatch({ type: QueryWindowStateActions.SetQuery, value: q }); |
|
|
|
|
} |
|
|
|
|
let setEditingQuery = (e: boolean) => { |
|
|
|
|
props.dispatch({ type: QueryWindowStateActions.SetEditingQuery, value: e }); |
|
|
|
|
} |
|
|
|
|
let setResultsForQuery = (r: ResultsForQuery | null) => { |
|
|
|
|
props.dispatch({ type: QueryWindowStateActions.SetResultsForQuery, value: r }); |
|
|
|
|
} |
|
|
|
|
let setResultsForQuery = useCallback((r: ResultsForQuery | null) => { |
|
|
|
|
dispatch({ type: QueryWindowStateActions.SetResultsForQuery, value: r }); |
|
|
|
|
}, [ dispatch ]); |
|
|
|
|
|
|
|
|
|
const loading = query && (!resultsFor || !_.isEqual(resultsFor.for, query)); |
|
|
|
|
const showResults = (query && resultsFor && query == resultsFor.for) ? resultsFor.results : []; |
|
|
|
|
const showResults = (query && resultsFor && query === resultsFor.for) ? resultsFor.results : []; |
|
|
|
|
|
|
|
|
|
const doQuery = async (_query: QueryElem) => { |
|
|
|
|
const doQuery = useCallback(async (_query: QueryElem) => { |
|
|
|
|
const songs = await querySongs({ |
|
|
|
|
query: _query, |
|
|
|
|
offset: 0, |
|
|
|
@ -141,7 +130,7 @@ export function QueryWindowControlled(props: { |
|
|
|
|
results: songs, |
|
|
|
|
}) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
}, [query, setResultsForQuery]); |
|
|
|
|
|
|
|
|
|
useEffect(() => { |
|
|
|
|
if (query) { |
|
|
|
@ -149,7 +138,7 @@ export function QueryWindowControlled(props: { |
|
|
|
|
} else { |
|
|
|
|
setResultsForQuery(null); |
|
|
|
|
} |
|
|
|
|
}, [query]); |
|
|
|
|
}, [query, doQuery, setResultsForQuery]); |
|
|
|
|
|
|
|
|
|
return <Box width="100%" justifyContent="center" display="flex" flexWrap="wrap"> |
|
|
|
|
<Box |
|
|
|
|