Skip to content

Commit 964203e

Browse files
committed
Basic search working
1 parent 30102fe commit 964203e

File tree

5 files changed

+153
-18
lines changed

5 files changed

+153
-18
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ _Note: this extension is beta and not yet available in the Raycast store_
99
## Running locally
1010

1111
```sh
12+
# make sure you have Raycast and Yarn / NPM installed
1213
yarn
14+
# Start local server
1315
yarn dev
16+
# Now open raycast. The dev tool should be the top item!
1417
```

assets/android-chrome-512x512.png

22.5 KB
Loading

package.json

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,24 @@
11
{
22
"$schema": "https://www.raycast.com/schemas/extension.json",
33
"name": "atomic",
4-
"title": "atomic",
4+
"title": "Atomic Data",
55
"description": "Search inside your Atomic-Server data",
66
"icon": "command-icon.png",
77
"author": "joepio",
88
"license": "MIT",
99
"commands": [
1010
{
1111
"name": "index",
12-
"title": "Show List and Detail",
13-
"description": "Template for showing a static list and a detail view",
12+
"title": "Search Atomic Data resources",
13+
"description": "Search inside your Atomic-Server data",
1414
"mode": "view"
1515
}
1616
],
1717
"dependencies": {
18-
"@raycast/api": "^1.26.3"
18+
"@raycast/api": "^1.26.3",
19+
"@tomic/lib": "^0.30.1",
20+
"@tomic/react": "^0.30.2",
21+
"node-fetch": "^3.1.0"
1922
},
2023
"devDependencies": {
2124
"@types/node": "~16.10.0",
@@ -32,4 +35,4 @@
3235
"dev": "ray develop",
3336
"lint": "ray lint"
3437
}
35-
}
38+
}

src/index.tsx

Lines changed: 73 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,78 @@
1-
import { ActionPanel, Detail, List, PushAction } from "@raycast/api";
1+
import { ActionPanel, Detail, List, OpenInBrowserAction, PushAction } from "@raycast/api";
2+
import { useServerSearch, StoreContext, useTitle, useResource, useString } from '@tomic/react';
3+
import { Store, urls } from '@tomic/lib';
4+
import React from "react";
5+
6+
const store = new Store({
7+
// By setting a Base URL, we tell the client where to send Commits to.
8+
serverUrl: "https://atomicdata.dev"
9+
});
210

311
export default function Command() {
12+
413
return (
5-
<List>
6-
<List.Item
7-
key="1"
8-
icon="list-icon.png"
9-
title="Greeting"
10-
actions={
11-
<ActionPanel>
12-
<PushAction title="Show Details" target={<Detail markdown="# Hey! 👋" />} />
13-
</ActionPanel>
14-
}
15-
/>
16-
</List>
14+
<StoreContext.Provider value={store}>
15+
<Content />
16+
</StoreContext.Provider>
1717
);
1818
}
19+
20+
function Content() {
21+
const [query, setQuery] = React.useState("");
22+
const { results, loading, error } = useServerSearch(query, {
23+
include: true,
24+
});
25+
26+
const onSearchTextChange = async (text: string) => {
27+
setQuery(text);
28+
}
29+
30+
return (
31+
<List
32+
navigationTitle="Atomic Data Search"
33+
searchBarPlaceholder="Search your Atomic Server..."
34+
isLoading={loading}
35+
onSearchTextChange={onSearchTextChange}
36+
>
37+
{error && <List.Item title={error.message} />}
38+
{query.length > 0 && results && results.map(subject => (
39+
<SearchHit
40+
subject={subject}
41+
key={subject}
42+
/>
43+
))}
44+
</List>
45+
)
46+
}
47+
48+
interface SearchHitProps {
49+
subject: string,
50+
}
51+
52+
function SearchHit({ subject }: SearchHitProps) {
53+
const resource = useResource(subject);
54+
55+
const title = useTitle(resource);
56+
const [description] = useString(resource, urls.properties.description);
57+
58+
const klass = useResource(resource.getClasses()[0]);
59+
const klassTitle = useTitle(klass);
60+
61+
const md = `# ${title} \n\n ${description}`;
62+
63+
return (
64+
<List.Item
65+
key={subject}
66+
icon="list-icon.png"
67+
title={title}
68+
subtitle={description || ""}
69+
accessoryTitle={klassTitle}
70+
actions={
71+
<ActionPanel>
72+
<PushAction title="Show Details" target={<Detail markdown={md} actions={<ActionPanel><OpenInBrowserAction title="Open in browser" url={subject} /></ActionPanel>}/>} />
73+
<OpenInBrowserAction title="Open in browser" url={subject} />
74+
</ActionPanel>
75+
}
76+
/>
77+
)
78+
}

