summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorLASER-Yi <[email protected]>2021-06-10 11:41:45 +0800
committerLASER-Yi <[email protected]>2021-06-10 11:41:45 +0800
commitc21e501ebe139fa76a4b1c6407731e0fd25997c7 (patch)
tree70030c6576224d1f71b166650b325783be12002c
parent8d447453e9f2daada8e4df4365ffad1b308a24e2 (diff)
downloadbazarr-c21e501ebe139fa76a4b1c6407731e0fd25997c7.tar.gz
bazarr-c21e501ebe139fa76a4b1c6407731e0fd25997c7.zip
Fix languages/providers filters issue in history statsv0.9.6-beta.22
-rw-r--r--bazarr/api.py22
-rw-r--r--frontend/src/History/Statistics/index.tsx17
-rw-r--r--frontend/src/apis/hooks.ts24
-rw-r--r--frontend/src/apis/index.ts1
-rw-r--r--frontend/src/apis/providers.ts4
-rw-r--r--frontend/src/apis/system.ts4
6 files changed, 57 insertions, 15 deletions
diff --git a/bazarr/api.py b/bazarr/api.py
index ba50f48e0..12b995ea3 100644
--- a/bazarr/api.py
+++ b/bazarr/api.py
@@ -54,7 +54,9 @@ from functools import wraps
api_bp = Blueprint('api', __name__, url_prefix=base_url.rstrip('/') + '/api')
api = Api(api_bp)
-None_Keys = ['null', 'undefined', '']
+None_Keys = ['null', 'undefined', '', None]
+
+False_Keys = ['False', 'false', '0']
def authenticate(actual_method):
@@ -350,10 +352,14 @@ class Languages(Resource):
@authenticate
def get(self):
history = request.args.get('history')
- if history and history not in ['False', 'false', '0']:
+ if history and history not in False_Keys:
languages = list(TableHistory.select(TableHistory.language).dicts())
languages += list(TableHistoryMovie.select(TableHistoryMovie.language).dicts())
- languages_list = list(set([x['language'].split(':')[0] for x in languages]))
+ languages_set = set()
+ for l in languages:
+ if l not in None_Keys and l['language'] not in None_Keys:
+ languages_set.add(l['language'].split(':')[0])
+ languages_list = list(languages_set)
languages_dicts = []
for language in languages_list:
code2 = None
@@ -365,7 +371,9 @@ class Languages(Resource):
if not any(x['code2'] == code2 for x in languages_dicts):
languages_dicts.append({
'code2': code2,
- 'name': language_from_alpha2(language)
+ 'name': language_from_alpha2(language),
+ # Compatibility: Use false temporarily
+ 'enabled': False
})
return jsonify(sorted(languages_dicts, key=itemgetter('name')))
result = TableSettingsLanguages.select(TableSettingsLanguages.name,
@@ -1128,7 +1136,7 @@ class Providers(Resource):
@authenticate
def get(self):
history = request.args.get('history')
- if history and history not in ['False', 'false', '0']:
+ if history and history not in False_Keys:
providers = list(TableHistory.select(TableHistory.provider)
.where(TableHistory.provider != None)
.dicts())
@@ -1139,7 +1147,9 @@ class Providers(Resource):
providers_dicts = []
for provider in providers_list:
providers_dicts.append({
- 'name': provider
+ 'name': provider,
+ 'status': 'History',
+ 'retry': '-'
})
return jsonify(data=sorted(providers_dicts, key=itemgetter('name')))
diff --git a/frontend/src/History/Statistics/index.tsx b/frontend/src/History/Statistics/index.tsx
index f8ecc986e..6616a5182 100644
--- a/frontend/src/History/Statistics/index.tsx
+++ b/frontend/src/History/Statistics/index.tsx
@@ -12,8 +12,12 @@ import {
XAxis,
YAxis,
} from "recharts";
-import { useLanguages, useSystemProviders } from "../../@redux/hooks";
-import { HistoryApi } from "../../apis";
+import {
+ HistoryApi,
+ ProvidersApi,
+ SystemApi,
+ useAsyncRequest,
+} from "../../apis";
import {
AsyncSelector,
ContentHeader,
@@ -45,9 +49,12 @@ const SelectorContainer: FunctionComponent = ({ children }) => (
);
const HistoryStats: FunctionComponent = () => {
- const [languages] = useLanguages(true);
+ const [languages] = useAsyncRequest(() => SystemApi.languages(true), []);
- const [providerList] = useSystemProviders();
+ const [providerList] = useAsyncRequest(
+ () => ProvidersApi.providers(true),
+ []
+ );
const [timeframe, setTimeframe] = useState<History.TimeframeOptions>("month");
const [action, setAction] = useState<Nullable<History.ActionOptions>>(null);
@@ -102,7 +109,7 @@ const HistoryStats: FunctionComponent = () => {
<SelectorContainer>
<LanguageSelector
clearable
- options={languages}
+ options={languages.data}
value={lang}
onChange={setLanguage}
></LanguageSelector>
diff --git a/frontend/src/apis/hooks.ts b/frontend/src/apis/hooks.ts
new file mode 100644
index 000000000..f0ee4f8a0
--- /dev/null
+++ b/frontend/src/apis/hooks.ts
@@ -0,0 +1,24 @@
+import { useCallback, useState } from "react";
+import { useDidMount } from "rooks";
+
+type RequestReturn<F extends () => Promise<any>> = PromiseType<ReturnType<F>>;
+
+export function useAsyncRequest<F extends () => Promise<any>>(
+ request: F,
+ defaultData: RequestReturn<F>
+): [AsyncState<RequestReturn<F>>, () => void] {
+ const [state, setState] = useState<AsyncState<RequestReturn<F>>>({
+ updating: true,
+ data: defaultData,
+ });
+ const update = useCallback(() => {
+ setState((s) => ({ ...s, updating: true }));
+ request()
+ .then((res) => setState({ updating: false, data: res }))
+ .catch((err) => setState((s) => ({ ...s, updating: false, err })));
+ }, [request]);
+
+ useDidMount(update);
+
+ return [state, update];
+}
diff --git a/frontend/src/apis/index.ts b/frontend/src/apis/index.ts
index f79ca6976..e6e085542 100644
--- a/frontend/src/apis/index.ts
+++ b/frontend/src/apis/index.ts
@@ -84,6 +84,7 @@ export { default as BadgesApi } from "./badges";
export { default as EpisodesApi } from "./episodes";
export { default as FilesApi } from "./files";
export { default as HistoryApi } from "./history";
+export * from "./hooks";
export { default as MoviesApi } from "./movies";
export { default as ProvidersApi } from "./providers";
export { default as SeriesApi } from "./series";
diff --git a/frontend/src/apis/providers.ts b/frontend/src/apis/providers.ts
index ffe9159d9..7e04239e7 100644
--- a/frontend/src/apis/providers.ts
+++ b/frontend/src/apis/providers.ts
@@ -5,9 +5,9 @@ class ProviderApi extends BaseApi {
super("/providers");
}
- async providers() {
+ async providers(history: boolean = false) {
return new Promise<Array<System.Provider>>((resolve, reject) => {
- this.get<DataWrapper<Array<System.Provider>>>("")
+ this.get<DataWrapper<Array<System.Provider>>>("", { history })
.then((result) => {
resolve(result.data.data);
})
diff --git a/frontend/src/apis/system.ts b/frontend/src/apis/system.ts
index 8322781fd..7bd1c6f93 100644
--- a/frontend/src/apis/system.ts
+++ b/frontend/src/apis/system.ts
@@ -57,9 +57,9 @@ class SystemApi extends BaseApi {
});
}
- async languages() {
+ async languages(history: boolean = false) {
return new Promise<Array<ApiLanguage>>((resolve, reject) => {
- this.get<Array<ApiLanguage>>("/languages")
+ this.get<Array<ApiLanguage>>("/languages", { history })
.then((result) => {
resolve(result.data);
})