Skip to content

Commit bfef840

Browse files
Pollepsjoepio
authored andcommitted
Search in current drive instead of current server
1 parent c182ba8 commit bfef840

File tree

3 files changed

+14
-8
lines changed

3 files changed

+14
-8
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,14 @@
22

33
This changelog covers all three packages, as they are (for now) updated as a whole
44

5+
## URELEASED
6+
7+
### @tomic/lib
8+
9+
#### Breaking changes
10+
11+
- `buildSearchSubject` now takes a serverURL instead of the store.
12+
513
## v0.35.0
614

715
### @tomic/browser

lib/src/search.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import { Store } from './index.js';
2-
31
export interface SearchOpts {
42
/** Fetch full resources instead of subjects */
53
include?: boolean;
@@ -53,12 +51,12 @@ function buildFilterString(filters: { [key: string]: string }): string {
5351

5452
/** Returns the URL of the search query. Fetch that and you get your results! */
5553
export function buildSearchSubject(
56-
store: Store,
54+
serverURL: string,
5755
query: string,
5856
opts: SearchOpts = {},
5957
) {
6058
const { include = false, limit = 30, scope, filters } = opts;
61-
const url = new URL(store.getServerUrl());
59+
const url = new URL(serverURL);
6260
url.pathname = 'search';
6361
query && url.searchParams.set('q', query);
6462
include && url.searchParams.set('include', include.toString());

react/src/useServerSearch.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { buildSearchSubject, SearchOpts, urls } from '@tomic/lib';
22
import { useEffect, useMemo, useState } from 'react';
3-
import { useArray, useDebounce, useResource, useStore } from './index.js';
3+
import { useArray, useDebounce, useResource, useServerURL } from './index.js';
44

55
interface SearchResults {
66
/** Subject URLs for resources that match the query */
@@ -27,13 +27,13 @@ export function useServerSearch(
2727
const { debounce = 50 } = opts;
2828

2929
const [results, setResults] = useState<string[]>([]);
30-
const store = useStore();
30+
const [serverURL] = useServerURL();
3131
// Calculating the query takes a while, so we debounce it
3232
const debouncedQuery = useDebounce(query, debounce) ?? '';
3333

3434
const searchSubjectURL: string = useMemo(
35-
() => buildSearchSubject(store, debouncedQuery, opts),
36-
[debouncedQuery, opts],
35+
() => buildSearchSubject(serverURL, debouncedQuery, opts),
36+
[debouncedQuery, opts, serverURL],
3737
);
3838

3939
const resource = useResource(searchSubjectURL, {

0 commit comments

Comments
 (0)