yarn.lock

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,20 @@
106106
dependencies:
107107
defer-to-connect "^1.0.1"
108108

109+
"@tomic/lib@^0.30.1":
110+
version "0.30.1"
111+
resolved "https://registry.yarnpkg.com/@tomic/lib/-/lib-0.30.1.tgz#565bf34596d8d5110b86eb10557d8c6598200771"
112+
integrity sha512-qp8AmZMYAeYOjypyQQHN0H8U9LL9+C4B/x3SGJWyd6hmdDvc/tW9x69WOb76FjL+xON+OoPsZc5YT3xHytUvdA==
113+
dependencies:
114+
base64-arraybuffer "^0.2.0"
115+
json-stable-stringify "^1.0.1"
116+
noble-ed25519 "^1.0.4"
117+
118+
"@tomic/react@^0.30.2":
119+
version "0.30.2"
120+
resolved "https://registry.yarnpkg.com/@tomic/react/-/react-0.30.2.tgz#7b64ccead70a7881ffa7b2fd9ff494a146b9ed9b"
121+
integrity sha512-lLB/i0nJ/fcNe6vKHVgxo1sSOFqt5JLRxGyx4zWmmhmbDTjCe7DBRibI72UJ8upR9F5YcrEIla4c4KoHudlV3g==
122+
109123
"@types/json-schema@^7.0.9":
110124
version "7.0.9"
111125
resolved "https://registry.yarnpkg.com/@types/json-schema/-/json-schema-7.0.9.tgz#97edc9037ea0c38585320b28964dde3b39e4660d"
@@ -298,6 +312,11 @@ balanced-match@^1.0.0:
298312
resolved "https://registry.yarnpkg.com/balanced-match/-/balanced-match-1.0.2.tgz#e83e3a7e3f300b34cb9d87f615fa0cbf357690ee"
299313
integrity sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==
300314

315+
base64-arraybuffer@^0.2.0:
316+
version "0.2.0"
317+
resolved "https://registry.yarnpkg.com/base64-arraybuffer/-/base64-arraybuffer-0.2.0.tgz#4b944fac0191aa5907afe2d8c999ccc57ce80f45"
318+
integrity sha512-7emyCsu1/xiBXgQZrscw/8KPRT44I4Yq9Pe6EGs3aPRTsWuggML1/1DTuZUuIaJPIm1FTDUVXl4x/yW8s0kQDQ==
319+
301320
boolean@^3.0.1:
302321
version "3.1.4"
303322
resolved "https://registry.yarnpkg.com/boolean/-/boolean-3.1.4.tgz#f51a2fb5838a99e06f9b6ec1edb674de67026435"
@@ -502,6 +521,11 @@ csstype@^3.0.2:
502521
resolved "https://registry.yarnpkg.com/csstype/-/csstype-3.0.10.tgz#2ad3a7bed70f35b965707c092e5f30b327c290e5"
503522
integrity sha512-2u44ZG2OcNUO9HDp/Jl8C07x6pU/eTR3ncV91SiK3dhG9TWvRVsCoJw14Ckx5DgWkzGA3waZWO3d7pgqpUI/XA==
504523

