Convert Search page to functional component (#6268)

This commit is contained in:
Tom Moor
2023-12-09 21:54:39 -05:00
committed by GitHub
parent 3f3d7b4978
commit 5dfa6a6011
7 changed files with 224 additions and 376 deletions

View File

@@ -43,9 +43,6 @@ export default class DocumentsStore extends Store<Document> {
{ sharedTree: NavigationNode; team: PublicTeam } | undefined
> = new Map();
@observable
searchCache: Map<string, SearchResult[] | undefined> = new Map();
@observable
backlinks: Map<string, string[]> = new Map();
@@ -173,10 +170,6 @@ export default class DocumentsStore extends Store<Document> {
return naturalSort(this.inCollection(collectionId), "title");
}
searchResults(query: string): SearchResult[] | undefined {
return this.searchCache.get(query);
}
@computed
get archived(): Document[] {
return orderBy(this.orderedData, "archivedAt", "desc").filter(
@@ -367,7 +360,10 @@ export default class DocumentsStore extends Store<Document> {
this.fetchNamedPage("list", options);
@action
searchTitles = async (query: string, options?: SearchParams) => {
searchTitles = async (
query: string,
options?: SearchParams
): Promise<SearchResult[]> => {
const compactedOptions = omitBy(options, (o) => !o);
const res = await client.post("/documents.search_titles", {
...compactedOptions,
@@ -388,15 +384,12 @@ export default class DocumentsStore extends Store<Document> {
return null;
}
return {
id: document.id,
document,
};
})
);
const existing = this.searchCache.get(query) || [];
// splice modifies any existing results, taking into account pagination
existing.splice(0, existing.length, ...results);
this.searchCache.set(query, existing);
return res.data;
return results;
};
@action
@@ -431,11 +424,7 @@ export default class DocumentsStore extends Store<Document> {
};
})
);
const existing = this.searchCache.get(query) || [];
// splice modifies any existing results, taking into account pagination
existing.splice(options.offset || 0, options.limit || 0, ...results);
this.searchCache.set(query, existing);
return res.data;
return results;
};
@action