@@ -1,45 +1,65 @@
1<script lang="ts">
1<script lang="ts">
2− import { Groups, Rolodex } from '@urbit/api';
3+ import type { Patp, Rolodex } from '@urbit/api';
3 import { searchPoints } from '../lib/api';
4 import { searchPoints } from '../lib/api';
4 import store from '../stores/store';
5 import store from '../stores/store';
5− import ShipListing from './ShipListing.svelte';
6+ import ShipListings from './ShipListings.svelte';
6− import SearchResultNavButtons from './SearchResultNavButtons.svelte';
7+
7− import ShipView from './ShipView.svelte';
8 export let query: RegExp;
8 export let query: RegExp;
9 export let search: string;
9 export let search: string;
10 // export let patp: string;
10 // export let patp: string;
11− let contactsList = [];
11+ let combinedSearchResults = [];
12+ let searchedPoints: Patp[] = [];
12 let selectedShipIndex: number;
13 let selectedShipIndex: number;
14 $: searchedPointsP = searchPoints(search)
15 $: searchedPointsP = searchPoints(search)
17+ searchedPointsP.then((points) => {
18+ searchedPoints = points;
16− // // if (!patp) {
23+ // if (!patp) {
17− // store.search(query)
24+ store.search(query)
19− // // if (searchQuery) {
26+ // if (searchQuery) {
20− // // store.search(searchQuery)
27+ // store.search(searchQuery)
21− // // } else {
28+ // } else {
22− // // store.reset();
29+ // store.reset();
33+ const contactSearchResults = JSON.parse(JSON.stringify($store.contactSearchResults));
35+ const nonContacts = [];
36+ searchedPoints.forEach(patp => {
37+ const contact = contactSearchResults[patp];
39+ contacts.push({ ...contact, patp });
40+ delete contactSearchResults[patp];
42+ nonContacts.push({ patp });
26− // contactsList = Object.entries($store?.contacts).map(([patp, ship]) => {
45+ const nonAzimuthContacts = Object.entries(contactSearchResults).map(([patp, ship]) => {
27− // return {
46+ return {
28− // ...ship,
47+ ...ship,
32− // if (contactsList.length === 1) {
51+ combinedSearchResults = [...contacts, ...nonAzimuthContacts, ...nonContacts];
52+ if (combinedSearchResults.length === 1) {
33− // selectedShipIndex = 0;
53+ selectedShipIndex = 0;
34− // } else {
54+ } else {
35− // selectedShipIndex = null;
55+ selectedShipIndex = null;
38− // $: selectedShip = contactsList[selectedShipIndex]
58+ $: selectedShip = combinedSearchResults[selectedShipIndex]
40− // function updateIndex(e) {
60+ function updateIndex(e) {
41− // selectedShipIndex = e.detail.index;
61+ selectedShipIndex = e.detail.index;
45<!-- should actually switch on whether field is empty -->
65<!-- should actually switch on whether field is empty -->
@@ -51,32 +71,36 @@
52<!-- {#if patp}
72<!-- {#if patp}
53 <ShipView {patp} />
73 <ShipView {patp} />
54−{:else if selectedShip}
74+{:else if selectedShip}-->
55− {#if contactsList.length > 1}
75+ <!-- {#if contactsList.length > 1}
56 <SearchResultNavButtons
76 <SearchResultNavButtons
57 index={selectedShipIndex}
77 index={selectedShipIndex}
58 totalResults={contactsList.length}
78 totalResults={contactsList.length}
59 on:updateIndex={updateIndex}
79 on:updateIndex={updateIndex}
62− <ShipView patp={selectedShip.patp} />
82+<!-- <ShipView patp={selectedShip.patp} />
63{:else} -->
83{:else} -->
64−{query}
84+<div class="max-w-md w-full rounded-lg bg-white overflow-hidden">
66−{#await searchedPointsP}
85+ {#await searchedPointsP}
67−Loading...
86+ <p class="p-8 text-center">
68−{:then { points }}
87+ Searching all spawned points...
69− <div class="max-w-md w-full rounded-lg bg-white">
88+ </p>
70− <!-- {#each contactsList as contact, i (contact.patp)}
89+ {:catch}
90+ <p class="p-8 text-center">
91+ Your search is too broad, please be more specific.
94+ {#if combinedSearchResults.length === 0}
95+ <p class="p-8 text-center">
96+ No spawned ships match your search.
100+ ships={combinedSearchResults}
71− <ShipListing ship={contact} on:click={() => selectedShipIndex = i}/>
101+ on:click={({ detail: i }) => selectedShipIndex = i}
72− {/each} -->
102+ linkToShips differentiateContacts
73− {#each points as patp, i (patp)}
103+ />
74− <ShipListing ship={{ patp }} linkToShip />
104+ {/if}
78− <div class="max-w-md w-full rounded-lg bg-white">
82−<!-- {/if} -->
106+ <!-- {/if} -->