524+
data-uri-to-buffer@^4.0.0:
525+
version "4.0.0"
526+
resolved "https://registry.yarnpkg.com/data-uri-to-buffer/-/data-uri-to-buffer-4.0.0.tgz#b5db46aea50f6176428ac05b73be39a57701a64b"
527+
integrity sha512-Vr3mLBA8qWmcuschSLAOogKgQ/Jwxulv3RNE4FXnYWRGujzrRWQI4m12fQqRkwX06C0KanhLr4hK+GydchZsaA==
528+
505529
debug@^2.6.9:
506530
version "2.6.9"
507531
resolved "https://registry.yarnpkg.com/debug/-/debug-2.6.9.tgz#5d128515df134ff327e90a4c93f4e077a536341f"
@@ -823,6 +847,13 @@ fd-slicer@~1.1.0:
823847
dependencies:
824848
pend "~1.2.0"
825849

850+
fetch-blob@^3.1.2:
851+
version "3.1.3"
852+
resolved "https://registry.yarnpkg.com/fetch-blob/-/fetch-blob-3.1.3.tgz#a7dca4855e39d3e3c5a1da62d4ee335c37d26012"
853+
integrity sha512-ax1Y5I9w+9+JiM+wdHkhBoxew+zG4AJ2SvAD1v1szpddUIiPERVGBxrMcB2ZqW0Y3PP8bOWYv2zqQq1Jp2kqUQ==
854+
dependencies:
855+
web-streams-polyfill "^3.0.3"
856+
826857
file-entry-cache@^6.0.1:
827858
version "6.0.1"
828859
resolved "https://registry.yarnpkg.com/file-entry-cache/-/file-entry-cache-6.0.1.tgz#211b2dd9659cb0394b073e7323ac3c933d522027"
@@ -850,6 +881,13 @@ flatted@^3.1.0:
850881
resolved "https://registry.yarnpkg.com/flatted/-/flatted-3.2.4.tgz#28d9969ea90661b5134259f312ab6aa7929ac5e2"
851882
integrity sha512-8/sOawo8tJ4QOBX8YlQBMxL8+RLZfxMQOif9o0KUKTNTjMYElWPE0r/m5VNFxTRd0NSw8qSy8dajrwX4RYI1Hw==
852883

884+
formdata-polyfill@^4.0.10:
885+
version "4.0.10"
886+
resolved "https://registry.yarnpkg.com/formdata-polyfill/-/formdata-polyfill-4.0.10.tgz#24807c31c9d402e002ab3d8c720144ceb8848423"
887+
integrity sha512-buewHzMvYL29jdeQTVILecSaZKnt/RJWjoZCF5OW60Z67/GmSLBkOFM7qh1PI3zFNtJbaZL5eQu1vLfazOwj4g==
888+
dependencies:
889+
fetch-blob "^3.1.2"
890+
853891
fs-extra@^8.1.0:
854892
version "8.1.0"
855893
resolved "https://registry.yarnpkg.com/fs-extra/-/fs-extra-8.1.0.tgz#49d43c45a88cd9677668cb7be1b46efdb8d2e1c0"
@@ -1184,6 +1222,13 @@ json-stable-stringify-without-jsonify@^1.0.1:
11841222
resolved "https://registry.yarnpkg.com/json-stable-stringify-without-jsonify/-/json-stable-stringify-without-jsonify-1.0.1.tgz#9db7b59496ad3f3cfef30a75142d2d930ad72651"
11851223
integrity sha1-nbe1lJatPzz+8wp1FC0tkwrXJlE=
11861224

1225+
json-stable-stringify@^1.0.1:
1226+
version "1.0.1"
1227+
resolved "https://registry.yarnpkg.com/json-stable-stringify/-/json-stable-stringify-1.0.1.tgz#9a759d39c5f2ff503fd5300646ed445f88c4f9af"
1228+
integrity sha1-mnWdOcXy/1A/1TAGRu1EX4jE+a8=
1229+
dependencies:
1230+
jsonify "~0.0.0"
1231+
11871232
json-stringify-safe@^5.0.1:
11881233
version "5.0.1"
11891234
resolved "https://registry.yarnpkg.com/json-stringify-safe/-/json-stringify-safe-5.0.1.tgz#1296a2d58fd45f19a0f6ce01d65701e2c735b6eb"
@@ -1196,6 +1241,11 @@ jsonfile@^4.0.0:
11961241
optionalDependencies:
11971242
graceful-fs "^4.1.6"
11981243

