@noya-app/noya-api-client-react 0.1.45 → 0.1.46
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.turbo/turbo-build.log +9 -9
- package/CHANGELOG.md +8 -0
- package/dist/index.d.mts +14 -54
- package/dist/index.d.ts +14 -54
- package/dist/index.js +835 -484
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +766 -408
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
- package/src/react/hooks.ts +1 -105
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@noya-app/noya-api-client-react",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.46",
|
|
4
4
|
"main": "./dist/index.js",
|
|
5
5
|
"module": "./dist/index.mjs",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
},
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"@legendapp/state": "^2.1.1",
|
|
13
|
-
"@noya-app/noya-api": "0.1.
|
|
13
|
+
"@noya-app/noya-api": "0.1.46",
|
|
14
14
|
"@noya-app/noya-utils": "0.1.9",
|
|
15
15
|
"@noya-app/observable": "0.1.12",
|
|
16
16
|
"@noya-app/observable-store": "0.1.2",
|
package/src/react/hooks.ts
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
|
|
3
3
|
import { useSelector } from "@legendapp/state/react";
|
|
4
|
-
import {
|
|
5
|
-
import { range } from "@noya-app/noya-utils";
|
|
4
|
+
import { NoyaAPI } from "@noya-app/noya-api";
|
|
6
5
|
import { useObservable } from "@noya-app/observable-react";
|
|
7
6
|
import { useCallback, useEffect, useMemo, useRef } from "react";
|
|
8
7
|
import {
|
|
@@ -168,115 +167,12 @@ export function useMetadata<T extends NoyaAPI.Json>(key: string) {
|
|
|
168
167
|
return metadataItem?.value as T | undefined;
|
|
169
168
|
}
|
|
170
169
|
|
|
171
|
-
export function useGeneratedComponentNames(name: string) {
|
|
172
|
-
const key = name.trim().toLowerCase();
|
|
173
|
-
const { generatedNames$, loadingNames$ } = useNoyaClientOrFallback();
|
|
174
|
-
const result = useSelector(
|
|
175
|
-
() => generatedNames$[key].get() as NoyaAPI.GeneratedName[] | undefined
|
|
176
|
-
);
|
|
177
|
-
const loading = useSelector(() => loadingNames$[key].get());
|
|
178
|
-
return useMemo(() => ({ names: result ?? [], loading }), [loading, result]);
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
export function useGeneratedComponentDescriptions() {
|
|
182
|
-
const { generatedDescriptions$, loadingDescriptions$ } =
|
|
183
|
-
useNoyaClientOrFallback();
|
|
184
|
-
const descriptions = useSelector(generatedDescriptions$);
|
|
185
|
-
const loading = useSelector(loadingDescriptions$);
|
|
186
|
-
return useMemo(() => ({ descriptions, loading }), [loading, descriptions]);
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
export function useGeneratedComponentDescription(name: string) {
|
|
190
|
-
const key = name.trim().toLowerCase();
|
|
191
|
-
const { generatedDescriptions$, loadingDescriptions$ } =
|
|
192
|
-
useNoyaClientOrFallback();
|
|
193
|
-
const description = useSelector(
|
|
194
|
-
() => generatedDescriptions$[key].get() as string | undefined
|
|
195
|
-
);
|
|
196
|
-
const loading = useSelector(() => loadingDescriptions$[key].get());
|
|
197
|
-
return useMemo(() => ({ description, loading }), [loading, description]);
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
export function useRandomImages() {
|
|
201
|
-
const { randomImages$, loadingRandomImages$ } = useNoyaClientOrFallback();
|
|
202
|
-
const images = useSelector(randomImages$);
|
|
203
|
-
const loading = useSelector(loadingRandomImages$);
|
|
204
|
-
return useMemo(() => ({ images, loading }), [loading, images]);
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
export function useRandomIcons() {
|
|
208
|
-
const { randomIcons$, loadingRandomIcons$ } = useNoyaClientOrFallback();
|
|
209
|
-
const icons = useSelector(randomIcons$);
|
|
210
|
-
const loading = useSelector(loadingRandomIcons$);
|
|
211
|
-
return useMemo(() => ({ icons, loading }), [loading, icons]);
|
|
212
|
-
}
|
|
213
|
-
|
|
214
170
|
export function useNetworkRequests() {
|
|
215
171
|
const { requests$ } = useNoyaClientOrFallback();
|
|
216
172
|
const requests = useSelector(requests$) as NoyaAPI.RequestSnapshot[];
|
|
217
173
|
return requests;
|
|
218
174
|
}
|
|
219
175
|
|
|
220
|
-
export type EnhancedGeneratedPageName = NoyaAPI.GeneratedName & {
|
|
221
|
-
index: number;
|
|
222
|
-
type: "suggestion";
|
|
223
|
-
};
|
|
224
|
-
|
|
225
|
-
export function useGeneratedPageNames(): EnhancedGeneratedPageName[] {
|
|
226
|
-
const { generatedPageNames$ } = useNoyaClientOrFallback();
|
|
227
|
-
const names = useSelector(generatedPageNames$) as NoyaAPI.GeneratedName[];
|
|
228
|
-
|
|
229
|
-
const namesWithDefaultsAndTypes = useMemo(() => {
|
|
230
|
-
const rangeArray = range(0, GENERATED_PAGE_NAME_COUNT);
|
|
231
|
-
|
|
232
|
-
// Fill any empty slots with default names in the 'loading' state
|
|
233
|
-
const withDefaults = rangeArray.map((index): NoyaAPI.GeneratedName => {
|
|
234
|
-
const name = names[index];
|
|
235
|
-
return name ?? { name: `Page ${index + 1}`, loading: true, key: "" };
|
|
236
|
-
});
|
|
237
|
-
|
|
238
|
-
return withDefaults.map(
|
|
239
|
-
(name, index): EnhancedGeneratedPageName => ({
|
|
240
|
-
...name,
|
|
241
|
-
index,
|
|
242
|
-
type: "suggestion",
|
|
243
|
-
})
|
|
244
|
-
);
|
|
245
|
-
}, [names]);
|
|
246
|
-
|
|
247
|
-
// Take the first 3
|
|
248
|
-
return namesWithDefaultsAndTypes.slice(0, 3);
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
export function useGeneratedPageComponentNames(): EnhancedGeneratedPageName[] {
|
|
252
|
-
const { generatedPageComponentNames$: generatedComponentNames$ } =
|
|
253
|
-
useNoyaClientOrFallback();
|
|
254
|
-
const names = useSelector(
|
|
255
|
-
generatedComponentNames$
|
|
256
|
-
) as NoyaAPI.GeneratedName[];
|
|
257
|
-
|
|
258
|
-
const namesWithDefaultsAndTypes = useMemo(() => {
|
|
259
|
-
const rangeArray = range(0, GENERATED_PAGE_NAME_COUNT);
|
|
260
|
-
|
|
261
|
-
// Fill any empty slots with default names in the 'loading' state
|
|
262
|
-
const withDefaults = rangeArray.map((index): NoyaAPI.GeneratedName => {
|
|
263
|
-
const name = names[index];
|
|
264
|
-
return name ?? { name: `Component ${index + 1}`, loading: true, key: "" };
|
|
265
|
-
});
|
|
266
|
-
|
|
267
|
-
return withDefaults.map(
|
|
268
|
-
(name, index): EnhancedGeneratedPageName => ({
|
|
269
|
-
...name,
|
|
270
|
-
index,
|
|
271
|
-
type: "suggestion",
|
|
272
|
-
})
|
|
273
|
-
);
|
|
274
|
-
}, [names]);
|
|
275
|
-
|
|
276
|
-
// Take the first 3
|
|
277
|
-
return namesWithDefaultsAndTypes.slice(0, 3);
|
|
278
|
-
}
|
|
279
|
-
|
|
280
176
|
export function useNoyaSites() {
|
|
281
177
|
const sites = useSelector(useNoyaClientOrFallback().sites$);
|
|
282
178
|
return sites;
|