forked from CopilotKit/CopilotKit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinventoryData.ts
More file actions
372 lines (362 loc) · 11 KB
/
Copy pathinventoryData.ts
File metadata and controls
372 lines (362 loc) · 11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
import { matchSorter } from "match-sorter";
// @ts-expect-error - no types, but it's a tiny function
import sortBy from "sort-by";
export type InventoryRecord = {
id: string;
avatar: string;
displayName: string;
priceInCents: number;
description: string;
createdAt: string;
};
type InventoryMutation = {
id?: string;
avatar: string;
displayName: string;
priceInCents: number;
description: string;
};
const fakeInventory = {
records: {} as Record<string, InventoryRecord>,
async getAll(): Promise<InventoryRecord[]> {
return Object.keys(fakeInventory.records)
.map((key) => fakeInventory.records[key])
.sort(sortBy("-createdAt", "last"));
},
async get(id: string): Promise<InventoryRecord | null> {
return fakeInventory.records[id] || null;
},
async create(values: InventoryMutation): Promise<InventoryRecord> {
const id = values.id || Math.random().toString(36).substring(2, 9);
const createdAt = new Date().toISOString();
const newItem = { id, createdAt, ...values };
fakeInventory.records[id] = newItem;
return newItem;
},
};
////////////////////////////////////////////////////////////////////////////////
// Handful of helper functions to be called from route loaders and actions
export async function getInventory(query?: string | null) {
await new Promise((resolve) => setTimeout(resolve, 500));
let items = await fakeInventory.getAll();
if (query) {
items = matchSorter(items, query, {
keys: ["displayName", "description"],
});
}
return items.sort(sortBy("displayName", "createdAt"));
}
export async function getItem(id: string) {
return fakeInventory.get(id);
}
export async function getAll() {
await new Promise((resolve) => setTimeout(resolve, 500));
return fakeInventory.records;
}
[
{
avatar: "https://picsum.photos/seed/item1/200",
displayName: "Vintage Backpack",
priceInCents: 4999,
description: "A durable and stylish backpack for everyday use.",
},
{
avatar: "https://picsum.photos/seed/item2/200",
displayName: "Wireless Headphones",
priceInCents: 8995,
description: "Noise-canceling headphones with 30-hour battery life.",
},
{
avatar: "https://picsum.photos/seed/item3/200",
displayName: "Espresso Machine",
priceInCents: 24900,
description: "Brew barista-quality espresso at home.",
},
{
avatar: "https://picsum.photos/seed/item4/200",
displayName: "Running Shoes",
priceInCents: 12000,
description: "Lightweight shoes designed for comfort and speed.",
},
{
avatar: "https://picsum.photos/seed/item5/200",
displayName: "Smartwatch",
priceInCents: 19999,
description: "Track your health and notifications on the go.",
},
{
avatar: "https://picsum.photos/seed/item6/200",
displayName: "Bluetooth Speaker",
priceInCents: 3999,
description: "Compact speaker with deep bass and clear sound.",
},
{
avatar: "https://picsum.photos/seed/item7/200",
displayName: "Desk Lamp",
priceInCents: 2250,
description: "LED desk lamp with touch controls and dimming.",
},
{
avatar: "https://picsum.photos/seed/item8/200",
displayName: "Stainless Steel Water Bottle",
priceInCents: 1875,
description: "Keeps your drinks hot or cold for hours.",
},
{
avatar: "https://picsum.photos/seed/item9/200",
displayName: "Gaming Mouse",
priceInCents: 5999,
description: "Ergonomic mouse with customizable buttons and lights.",
},
{
avatar: "https://picsum.photos/seed/item10/200",
displayName: "Mechanical Keyboard",
priceInCents: 9900,
description: "Tactile keys and RGB lighting for gaming or typing.",
},
{
avatar: "https://picsum.photos/seed/item11/200",
displayName: "Yoga Mat",
priceInCents: 2999,
description: "Non-slip surface for yoga or pilates practice.",
},
{
avatar: "https://picsum.photos/seed/item12/200",
displayName: "Sunglasses",
priceInCents: 4500,
description: "UV-protected, stylish sunglasses for sunny days.",
},
{
avatar: "https://picsum.photos/seed/item13/200",
displayName: "Electric Toothbrush",
priceInCents: 7995,
description: "Powerful cleaning with smart timer technology.",
},
{
avatar: "https://picsum.photos/seed/item14/200",
displayName: "Hoodie",
priceInCents: 6000,
description: "Warm, cozy, and perfect for chilly weather.",
},
{
avatar: "https://picsum.photos/seed/item15/200",
displayName: "Leather Wallet",
priceInCents: 3500,
description: "Slim and stylish wallet made from genuine leather.",
},
{
avatar: "https://picsum.photos/seed/item16/200",
displayName: "Notebook Set",
priceInCents: 1599,
description: "Pack of 3 softcover notebooks for notes and sketches.",
},
{
avatar: "https://picsum.photos/seed/item17/200",
displayName: "Portable Charger",
priceInCents: 2799,
description: "Fast-charging power bank with dual USB ports.",
},
{
avatar: "https://picsum.photos/seed/item18/200",
displayName: "Cooking Pan",
priceInCents: 3200,
description: "Non-stick pan ideal for everyday cooking.",
},
{
avatar: "https://picsum.photos/seed/item19/200",
displayName: "Minimalist Watch",
priceInCents: 11000,
description: "Elegant watch with clean, modern design.",
},
{
avatar: "https://picsum.photos/seed/item20/200",
displayName: "Camping Tent",
priceInCents: 13000,
description: "2-person lightweight and waterproof tent.",
},
{
avatar: "https://picsum.photos/seed/item21/200",
displayName: "Scented Candles",
priceInCents: 2450,
description: "Set of 3 aromatherapy candles for relaxation.",
},
{
avatar: "https://picsum.photos/seed/item22/200",
displayName: "Laptop Stand",
priceInCents: 4000,
description: "Adjustable stand for comfortable laptop use.",
},
{
avatar: "https://picsum.photos/seed/item23/200",
displayName: "Beanie Hat",
priceInCents: 1495,
description: "Soft knit beanie to keep you warm in winter.",
},
{
avatar: "https://picsum.photos/seed/item24/200",
displayName: "Desk Organizer",
priceInCents: 2349,
description: "Keep your workspace tidy with multiple compartments.",
},
{
avatar: "https://picsum.photos/seed/item25/200",
displayName: "Cordless Drill",
priceInCents: 7500,
description: "Powerful and compact drill for home projects.",
},
{
avatar: "https://picsum.photos/seed/item26/200",
displayName: "Phone Tripod",
priceInCents: 1995,
description: "Flexible tripod perfect for content creation.",
},
{
avatar: "https://picsum.photos/seed/item27/200",
displayName: "Wireless Charger",
priceInCents: 2999,
description: "Fast wireless charging pad for smartphones.",
},
{
avatar: "https://picsum.photos/seed/item28/200",
displayName: "Bath Towels",
priceInCents: 3999,
description: "Soft and absorbent towel set in multiple colors.",
},
{
avatar: "https://picsum.photos/seed/item29/200",
displayName: "Picnic Blanket",
priceInCents: 2500,
description: "Waterproof blanket for outdoor picnics and camping.",
},
{
avatar: "https://picsum.photos/seed/item30/200",
displayName: "Digital Alarm Clock",
priceInCents: 1850,
description: "Easy-to-read clock with snooze and backlight.",
},
{
avatar: "https://picsum.photos/seed/item31/200",
displayName: "Leather Journal",
priceInCents: 2699,
description: "Handmade journal with vintage leather cover.",
},
{
avatar: "https://picsum.photos/seed/item32/200",
displayName: "Slip-On Sneakers",
priceInCents: 5500,
description: "Comfortable sneakers perfect for casual outings.",
},
{
avatar: "https://picsum.photos/seed/item33/200",
displayName: "Wall Art Print",
priceInCents: 3499,
description: "High-quality print to add character to any room.",
},
{
avatar: "https://picsum.photos/seed/item34/200",
displayName: "Bike Helmet",
priceInCents: 6500,
description: "Safety-certified helmet with adjustable straps.",
},
{
avatar: "https://picsum.photos/seed/item35/200",
displayName: "French Press",
priceInCents: 2875,
description: "Brew rich and bold coffee the classic way.",
},
{
avatar: "https://picsum.photos/seed/item36/200",
displayName: "Graphic Tee",
priceInCents: 2200,
description: "Casual t-shirt with a unique printed design.",
},
{
avatar: "https://picsum.photos/seed/item37/200",
displayName: "Skateboard",
priceInCents: 8999,
description: "Complete skateboard for beginners and pros.",
},
{
avatar: "https://picsum.photos/seed/item38/200",
displayName: "BBQ Grill Set",
priceInCents: 5495,
description: "Everything you need for a perfect barbecue.",
},
{
avatar: "https://picsum.photos/seed/item39/200",
displayName: "Plant Pot Set",
priceInCents: 3150,
description: "Decorative pots for indoor or outdoor plants.",
},
{
avatar: "https://picsum.photos/seed/item40/200",
displayName: "Throw Pillow",
priceInCents: 1995,
description: "Soft decorative pillow for your couch or bed.",
},
{
avatar: "https://picsum.photos/seed/item41/200",
displayName: "Linen Apron",
priceInCents: 2700,
description: "Classic kitchen apron with adjustable fit.",
},
{
avatar: "https://picsum.photos/seed/item42/200",
displayName: "Board Game",
priceInCents: 4499,
description: "Fun and strategic game for family game night.",
},
{
avatar: "https://picsum.photos/seed/item43/200",
displayName: "Face Serum",
priceInCents: 3600,
description: "Hydrating serum with vitamins C and E.",
},
{
avatar: "https://picsum.photos/seed/item44/200",
displayName: "Hiking Backpack",
priceInCents: 9800,
description: "Spacious and rugged backpack for outdoor adventures.",
},
{
avatar: "https://picsum.photos/seed/item45/200",
displayName: "Instant Camera",
priceInCents: 7499,
description: "Capture and print memories in seconds.",
},
{
avatar: "https://picsum.photos/seed/item46/200",
displayName: "Cheese Board Set",
priceInCents: 4950,
description: "Elegant bamboo board with utensils and accessories.",
},
{
avatar: "https://picsum.photos/seed/item47/200",
displayName: "Dumbbell Set",
priceInCents: 5900,
description: "Adjustable dumbbells for your home gym.",
},
{
avatar: "https://picsum.photos/seed/item48/200",
displayName: "Floor Lamp",
priceInCents: 7800,
description: "Modern standing lamp with adjustable brightness.",
},
{
avatar: "https://picsum.photos/seed/item49/200",
displayName: "Cooking Knife",
priceInCents: 3850,
description: "Chef-grade knife with razor-sharp edge.",
},
{
avatar: "https://picsum.photos/seed/item50/200",
displayName: "Wool Blanket",
priceInCents: 6999,
description: "Warm and soft wool blanket for cozy nights.",
},
].forEach((item) => {
fakeInventory.create({
...item,
id: item.displayName.toLowerCase().replaceAll(" ", "-"),
});
});