fix ([data-bind=backend-enabled]): remove quickfix and fix root cause of cf83f7507c

This commit is contained in:
MickaelK
2024-01-30 17:37:05 +11:00
parent 410e638f19
commit 029f5efc82
3 changed files with 8 additions and 4 deletions
@@ -12,7 +12,10 @@ const backendsEnabled$ = new rxjs.BehaviorSubject();
export async function initStorage() {
return await getConfig().pipe(
rxjs.map(({ connections }) => connections),
rxjs.tap((connections) => backendsEnabled$.next(Array.isArray(connections) ? connections : [])),
rxjs.tap((connections) => {
if (backendsEnabled$.value !== undefined) return;
backendsEnabled$.next(Array.isArray(connections) ? connections : [])
}),
).toPromise();
}
@@ -7,7 +7,6 @@ import { isAdmin$ } from "./model_admin_session.js";
export default function AdminOnly(ctrlWrapped) {
return (render) => {
effect(isAdmin$().pipe(
rxjs.distinctUntilChanged(),
rxjs.map((isAdmin) => isAdmin ? ctrlWrapped : ctrlLogin),
rxjs.tap((ctrl) => ctrl(render)),
rxjs.catchError(ctrlError(render)),
@@ -9,9 +9,11 @@ const adminSession$ = rxjs.merge(
rxjs.startWith(null),
rxjs.mergeMap(() => ajax({ url: "/admin/api/session", responseType: "json" })),
rxjs.map(({ responseJSON }) => responseJSON.result),
rxjs.distinctUntilChanged(),
)
).pipe(rxjs.shareReplay(1));
).pipe(
rxjs.distinctUntilChanged(),
rxjs.shareReplay(1)
);
export function isAdmin$() {
return adminSession$;