1244+
jsonify@~0.0.0:
1245+
version "0.0.0"
1246+
resolved "https://registry.yarnpkg.com/jsonify/-/jsonify-0.0.0.tgz#2c74b6ee41d93ca51b7b5aaee8f503631d252a73"
1247+
integrity sha1-LHS27kHZPKUbe1qu6PUDYx0lKnM=
1248+
11991249
keyv@^3.0.0:
12001250
version "3.1.0"
12011251
resolved "https://registry.yarnpkg.com/keyv/-/keyv-3.1.0.tgz#ecc228486f69991e49e9476485a5be1e8fc5c4d9"
@@ -1324,6 +1374,20 @@ natural-compare@^1.4.0:
13241374
resolved "https://registry.yarnpkg.com/natural-compare/-/natural-compare-1.4.0.tgz#4abebfeed7541f2c27acfb29bdbbd15c8d5ba4f7"
13251375
integrity sha1-Sr6/7tdUHywnrPspvbvRXI1bpPc=
13261376

1377+
noble-ed25519@^1.0.4:
1378+
version "1.2.6"
1379+
resolved "https://registry.yarnpkg.com/noble-ed25519/-/noble-ed25519-1.2.6.tgz#a55b75c61da000498abb43ffd81caaa370bfed22"
1380+
integrity sha512-zfnWqg9FVMp8CnzUpAjbt1nDXpDjCvxYiCXdnW1mY8zQHw/6twUlkFm14VPdojVzc0kcd+i9zT79+26GcNbsuQ==
1381+
1382+
node-fetch@^3.1.0:
1383+
version "3.1.0"
1384+
resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-3.1.0.tgz#714f4922dc270239487654eaeeab86b8206cb52e"
1385+
integrity sha512-QU0WbIfMUjd5+MUzQOYhenAazakV7Irh1SGkWCsRzBwvm4fAhzEUaHMJ6QLP7gWT6WO9/oH2zhKMMGMuIrDyKw==
1386+
dependencies:
1387+
data-uri-to-buffer "^4.0.0"
1388+
fetch-blob "^3.1.2"
1389+
formdata-polyfill "^4.0.10"
1390+
13271391
normalize-url@^4.1.0:
13281392
version "4.5.1"
13291393
resolved "https://registry.yarnpkg.com/normalize-url/-/normalize-url-4.5.1.tgz#0dd90cf1288ee1d1313b87081c9a5932ee48518a"
@@ -1925,6 +1989,11 @@ v8-compile-cache@^2.0.3:
19251989
resolved "https://registry.yarnpkg.com/v8-compile-cache/-/v8-compile-cache-2.3.0.tgz#2de19618c66dc247dcfb6f99338035d8245a2cee"
19261990
integrity sha512-l8lCEmLcLYZh4nbunNZvQCJc5pv7+RCwa8q/LdUx8u7lsWvPDKmpodJAJNwkAhJC//dFY48KuIEmjtd4RViDrA==
19271991

1992+
web-streams-polyfill@^3.0.3:
1993+
version "3.2.0"
1994+
resolved "https://registry.yarnpkg.com/web-streams-polyfill/-/web-streams-polyfill-3.2.0.tgz#a6b74026b38e4885869fb5c589e90b95ccfc7965"
1995+
integrity sha512-EqPmREeOzttaLRm5HS7io98goBgZ7IVz79aDvqjD0kYXLtFZTc0T/U6wHTPKyIjb+MdN7DFIIX6hgdBEpWmfPA==
1996+
19281997
which@^1.2.9:
19291998
version "1.3.1"
19301999
resolved "https://registry.yarnpkg.com/which/-/which-1.3.1.tgz#a45043d54f5805316da8d62f9f50918d3da70b0a"

0 commit comments

Comments
 (0)