on main help sign in
more search fixes, and rudimentary frontend search
commit9ea2d6fde5284b9c98e3323f7c6a71ae635d82a7 authorJohn Hyde <johnhydefour@gmail.com> dateTue 7 Jun 2022, 22:08 (4 years ago) parent2904f2a
10 files changed+163−108
desk/app/astrolabe.hoon+28−17 desk/lib/astrolabe.hoon+32−10 ui/src/components/SearchResults.svelte+52−38 ui/src/components/ShipView.svelte+3−5 ui/src/lib/api.ts+29−1 ui/src/routes/ShipViewPage.svelte+4−1 ui/src/stores/docs.ts+9−5 ui/src/stores/store.ts+2−30 ui/src/styles/tailwind-output.css+4 ui/src/types/store.ts−1
desk/app/astrolabe.hoon+28−17
@@ -136,6 +136,12 @@
136136++ on-naive-diff
137137 |= =diff:naive
138138 ^- (quip card _state)
139+ ~& %+ weld "received diff:naive: {<-.diff>}"
140+ ?+ -.diff ""
141+ %nonce " ship: {<ship.diff>}"
142+ %tx " from: {<ship.from.tx.raw-tx.diff>} - {<+<.tx.raw-tx.diff>}"
143+ %point " ship: {<ship.diff>} - {<+>-.diff>}"
144+ ==
139145 =? state ?=([%tx [* * * %spawn ship *] *] diff)
140146 %- put-in-opoints
141147 ship.tx.raw-tx.diff
@@ -201,35 +207,37 @@
201207++ run-wildcard-search
202208 |* [agg=mold search=search-full points=opoints =page-info]
203209 |= f=$-([agg @q] agg)
204− ^- agg
210+ ^- [count=@ =agg]
205211 =/ s-syls search-syls.search
206212 ~& s-syls
207213 =/ s-opts search-opts.search
208− =| =agg
214+ =| res=[count=@ =agg]
209215 =+ [llb=.~zod rrb=`@q`(sub (bex 32) 1)]
210− =| agg-count=@
216+ :: =< +
211217 |-
212− ^- _agg
218+ ^- _res
213219 ?~ points
214220 :: ~& "nothing here, going up"
215− agg
221+ res
222+ ?: (gth count.res 1.000) ~|(%search-too-broad !!)
216223 =/ n=@q `@`-.n.points
217224 =/ lrb=@q ?: (gth n 0) (sub-d n 1) .~zod
218225 =/ rlb=@q (add-d n 1)
219226 =/ left-view (range-contains-search llb lrb s-opts)
220227 :: ~& "arrived at {<n>}"
221− :: ~& "left side: {<?:(contains.left-view 'Y' 'N')>} {<llb>} - {<lrb>} contains {<s-opts>}"
228+ :: ~& "left side: {<?:(contains.left-view 'Y' 'N')>} {<llb>} - {<lrb>}"
222229 =/ right-view (range-contains-search rlb rrb s-opts)
223− =? agg contains.left-view
230+ =? res contains.left-view
224231 $(points l.points, rrb lrb, s-opts opts.left-view)
225− =? agg (matches-search s-syls n)
226− =/ fits (fits-on-page agg-count page-info)
227− =. agg-count +(agg-count)
228− ?: fits (f agg n) agg
229− :: ~& "right side: {<?:(contains.right-view 'Y' 'N')>} {<rlb>} - {<rrb>} contains {<s-opts>}"
230− =? agg contains.right-view
232+ =? res (matches-search s-syls n)
233+ =/ fits (fits-on-page count.res page-info)
234+ =. count.res +(count.res)
235+ =? agg.res fits (f agg.res n)
236+ res
237+ :: ~& "right side: {<?:(contains.right-view 'Y' 'N')>} {<rlb>} - {<rrb>}"
238+ =? res contains.right-view
231239 $(points r.points, llb rlb, s-opts opts.right-view)
232− agg
240+ res
233241::
234242++ search-opoints
235243 |= =search-text
@@ -237,15 +245,18 @@
237245 =/ =search-full (search-text-to-search-full search-text)
238246 =^ spoints search-full
239247 (maybe-reverse-search search-full fopoints ropoints)
248+ ?: (gth pain.spoints 2.820) ~|(%search-predicted-too-broad !!)
240249 =/ results
241250 %-
242251 (run-wildcard-search (list @q) search-full points.spoints *page-info)
243252 |= [agg=(list @q) result=@q]
244253 [result agg]
245− =? results reversed.spoints
246− (turn results switch-words)
254+ ~& "returning {<(lent agg.results)>} of {<count.results>} results"
255+ =/ ships agg.results
256+ =? ships reversed.spoints
257+ (turn ships switch-words)
247258 %- flop
248− (turn results to-p)
259+ (turn ships to-p)
249260::
250261++ sponsor-chain
251262 |= [=ship =unpoint]
desk/lib/astrolabe.hoon+32−10
@@ -109,10 +109,17 @@
109109 %+ weld
110110 (slag 2 lst)
111111 (scag 2 lst)
112+++ pad-search-syls
113+ |= =search-syls
114+ ^- ^search-syls
115+ =/ padding (search-text-to-search-syls "dozzoddozzod")
116+ %+ weld
117+ search-syls
118+ (slag (lent search-syls) padding)
112119++ reverse-search
113120 |= search=search-full
114121 ^- search-full
115− :- (reverse-list search-syls.search)
122+ :- (reverse-list (pad-search-syls search-syls.search))
116123 (reverse-list search-opts.search)
117124++ estimate-search-pain
118125 |= search=search-full
@@ -123,15 +130,29 @@
123130 =/ new-acc
124131 (add (mul acc 2) (lent i.opts))
125132 $(acc new-acc, opts t.opts)
133+:: ++ estimate-search-pain
134+:: |= search=search-full
135+:: =/ max-pain (bex 32)
136+:: =/ opts search-opts.search
137+:: =| acc=@
138+:: |-
139+:: ?~ opts acc
140+:: =/ level-pain (div (mul max-pain (lent i.opts)) 256)
141+:: =/ new-acc
142+:: (add (mul acc 2) (lent i.opts))
143+:: $(acc new-acc, opts t.opts)
144+++ estimate-search-text-pain
145+ |= =search-text
146+ (estimate-search-pain (search-text-to-search-full search-text))
126147++ maybe-reverse-search
127148 |= [search=search-full fopoints=opoints ropoints=opoints]
128− ^- [[points=opoints reversed=?] search-full]
149+ ^- [[points=opoints reversed=? pain=@] =search-full]
129150 =/ search-pain (estimate-search-pain search)
130151 =/ rsearch (reverse-search search)
131152 =/ rsearch-pain (estimate-search-pain rsearch)
132153 ?: (gth search-pain rsearch-pain)
133− [[ropoints %.y] rsearch]
134− [[fopoints %.n] search]
154+ [[ropoints %.y rsearch-pain] rsearch]
155+ [[fopoints %.n search-pain] search]
135156++ tape-matches
136157 |= [search=tape cand=tape]
137158 ^- ?
@@ -149,14 +170,15 @@
149170++ matches-search
150171 |= [search=search-syls cand-atom=@]
151172 =/ cand (rip 3 cand-atom)
152− =? cand =(cand ~)
153− (limo ~[0])
154173 |-
155174 ^- ?
156− ?~ search =(~ cand)
157− ?~ cand %.n
158− ?: (syl-matches i.search i.cand)
159− $(search t.search, cand t.cand)
175+ ?~ search =(cand ~)
176+ :: =? cand =(cand ~)
177+ :: `(lest @)`~[0]
178+ =/ nncand ^- (lest @)
179+ ?~ cand ~[0] cand
180+ ?: (syl-matches i.search i.nncand)
181+ $(search t.search, cand t.nncand)
160182 %.n
161183::
162184++ opts-in-range
ui/src/components/SearchResults.svelte+52−38
@@ -1,42 +1,45 @@
11<script lang="ts">
22 import { Groups, Rolodex } from '@urbit/api';
3+ import { searchPoints } from '../lib/api';
34 import store from '../stores/store';
45 import ShipListing from './ShipListing.svelte';
56 import SearchResultNavButtons from './SearchResultNavButtons.svelte';
67 import ShipView from './ShipView.svelte';
7− export let searchQuery: RegExp;
8− export let patp: string;
8+ export let query: RegExp;
9+ export let search: string;
10+ // export let patp: string;
911 let contactsList = [];
1012 let selectedShipIndex: number;
1113
12− $: {
13− if (!patp) {
14− store.search(searchQuery)
15− }
16− // if (searchQuery) {
17− // store.search(searchQuery)
18− // } else {
19− // store.reset();
20− // }
21− }
22− $: {
23− contactsList = Object.entries($store?.contacts).map(([patp, ship]) => {
24− return {
25− ...ship,
26− patp,
27− };
28− });
29− if (contactsList.length === 1) {
30− selectedShipIndex = 0;
31− } else {
32− selectedShipIndex = null;
33− }
34− }
35− $: selectedShip = contactsList[selectedShipIndex]
14+ $: searchedPointsP = searchPoints(search)
15+ // $: {
16+ // // if (!patp) {
17+ // store.search(query)
18+ // // }
19+ // // if (searchQuery) {
20+ // // store.search(searchQuery)
21+ // // } else {
22+ // // store.reset();
23+ // // }
24+ // }
25+ // $: {
26+ // contactsList = Object.entries($store?.contacts).map(([patp, ship]) => {
27+ // return {
28+ // ...ship,
29+ // patp,
30+ // };
31+ // });
32+ // if (contactsList.length === 1) {
33+ // selectedShipIndex = 0;
34+ // } else {
35+ // selectedShipIndex = null;
36+ // }
37+ // }
38+ // $: selectedShip = contactsList[selectedShipIndex]
3639
37− function updateIndex(e) {
38− selectedShipIndex = e.detail.index;
39− }
40+ // function updateIndex(e) {
41+ // selectedShipIndex = e.detail.index;
42+ // }
4043</script>
4144
4245<!-- should actually switch on whether field is empty -->
@@ -46,7 +49,7 @@
4649 Hello, ~{window.ship}, would you like to search?
4750 </p>
4851{/if} -->
49−{#if patp}
52+<!-- {#if patp}
5053 <ShipView {patp} />
5154{:else if selectedShip}
5255 {#if contactsList.length > 1}
@@ -57,12 +60,23 @@
5760 />
5861 {/if}
5962 <ShipView patp={selectedShip.patp} />
60−{:else}
61− <div class="flex justify-center">
62− <div class="max-w-md w-full rounded-lg bg-white">
63− {#each contactsList as contact, i (contact.patp)}
64− <ShipListing ship={contact} on:click={() => selectedShipIndex = i}/>
65− {/each}
66− </div>
63+{:else} -->
64+{query}
65+{search}
66+{#await searchedPointsP}
67+Loading...
68+{:then { points }}
69+ <div class="max-w-md w-full rounded-lg bg-white">
70+ <!-- {#each contactsList as contact, i (contact.patp)}
71+ <ShipListing ship={contact} on:click={() => selectedShipIndex = i}/>
72+ {/each} -->
73+ {#each points as patp, i (patp)}
74+ <ShipListing ship={{ patp }} linkToShip />
75+ {/each}
6776 </div>
68−{/if}
77+{:catch}
78+ <div class="max-w-md w-full rounded-lg bg-white">
79+ Search Too Broad
80+ </div>
81+{/await}
82+<!-- {/if} -->
ui/src/components/ShipView.svelte+3−5
@@ -1,9 +1,8 @@
11<script lang="ts">
2− import UrbitApi from '@urbit/http-api';
32 import { clan, sein, patp2dec } from 'urbit-ob';
43
54 import { cite, normalizeId } from '../lib/id';
6− import tooltip from "../actions/tooltip";
5+ import { getPoint, getSpawnedPoints } from '../lib/api';
76 import Sigil from "./Sigil.svelte";
87 import GoldBadge from './GoldBadge.svelte';
98 import TooltipAndDocLink from "./TooltipAndDocLink.svelte";
@@ -23,7 +22,6 @@
2322 let rawSpawnedPointsPromise: any;
2423 let rawSpawnedPoints: any = null;
2524 let spawnedPoints: string[] = [];
26− const api: UrbitApi = new UrbitApi('');
2725 const spawnStatusOptions = {
2826 unspawned: {
2927 text: 'unspawned',
@@ -83,7 +81,7 @@
8381 $: {
8482 rawPointInfo = null;
8583 if (azPoint) {
86− rawPointInfoPromise = api.scry<any>({ app: 'astrolabe', path: `/point/${patp}` });
84+ rawPointInfoPromise = getPoint(patp);
8785 rawPointInfoPromise.then((info) => {
8886 rawPointInfo = info;
8987 }).catch((error) => {
@@ -94,7 +92,7 @@
9492 $: {
9593 rawSpawnedPoints = null;
9694 if (canSpawnPoints) {
97− rawSpawnedPointsPromise = api.scry<any>({ app: 'astrolabe', path: `/point/${patp}/spawned` });
95+ rawSpawnedPointsPromise = getSpawnedPoints(patp);
9896 rawSpawnedPointsPromise.then((info) => {
9997 rawSpawnedPoints = info;
10098 }).catch((error) => {
ui/src/lib/api.ts+29−1
@@ -1,4 +1,32 @@
11import UrbitApi from '@urbit/http-api';
2+console.log(`Initializing Urbit API at ${Date()}`);
23const api: UrbitApi = new UrbitApi('');
34
4−export default api;
5+function scry<T = any>(path: string): Promise<T> {
6+ return api.scry<T>({ app: 'astrolabe', path });
7+}
8+
9+function getPoint(patp: string): Promise<any> {
10+ return scry<any>(`/point/${patp}`);
11+}
12+
13+function getSpawnedPoints(patp: string): Promise<any> {
14+ return scry<any>(`/point/${patp}/spawned`);
15+}
16+
17+function searchPoints(search: string): Promise<any> {
18+ return scry<any>(`/search/${search}`);
19+}
20+
21+function getDoc(path: string): Promise<string> {
22+ return scry<string>(`/doc/${path}`);
23+}
24+
25+export {
26+ api,
27+ scry,
28+ getPoint,
29+ getSpawnedPoints,
30+ searchPoints,
31+ getDoc,
32+};
ui/src/routes/ShipViewPage.svelte+4−1
@@ -4,6 +4,7 @@
44 import { SearchAnalysis } from '../lib/id';
55 import { linkToShip } from '../lib/link';
66 import SearchBar from "../components/SearchBar.svelte";
7+ import SearchResults from "../components/SearchResults.svelte";
78 import ShipView from '../components/ShipView.svelte';
89 import ValidationProblems from '../components/ValidationProblems.svelte';
910 import HomeScreenTiles from '../components/HomeScreenTiles.svelte';
@@ -44,8 +45,10 @@
4445 <SearchBar bind:analysis bind:search />
4546 {#if analysis.patpIsValid}
4647 <ShipView patp={analysis.patp} />
48+ {:else if (analysis.queryIsValid)}
49+ <SearchResults query={analysis.query} search={analysis.search} />
4750 {:else if (analysis.search.length > 0)}
48− <ValidationProblems problems={analysis.patpProblems} />
51+ <ValidationProblems problems={analysis.queryProblems} />
4952 {:else}
5053 <HomeScreenTiles />
5154 {/if}
ui/src/stores/docs.ts+9−5
@@ -1,6 +1,6 @@
11import { writable } from 'svelte/store';
22
3−import api from '../lib/api';
3+import { getDoc } from '../lib/api';
44const docs = {};
55// import type { AppState, Contacts } from '../types/store';
66
@@ -12,11 +12,11 @@ const initStore: any = {
1212const store = writable(initStore);
1313const { subscribe, update, set } = store;
1414
15−async function getDoc(path): Promise<string> {
15+async function getCachedDoc(path): Promise<string> {
1616 if (docs[path]) {
1717 return docs[path];
1818 } else {
19− const doc = await api.scry<string>({ app: 'astrolabe', path: `/doc/${path}` });
19+ const doc = await getDoc(path);
2020 docs[path] = doc;
2121 return doc;
2222 }
@@ -37,5 +37,9 @@ function hide() {
3737 }));
3838}
3939
40−
41−export default { subscribe, getDoc, show, hide };
40+export default {
41+ subscribe,
42+ getDoc: getCachedDoc,
43+ show,
44+ hide
45+};
ui/src/stores/store.ts+2−30
@@ -1,6 +1,6 @@
11import { writable } from 'svelte/store';
22
3−import api from '../lib/api';
3+import { api } from '../lib/api';
44import type { StoreState, Contacts } from '../types/store';
55import { filterObject } from '../lib/utils';
66import fakeContacts from '../fake_data/fake-contacts';
@@ -11,7 +11,6 @@ const initStore: StoreState = {
1111 contacts: {},
1212 connection: 'disconnected',
1313 ship: window.ship,
14− docs: {},
1514};
1615
1716const store = writable(initStore);
@@ -40,32 +39,5 @@ function reset() {
4039 set(initStore);
4140}
4241
43−function getDoc(path) {
44− return new Promise((resolve, reject) => {
45− const unsubscribe = subscribe(async ({ docs }) => {
46− try {
47− if (docs[path]) {
48− resolve(docs[path]);
49− } else {
50− const doc = await api.scry<string>({ app: 'astrolabe', path: `/doc/${path}` });
51− update(($store: StoreState): StoreState => {
52− return {
53− ...$store,
54− docs: {
55− ...$store.docs,
56− [path]: doc,
57− },
58− }
59− });
60− resolve(doc);
61− }
62− } catch (error) {
63− reject(error);
64− }
65− });
66− unsubscribe();
67− });
68−}
69−
7042
71−export default { subscribe, search, reset, getDoc };
43+export default { subscribe, search, reset };
ui/src/styles/tailwind-output.css+4
@@ -1106,6 +1106,10 @@ Ensure the default browser behavior of the `hidden` attribute.
11061106 max-width: 42rem;
11071107 }
11081108
1109+ .md\:max-w-lg {
1110+ max-width: 32rem;
1111+ }
1112+
11091113 .md\:flex-row {
11101114 flex-direction: row;
11111115 }
ui/src/types/store.ts−1
@@ -17,5 +17,4 @@ export interface StoreState {
1717 connection: ConnectionStatus;
1818 subscription?: unknown;
1919 ship: Patp;
20− docs: Docs;
2120}