@noya-app/noya-api-client-react 0.1.38 → 0.1.40
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 +17 -0
- package/dist/index.d.mts +32 -1
- package/dist/index.d.ts +32 -1
- package/dist/index.js +146 -104
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +132 -91
- package/dist/index.mjs.map +1 -1
- package/package.json +4 -4
- package/src/react/tableHooks.ts +69 -9
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.40",
|
|
4
4
|
"main": "./dist/index.js",
|
|
5
5
|
"module": "./dist/index.mjs",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -10,10 +10,10 @@
|
|
|
10
10
|
},
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"@legendapp/state": "^2.1.1",
|
|
13
|
-
"@noya-app/noya-api": "0.1.
|
|
14
|
-
"@noya-app/noya-utils": "0.1.
|
|
13
|
+
"@noya-app/noya-api": "0.1.40",
|
|
14
|
+
"@noya-app/noya-utils": "0.1.9",
|
|
15
15
|
"@noya-app/observable": "0.1.12",
|
|
16
|
-
"@noya-app/observable-store": "0.1.
|
|
16
|
+
"@noya-app/observable-store": "0.1.2",
|
|
17
17
|
"@noya-app/observable-react": "0.1.22"
|
|
18
18
|
},
|
|
19
19
|
"peerDependencies": {
|
package/src/react/tableHooks.ts
CHANGED
|
@@ -5,13 +5,14 @@ import { Static, useObservable } from "@noya-app/noya-multiplayer-react";
|
|
|
5
5
|
import { ActivityEvent, Resource } from "@noya-app/noya-schemas";
|
|
6
6
|
import { SelectConfig, SelectedShape } from "@noya-app/observable";
|
|
7
7
|
import {
|
|
8
|
+
Entity,
|
|
8
9
|
EntitySchema,
|
|
9
10
|
RefetchFunction,
|
|
10
11
|
RefetchableObservable,
|
|
11
12
|
Table,
|
|
12
13
|
TableFetchOptions,
|
|
13
14
|
} from "@noya-app/observable-store";
|
|
14
|
-
import { useEffect, useMemo } from "react";
|
|
15
|
+
import { useCallback, useEffect, useMemo } from "react";
|
|
15
16
|
import { useNoyaClientOrFallback } from "./context";
|
|
16
17
|
|
|
17
18
|
type GetRowType<TTable extends Table<EntitySchema>> = Static<TTable["schema"]>;
|
|
@@ -38,6 +39,10 @@ export function useTable<
|
|
|
38
39
|
status: NoyaAPI.FetchStatus;
|
|
39
40
|
data: SelectedShape<GetRowType<TTable>, Config>[];
|
|
40
41
|
refetch: () => void;
|
|
42
|
+
optimisticUpdate: (
|
|
43
|
+
entity: Entity<TTable["schema"]>,
|
|
44
|
+
config?: GetSelectConfig<TTable>
|
|
45
|
+
) => void;
|
|
41
46
|
} {
|
|
42
47
|
const stableSelect = useMemo(() => {
|
|
43
48
|
return JSON.stringify(select);
|
|
@@ -101,14 +106,22 @@ export function useTable<
|
|
|
101
106
|
}, [observable]);
|
|
102
107
|
|
|
103
108
|
const { status, data } = useObservable(observable);
|
|
109
|
+
const optimisticUpdate = useCallback(
|
|
110
|
+
(entity: Entity<TTable["schema"]>, config?: GetSelectConfig<TTable>) => {
|
|
111
|
+
if (!table) return;
|
|
112
|
+
table.optimisticUpdate(entity, config);
|
|
113
|
+
},
|
|
114
|
+
[table]
|
|
115
|
+
);
|
|
104
116
|
|
|
105
117
|
return useMemo(() => {
|
|
106
118
|
return {
|
|
107
119
|
status,
|
|
108
120
|
data,
|
|
109
121
|
refetch: observable.refetch,
|
|
122
|
+
optimisticUpdate,
|
|
110
123
|
};
|
|
111
|
-
}, [status, data, observable]);
|
|
124
|
+
}, [status, data, observable, optimisticUpdate]);
|
|
112
125
|
}
|
|
113
126
|
|
|
114
127
|
export function useFileList<Config extends SelectConfig<NoyaAPI.FileListItem>>(
|
|
@@ -118,10 +131,25 @@ export function useFileList<Config extends SelectConfig<NoyaAPI.FileListItem>>(
|
|
|
118
131
|
status: NoyaAPI.FetchStatus;
|
|
119
132
|
data: SelectedShape<NoyaAPI.FileListItem, Config>[];
|
|
120
133
|
refetch: RefetchFunction;
|
|
134
|
+
optimisticUpdate: (
|
|
135
|
+
entity: Partial<NoyaAPI.FileListItem> & { id: string },
|
|
136
|
+
config?: Config
|
|
137
|
+
) => void;
|
|
121
138
|
} {
|
|
122
139
|
const client = useNoyaClientOrFallback();
|
|
123
140
|
|
|
124
|
-
|
|
141
|
+
const { status, data, refetch, optimisticUpdate } = useTable(
|
|
142
|
+
client.fileList$,
|
|
143
|
+
{ select },
|
|
144
|
+
options
|
|
145
|
+
);
|
|
146
|
+
|
|
147
|
+
return {
|
|
148
|
+
status,
|
|
149
|
+
data,
|
|
150
|
+
refetch,
|
|
151
|
+
optimisticUpdate,
|
|
152
|
+
};
|
|
125
153
|
}
|
|
126
154
|
|
|
127
155
|
export function useFileListItem<
|
|
@@ -134,10 +162,14 @@ export function useFileListItem<
|
|
|
134
162
|
status: NoyaAPI.FetchStatus;
|
|
135
163
|
data: SelectedShape<NoyaAPI.FileListItem, Config> | undefined;
|
|
136
164
|
refetch: RefetchFunction;
|
|
165
|
+
optimisticUpdate: (
|
|
166
|
+
entity: Partial<NoyaAPI.FileListItem> & { id: string },
|
|
167
|
+
config?: Config
|
|
168
|
+
) => void;
|
|
137
169
|
} {
|
|
138
170
|
const client = useNoyaClientOrFallback();
|
|
139
171
|
|
|
140
|
-
const { status, data, refetch } = useTable(
|
|
172
|
+
const { status, data, refetch, optimisticUpdate } = useTable(
|
|
141
173
|
client.fileList$,
|
|
142
174
|
{ where: { id: id ?? null }, select },
|
|
143
175
|
options
|
|
@@ -148,8 +180,9 @@ export function useFileListItem<
|
|
|
148
180
|
data: data.at(0),
|
|
149
181
|
status,
|
|
150
182
|
refetch,
|
|
183
|
+
optimisticUpdate,
|
|
151
184
|
};
|
|
152
|
-
}, [data, status, refetch]);
|
|
185
|
+
}, [data, status, refetch, optimisticUpdate]);
|
|
153
186
|
}
|
|
154
187
|
|
|
155
188
|
export function useResourcesList<Config extends SelectConfig<Resource>>(
|
|
@@ -160,14 +193,25 @@ export function useResourcesList<Config extends SelectConfig<Resource>>(
|
|
|
160
193
|
status: NoyaAPI.FetchStatus;
|
|
161
194
|
data: SelectedShape<Resource, Config>[];
|
|
162
195
|
refetch: RefetchFunction;
|
|
196
|
+
optimisticUpdate: (
|
|
197
|
+
entity: Partial<Resource> & { id: string },
|
|
198
|
+
config?: Config
|
|
199
|
+
) => void;
|
|
163
200
|
} {
|
|
164
201
|
const client = useNoyaClientOrFallback();
|
|
165
202
|
|
|
166
|
-
|
|
203
|
+
const { status, data, refetch, optimisticUpdate } = useTable(
|
|
167
204
|
client.resources$,
|
|
168
205
|
{ select, where: { accessibleByFileId: fileId } },
|
|
169
206
|
options
|
|
170
207
|
);
|
|
208
|
+
|
|
209
|
+
return {
|
|
210
|
+
status,
|
|
211
|
+
data,
|
|
212
|
+
refetch,
|
|
213
|
+
optimisticUpdate,
|
|
214
|
+
};
|
|
171
215
|
}
|
|
172
216
|
|
|
173
217
|
export function useUser<Config extends SelectConfig<NoyaAPI.PublicUser>>(
|
|
@@ -178,10 +222,14 @@ export function useUser<Config extends SelectConfig<NoyaAPI.PublicUser>>(
|
|
|
178
222
|
status: NoyaAPI.FetchStatus;
|
|
179
223
|
data: SelectedShape<NoyaAPI.PublicUser, Config> | undefined;
|
|
180
224
|
refetch: RefetchFunction;
|
|
225
|
+
optimisticUpdate: (
|
|
226
|
+
entity: Partial<NoyaAPI.PublicUser> & { id: string },
|
|
227
|
+
config?: Config
|
|
228
|
+
) => void;
|
|
181
229
|
} {
|
|
182
230
|
const client = useNoyaClientOrFallback();
|
|
183
231
|
|
|
184
|
-
const { status, data, refetch } = useTable(
|
|
232
|
+
const { status, data, refetch, optimisticUpdate } = useTable(
|
|
185
233
|
client.users$,
|
|
186
234
|
{ select, where: { id: id ?? null } },
|
|
187
235
|
options
|
|
@@ -192,8 +240,9 @@ export function useUser<Config extends SelectConfig<NoyaAPI.PublicUser>>(
|
|
|
192
240
|
status,
|
|
193
241
|
data: data.at(0),
|
|
194
242
|
refetch,
|
|
243
|
+
optimisticUpdate,
|
|
195
244
|
};
|
|
196
|
-
}, [status, data, refetch]);
|
|
245
|
+
}, [status, data, refetch, optimisticUpdate]);
|
|
197
246
|
}
|
|
198
247
|
|
|
199
248
|
export function useActivityEventsList<
|
|
@@ -206,12 +255,23 @@ export function useActivityEventsList<
|
|
|
206
255
|
status: NoyaAPI.FetchStatus;
|
|
207
256
|
data: SelectedShape<ActivityEvent, Config>[];
|
|
208
257
|
refetch: RefetchFunction;
|
|
258
|
+
optimisticUpdate: (
|
|
259
|
+
entity: Partial<ActivityEvent> & { id: string },
|
|
260
|
+
config?: Config
|
|
261
|
+
) => void;
|
|
209
262
|
} {
|
|
210
263
|
const client = useNoyaClientOrFallback();
|
|
211
264
|
|
|
212
|
-
|
|
265
|
+
const { status, data, refetch, optimisticUpdate } = useTable(
|
|
213
266
|
client.activityEvents$,
|
|
214
267
|
{ select, where: { fileId } },
|
|
215
268
|
options
|
|
216
269
|
);
|
|
270
|
+
|
|
271
|
+
return {
|
|
272
|
+
status,
|
|
273
|
+
data,
|
|
274
|
+
refetch,
|
|
275
|
+
optimisticUpdate,
|
|
276
|
+
};
|
|
217
277
|
}
|