fix: Load relationships on search page load (#6295)

This commit is contained in:
Tom Moor
2023-12-16 10:36:19 -05:00
committed by GitHub
parent ab7515b0e1
commit 7df0f63ce6
4 changed files with 45 additions and 29 deletions

View File

@@ -11,7 +11,6 @@ import {
} from "@shared/types";
import Collection from "~/models/Collection";
import { client } from "~/utils/ApiClient";
import { AuthorizationError, NotFoundError } from "~/utils/errors";
import RootStore from "./RootStore";
import Store from "./base/Store";
@@ -164,32 +163,10 @@ export default class CollectionsStore extends Store<Collection> {
}
@action
async fetch(
id: string,
options: Record<string, any> = {}
): Promise<Collection> {
const item = this.get(id) || this.getByUrl(id);
if (item && !options.force) {
return item;
}
this.isFetching = true;
try {
const res = await client.post(`/collections.info`, {
id,
});
invariant(res?.data, "Collection not available");
this.addPolicies(res.policies);
return this.add(res.data);
} catch (err) {
if (err instanceof AuthorizationError || err instanceof NotFoundError) {
this.remove(id);
}
throw err;
} finally {
this.isFetching = false;
}
async fetch(id: string, options?: { force: boolean }): Promise<Collection> {
const model = await super.fetch(id, options);
await model.fetchDocuments(options);
return model;
}
@computed